/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/send.py

  • Committer: Breezy landing bot
  • Author(s): Colin Watson
  • Date: 2020-11-16 21:47:08 UTC
  • mfrom: (7521.1.1 remove-lp-workaround)
  • Revision ID: breezy.the.bot@gmail.com-20201116214708-jos209mgxi41oy15
Remove breezy.git workaround for bazaar.launchpad.net.

Merged from https://code.launchpad.net/~cjwatson/brz/remove-lp-workaround/+merge/393710

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
from __future__ import absolute_import
18
 
 
19
17
import os
20
18
import time
21
19
 
22
 
from bzrlib import (
 
20
from . import (
23
21
    controldir,
24
22
    errors,
25
23
    osutils,
26
24
    registry,
27
25
    trace,
28
26
    )
29
 
from bzrlib.i18n import gettext
30
 
from bzrlib.branch import (
 
27
from .i18n import gettext
 
28
from .branch import (
31
29
    Branch,
32
30
    )
33
 
from bzrlib.revision import (
 
31
from .revision import (
34
32
    NULL_REVISION,
35
33
    )
36
34
 
46
44
        from_, possible_transports=possible_transports)[:2]
47
45
    # we may need to write data into branch's repository to calculate
48
46
    # the data to send.
49
 
    branch.lock_write()
50
 
    try:
 
47
    with branch.lock_write():
51
48
        if output is None:
52
49
            config_stack = branch.get_config_stack()
53
50
            if mail_to is None:
54
51
                mail_to = config_stack.get('submit_to')
55
52
            mail_client = config_stack.get('mail_client')(config_stack)
56
53
            if (not getattr(mail_client, 'supports_body', False)
57
 
                and body is not None):
58
 
                raise errors.BzrCommandError(gettext(
 
54
                    and body is not None):
 
55
                raise errors.CommandError(gettext(
59
56
                    'Mail client "%s" does not support specifying body') %
60
57
                    mail_client.__class__.__name__)
61
58
        if remember and target_branch is None:
62
 
            raise errors.BzrCommandError(gettext(
 
59
            raise errors.CommandError(gettext(
63
60
                '--remember requires a branch to be specified.'))
64
61
        stored_target_branch = branch.get_submit_branch()
65
62
        remembered_target_branch = None
75
72
            target_branch = branch.get_parent()
76
73
            remembered_target_branch = "parent"
77
74
        if target_branch is None:
78
 
            raise errors.BzrCommandError(gettext('No submit branch known or'
79
 
                                         ' specified'))
 
75
            raise errors.CommandError(gettext('No submit branch known or'
 
76
                                                 ' specified'))
80
77
        if remembered_target_branch is not None:
81
78
            trace.note(gettext('Using saved {0} location "{1}" to determine '
82
 
                       'what changes to submit.').format(
83
 
                                    remembered_target_branch,
84
 
                                    target_branch))
 
79
                               'what changes to submit.').format(
 
80
                remembered_target_branch,
 
81
                target_branch))
85
82
 
86
83
        submit_branch = Branch.open(target_branch,
87
 
            possible_transports=possible_transports)
88
 
        possible_transports.append(submit_branch.bzrdir.root_transport)
 
84
                                    possible_transports=possible_transports)
 
85
        possible_transports.append(submit_branch.controldir.root_transport)
89
86
        if mail_to is None or format is None:
90
87
            if mail_to is None:
91
88
                mail_to = submit_branch.get_config_stack().get(
95
92
                try:
96
93
                    format = format_registry.get(formatname)
97
94
                except KeyError:
98
 
                    raise errors.BzrCommandError(
 
95
                    raise errors.CommandError(
99
96
                        gettext("No such send format '%s'.") % formatname)
100
97
 
101
98
        stored_public_branch = branch.get_public_branch()
106
103
              or (remember is None and stored_public_branch is None)):
107
104
            branch.set_public_branch(public_branch)
108
105
        if no_bundle and public_branch is None:
109
 
            raise errors.BzrCommandError(gettext('No public branch specified or'
110
 
                                         ' known'))
 
106
            raise errors.CommandError(gettext('No public branch specified or'
 
107
                                                 ' known'))
111
108
        base_revision_id = None
112
109
        revision_id = None
113
110
        if revision is not None:
114
111
            if len(revision) > 2:
115
 
                raise errors.BzrCommandError(gettext('bzr send takes '
116
 
                    'at most two one revision identifiers'))
 
112
                raise errors.CommandError(gettext('bzr send takes '
 
113
                                                     'at most two one revision identifiers'))
117
114
            revision_id = revision[-1].as_revision_id(branch)
118
115
            if len(revision) == 2:
119
116
                base_revision_id = revision[0].as_revision_id(branch)
125
122
                    more_warning='Uncommitted changes will not be sent.')
126
123
            revision_id = branch.last_revision()
127
124
        if revision_id == NULL_REVISION:
128
 
            raise errors.BzrCommandError(gettext('No revisions to submit.'))
 
125
            raise errors.CommandError(gettext('No revisions to submit.'))
129
126
        if format is None:
130
127
            format = format_registry.get()
131
128
        directive = format(branch, revision_id, target_branch,
132
 
            public_branch, no_patch, no_bundle, message, base_revision_id,
133
 
            submit_branch)
 
129
                           public_branch, no_patch, no_bundle, message, base_revision_id,
 
130
                           submit_branch)
134
131
        if output is None:
135
132
            directive.compose_merge_request(mail_client, mail_to, body,
136
133
                                            branch, tree)
137
134
        else:
138
135
            if directive.multiple_output_files:
139
136
                if output == '-':
140
 
                    raise errors.BzrCommandError(gettext('- not supported for '
141
 
                        'merge directives that use more than one output file.'))
 
137
                    raise errors.CommandError(gettext('- not supported for '
 
138
                                                         'merge directives that use more than one output file.'))
142
139
                if not os.path.exists(output):
143
 
                    os.mkdir(output, 0755)
 
140
                    os.mkdir(output, 0o755)
144
141
                for (filename, lines) in directive.to_files():
145
142
                    path = os.path.join(output, filename)
146
 
                    outfile = open(path, 'wb')
147
 
                    try:
 
143
                    with open(path, 'wb') as outfile:
148
144
                        outfile.writelines(lines)
149
 
                    finally:
150
 
                        outfile.close()
151
145
            else:
152
146
                if output == '-':
153
147
                    outfile = to_file
158
152
                finally:
159
153
                    if outfile is not to_file:
160
154
                        outfile.close()
161
 
    finally:
162
 
        branch.unlock()
163
155
 
164
156
 
165
157
def _send_4(branch, revision_id, target_branch, public_branch,
166
158
            no_patch, no_bundle, message,
167
159
            base_revision_id, local_target_branch=None):
168
 
    from bzrlib import merge_directive
 
160
    from breezy import merge_directive
169
161
    return merge_directive.MergeDirective2.from_objects(
170
162
        branch.repository, revision_id, time.time(),
171
163
        osutils.local_time_offset(), target_branch,
183
175
        if not no_patch:
184
176
            patch_type = 'bundle'
185
177
        else:
186
 
            raise errors.BzrCommandError(gettext('Format 0.9 does not'
187
 
                ' permit bundle with no patch'))
 
178
            raise errors.CommandError(gettext('Format 0.9 does not'
 
179
                                                 ' permit bundle with no patch'))
188
180
    else:
189
181
        if not no_patch:
190
182
            patch_type = 'diff'
191
183
        else:
192
184
            patch_type = None
193
 
    from bzrlib import merge_directive
 
185
    from breezy import merge_directive
194
186
    return merge_directive.MergeDirective.from_objects(
195
187
        branch.repository, revision_id, time.time(),
196
188
        osutils.local_time_offset(), submit_branch,
199
191
 
200
192
 
201
193
format_registry.register('4',
202
 
    _send_4, 'Bundle format 4, Merge Directive 2 (default)')
 
194
                         _send_4, 'Bundle format 4, Merge Directive 2 (default)')
203
195
format_registry.register('0.9',
204
 
    _send_0_9, 'Bundle format 0.9, Merge Directive 1')
 
196
                         _send_0_9, 'Bundle format 0.9, Merge Directive 1')
205
197
format_registry.default_key = '4'