~bzr/ubuntu/maverick/bzr/beta-ppa

« back to all changes in this revision

Viewing changes to bzrlib/send.py

Merge from main PPA.

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
17
18
 
18
19
import os
19
20
import time
20
21
 
21
22
from bzrlib import (
22
 
    bzrdir,
 
23
    controldir,
23
24
    errors,
24
25
    osutils,
25
26
    registry,
37
38
format_registry = registry.Registry()
38
39
 
39
40
 
40
 
def send(submit_branch, revision, public_branch, remember, format,
41
 
         no_bundle, no_patch, output, from_, mail_to, message, body,
 
41
def send(target_branch, revision, public_branch, remember,
 
42
         format, no_bundle, no_patch, output, from_, mail_to, message, body,
42
43
         to_file, strict=None):
43
 
    tree, branch = bzrdir.BzrDir.open_containing_tree_or_branch(from_)[:2]
 
44
    possible_transports = []
 
45
    tree, branch = controldir.ControlDir.open_containing_tree_or_branch(
 
46
        from_, possible_transports=possible_transports)[:2]
44
47
    # we may need to write data into branch's repository to calculate
45
48
    # the data to send.
46
49
    branch.lock_write()
47
50
    try:
48
51
        if output is None:
49
 
            config = branch.get_config()
50
52
            if mail_to is None:
51
 
                mail_to = config.get_user_option('submit_to')
52
 
            mail_client = config.get_mail_client()
 
53
                mail_to = branch.get_config_stack().get('submit_to')
 
54
            mail_client = branch.get_config().get_mail_client()
53
55
            if (not getattr(mail_client, 'supports_body', False)
54
56
                and body is not None):
55
57
                raise errors.BzrCommandError(gettext(
56
58
                    'Mail client "%s" does not support specifying body') %
57
59
                    mail_client.__class__.__name__)
58
 
        if remember and submit_branch is None:
 
60
        if remember and target_branch is None:
59
61
            raise errors.BzrCommandError(gettext(
60
62
                '--remember requires a branch to be specified.'))
61
 
        stored_submit_branch = branch.get_submit_branch()
62
 
        remembered_submit_branch = None
63
 
        if submit_branch is None:
64
 
            submit_branch = stored_submit_branch
65
 
            remembered_submit_branch = "submit"
 
63
        stored_target_branch = branch.get_submit_branch()
 
64
        remembered_target_branch = None
 
65
        if target_branch is None:
 
66
            target_branch = stored_target_branch
 
67
            remembered_target_branch = "submit"
66
68
        else:
67
69
            # Remembers if asked explicitly or no previous location is set
68
 
            if remember or (remember is None and stored_submit_branch is None):
69
 
                branch.set_submit_branch(submit_branch)
70
 
        if submit_branch is None:
71
 
            submit_branch = branch.get_parent()
72
 
            remembered_submit_branch = "parent"
73
 
        if submit_branch is None:
 
70
            if remember or (
 
71
                    remember is None and stored_target_branch is None):
 
72
                branch.set_submit_branch(target_branch)
 
73
        if target_branch is None:
 
74
            target_branch = branch.get_parent()
 
75
            remembered_target_branch = "parent"
 
76
        if target_branch is None:
74
77
            raise errors.BzrCommandError(gettext('No submit branch known or'
75
78
                                         ' specified'))
76
 
        if remembered_submit_branch is not None:
 
79
        if remembered_target_branch is not None:
77
80
            trace.note(gettext('Using saved {0} location "{1}" to determine '
78
81
                       'what changes to submit.').format(
79
 
                                    remembered_submit_branch, submit_branch))
 
82
                                    remembered_target_branch,
 
83
                                    target_branch))
80
84
 
 
85
        submit_branch = Branch.open(target_branch,
 
86
            possible_transports=possible_transports)
 
87
        possible_transports.append(submit_branch.bzrdir.root_transport)
81
88
        if mail_to is None or format is None:
82
 
            # TODO: jam 20090716 we open the submit_branch here, but we *don't*
83
 
            #       pass it down into the format creation, so it will have to
84
 
            #       open it again
85
 
            submit_br = Branch.open(submit_branch)
86
 
            submit_config = submit_br.get_config()
87
89
            if mail_to is None:
88
 
                mail_to = submit_config.get_user_option("child_submit_to")
 
90
                mail_to = submit_branch.get_config_stack().get(
 
91
                    'child_submit_to')
89
92
            if format is None:
90
 
                formatname = submit_br.get_child_submit_format()
 
93
                formatname = submit_branch.get_child_submit_format()
91
94
                try:
92
95
                    format = format_registry.get(formatname)
93
96
                except KeyError:
94
 
                    raise errors.BzrCommandError(gettext("No such send format '%s'.") % 
95
 
                                                 formatname)
 
97
                    raise errors.BzrCommandError(
 
98
                        gettext("No such send format '%s'.") % formatname)
96
99
 
97
100
        stored_public_branch = branch.get_public_branch()
98
101
        if public_branch is None:
124
127
            raise errors.BzrCommandError(gettext('No revisions to submit.'))
125
128
        if format is None:
126
129
            format = format_registry.get()
127
 
        directive = format(branch, revision_id, submit_branch,
128
 
            public_branch, no_patch, no_bundle, message, base_revision_id)
 
130
        directive = format(branch, revision_id, target_branch,
 
131
            public_branch, no_patch, no_bundle, message, base_revision_id,
 
132
            submit_branch)
129
133
        if output is None:
130
134
            directive.compose_merge_request(mail_client, mail_to, body,
131
135
                                            branch, tree)
157
161
        branch.unlock()
158
162
 
159
163
 
160
 
def _send_4(branch, revision_id, submit_branch, public_branch,
161
 
            no_patch, no_bundle, message, base_revision_id):
 
164
def _send_4(branch, revision_id, target_branch, public_branch,
 
165
            no_patch, no_bundle, message,
 
166
            base_revision_id, local_target_branch=None):
162
167
    from bzrlib import merge_directive
163
168
    return merge_directive.MergeDirective2.from_objects(
164
169
        branch.repository, revision_id, time.time(),
165
 
        osutils.local_time_offset(), submit_branch,
166
 
        public_branch=public_branch, include_patch=not no_patch,
 
170
        osutils.local_time_offset(), target_branch,
 
171
        public_branch=public_branch,
 
172
        include_patch=not no_patch,
167
173
        include_bundle=not no_bundle, message=message,
168
 
        base_revision_id=base_revision_id)
 
174
        base_revision_id=base_revision_id,
 
175
        local_target_branch=local_target_branch)
169
176
 
170
177
 
171
178
def _send_0_9(branch, revision_id, submit_branch, public_branch,
172
 
              no_patch, no_bundle, message, base_revision_id):
 
179
              no_patch, no_bundle, message,
 
180
              base_revision_id, local_target_branch=None):
173
181
    if not no_bundle:
174
182
        if not no_patch:
175
183
            patch_type = 'bundle'
186
194
        branch.repository, revision_id, time.time(),
187
195
        osutils.local_time_offset(), submit_branch,
188
196
        public_branch=public_branch, patch_type=patch_type,
189
 
        message=message)
190
 
 
191
 
 
192
 
format_registry.register('4', 
 
197
        message=message, local_target_branch=local_target_branch)
 
198
 
 
199
 
 
200
format_registry.register('4',
193
201
    _send_4, 'Bundle format 4, Merge Directive 2 (default)')
194
202
format_registry.register('0.9',
195
203
    _send_0_9, 'Bundle format 0.9, Merge Directive 1')