/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 bzrlib/send.py

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

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