~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/send.py

  • Committer: Jelmer Vernooij
  • Date: 2011-09-26 15:21:01 UTC
  • mfrom: (6165.2.3 avoid-revision-history)
  • mto: This revision was merged to the branch mainline in revision 6216.
  • Revision ID: jelmer@samba.org-20110926152101-afcxw1hikybyivfd
merge avoid-revision-history.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
 
 
18
import os
18
19
import time
19
20
 
20
21
from bzrlib import (
24
25
    registry,
25
26
    trace,
26
27
    )
 
28
from bzrlib.i18n import gettext
27
29
from bzrlib.branch import (
28
30
    Branch,
29
31
    )
50
52
            mail_client = config.get_mail_client()
51
53
            if (not getattr(mail_client, 'supports_body', False)
52
54
                and body is not None):
53
 
                raise errors.BzrCommandError(
54
 
                    'Mail client "%s" does not support specifying body' %
 
55
                raise errors.BzrCommandError(gettext(
 
56
                    'Mail client "%s" does not support specifying body') %
55
57
                    mail_client.__class__.__name__)
56
58
        if remember and submit_branch is None:
57
 
            raise errors.BzrCommandError(
58
 
                '--remember requires a branch to be specified.')
 
59
            raise errors.BzrCommandError(gettext(
 
60
                '--remember requires a branch to be specified.'))
59
61
        stored_submit_branch = branch.get_submit_branch()
60
62
        remembered_submit_branch = None
61
63
        if submit_branch is None:
62
64
            submit_branch = stored_submit_branch
63
65
            remembered_submit_branch = "submit"
64
66
        else:
65
 
            if stored_submit_branch is None or remember:
 
67
            # Remembers if asked explicitly or no previous location is set
 
68
            if remember or (remember is None and stored_submit_branch is None):
66
69
                branch.set_submit_branch(submit_branch)
67
70
        if submit_branch is None:
68
71
            submit_branch = branch.get_parent()
69
72
            remembered_submit_branch = "parent"
70
73
        if submit_branch is None:
71
 
            raise errors.BzrCommandError('No submit branch known or'
72
 
                                         ' specified')
 
74
            raise errors.BzrCommandError(gettext('No submit branch known or'
 
75
                                         ' specified'))
73
76
        if remembered_submit_branch is not None:
74
 
            trace.note('Using saved %s location "%s" to determine what '
75
 
                       'changes to submit.', remembered_submit_branch,
76
 
                       submit_branch)
 
77
            trace.note(gettext('Using saved {0} location "{1}" to determine '
 
78
                       'what changes to submit.').format(
 
79
                                    remembered_submit_branch, submit_branch))
77
80
 
78
81
        if mail_to is None or format is None:
79
82
            # TODO: jam 20090716 we open the submit_branch here, but we *don't*
88
91
                try:
89
92
                    format = format_registry.get(formatname)
90
93
                except KeyError:
91
 
                    raise errors.BzrCommandError("No such send format '%s'." % 
 
94
                    raise errors.BzrCommandError(gettext("No such send format '%s'.") % 
92
95
                                                 formatname)
93
96
 
94
97
        stored_public_branch = branch.get_public_branch()
95
98
        if public_branch is None:
96
99
            public_branch = stored_public_branch
97
 
        elif stored_public_branch is None or remember:
 
100
        # Remembers if asked explicitly or no previous location is set
 
101
        elif (remember
 
102
              or (remember is None and stored_public_branch is None)):
98
103
            branch.set_public_branch(public_branch)
99
104
        if no_bundle and public_branch is None:
100
 
            raise errors.BzrCommandError('No public branch specified or'
101
 
                                         ' known')
 
105
            raise errors.BzrCommandError(gettext('No public branch specified or'
 
106
                                         ' known'))
102
107
        base_revision_id = None
103
108
        revision_id = None
104
109
        if revision is not None:
105
110
            if len(revision) > 2:
106
 
                raise errors.BzrCommandError('bzr send takes '
107
 
                    'at most two one revision identifiers')
 
111
                raise errors.BzrCommandError(gettext('bzr send takes '
 
112
                    'at most two one revision identifiers'))
108
113
            revision_id = revision[-1].as_revision_id(branch)
109
114
            if len(revision) == 2:
110
115
                base_revision_id = revision[0].as_revision_id(branch)
111
116
        if revision_id is None:
112
 
            if strict is None:
113
 
                strict = branch.get_config(
114
 
                    ).get_user_option_as_bool('send_strict')
115
 
            if strict is None: strict = True # default value
116
 
            if strict and tree is not None:
117
 
                if (tree.has_changes()):
118
 
                    raise errors.UncommittedChanges(
119
 
                        tree, more='Use --no-strict to force the send.')
120
 
                if tree.last_revision() != tree.branch.last_revision():
121
 
                    # The tree has lost sync with its branch, there is little
122
 
                    # chance that the user is aware of it but he can still force
123
 
                    # the send with --no-strict
124
 
                    raise errors.OutOfDateTree(
125
 
                        tree, more='Use --no-strict to force the send.')
 
117
            if tree is not None:
 
118
                tree.check_changed_or_out_of_date(
 
119
                    strict, 'send_strict',
 
120
                    more_error='Use --no-strict to force the send.',
 
121
                    more_warning='Uncommitted changes will not be sent.')
126
122
            revision_id = branch.last_revision()
127
123
        if revision_id == NULL_REVISION:
128
 
            raise errors.BzrCommandError('No revisions to submit.')
 
124
            raise errors.BzrCommandError(gettext('No revisions to submit.'))
129
125
        if format is None:
130
126
            format = format_registry.get()
131
127
        directive = format(branch, revision_id, submit_branch,
134
130
            directive.compose_merge_request(mail_client, mail_to, body,
135
131
                                            branch, tree)
136
132
        else:
137
 
            if output == '-':
138
 
                outfile = to_file
 
133
            if directive.multiple_output_files:
 
134
                if output == '-':
 
135
                    raise errors.BzrCommandError(gettext('- not supported for '
 
136
                        'merge directives that use more than one output file.'))
 
137
                if not os.path.exists(output):
 
138
                    os.mkdir(output, 0755)
 
139
                for (filename, lines) in directive.to_files():
 
140
                    path = os.path.join(output, filename)
 
141
                    outfile = open(path, 'wb')
 
142
                    try:
 
143
                        outfile.writelines(lines)
 
144
                    finally:
 
145
                        outfile.close()
139
146
            else:
140
 
                outfile = open(output, 'wb')
141
 
            try:
142
 
                outfile.writelines(directive.to_lines())
143
 
            finally:
144
 
                if outfile is not to_file:
145
 
                    outfile.close()
 
147
                if output == '-':
 
148
                    outfile = to_file
 
149
                else:
 
150
                    outfile = open(output, 'wb')
 
151
                try:
 
152
                    outfile.writelines(directive.to_lines())
 
153
                finally:
 
154
                    if outfile is not to_file:
 
155
                        outfile.close()
146
156
    finally:
147
157
        branch.unlock()
148
158
 
164
174
        if not no_patch:
165
175
            patch_type = 'bundle'
166
176
        else:
167
 
            raise errors.BzrCommandError('Format 0.9 does not'
168
 
                ' permit bundle with no patch')
 
177
            raise errors.BzrCommandError(gettext('Format 0.9 does not'
 
178
                ' permit bundle with no patch'))
169
179
    else:
170
180
        if not no_patch:
171
181
            patch_type = 'diff'