~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/send.py

  • Committer: INADA Naoki
  • Date: 2011-05-18 06:27:34 UTC
  • mfrom: (5887 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5894.
  • Revision ID: songofacandy@gmail.com-20110518062734-1ilhll0rrqyyp8um
merge from lp:bzr and resolve conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009 Canonical Ltd
 
1
# Copyright (C) 2009, 2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
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 (
21
22
    bzrdir,
22
23
    errors,
23
 
    merge_directive,
24
24
    osutils,
25
25
    registry,
26
26
    trace,
63
63
            submit_branch = stored_submit_branch
64
64
            remembered_submit_branch = "submit"
65
65
        else:
66
 
            if stored_submit_branch is None or remember:
 
66
            # Remembers if asked explicitly or no previous location is set
 
67
            if remember or (remember is None and stored_submit_branch is None):
67
68
                branch.set_submit_branch(submit_branch)
68
69
        if submit_branch is None:
69
70
            submit_branch = branch.get_parent()
95
96
        stored_public_branch = branch.get_public_branch()
96
97
        if public_branch is None:
97
98
            public_branch = stored_public_branch
98
 
        elif stored_public_branch is None or remember:
 
99
        # Remembers if asked explicitly or no previous location is set
 
100
        elif (remember
 
101
              or (remember is None and stored_public_branch is None)):
99
102
            branch.set_public_branch(public_branch)
100
103
        if no_bundle and public_branch is None:
101
104
            raise errors.BzrCommandError('No public branch specified or'
110
113
            if len(revision) == 2:
111
114
                base_revision_id = revision[0].as_revision_id(branch)
112
115
        if revision_id is None:
113
 
            if strict is None:
114
 
                strict = branch.get_config(
115
 
                    ).get_user_option_as_bool('send_strict')
116
 
            if strict is None: strict = True # default value
117
 
            if strict and tree is not None:
118
 
                if (tree.has_changes(tree.basis_tree())
119
 
                    or len(tree.get_parent_ids()) > 1):
120
 
                    raise errors.UncommittedChanges(
121
 
                        tree, more='Use --no-strict to force the send.')
122
 
                if tree.last_revision() != tree.branch.last_revision():
123
 
                    # The tree has lost sync with its branch, there is little
124
 
                    # chance that the user is aware of it but he can still force
125
 
                    # the push with --no-strict
126
 
                    raise errors.OutOfDateTree(
127
 
                        tree, more='Use --no-strict to force the send.')
 
116
            if tree is not None:
 
117
                tree.check_changed_or_out_of_date(
 
118
                    strict, 'send_strict',
 
119
                    more_error='Use --no-strict to force the send.',
 
120
                    more_warning='Uncommitted changes will not be sent.')
128
121
            revision_id = branch.last_revision()
129
122
        if revision_id == NULL_REVISION:
130
123
            raise errors.BzrCommandError('No revisions to submit.')
136
129
            directive.compose_merge_request(mail_client, mail_to, body,
137
130
                                            branch, tree)
138
131
        else:
139
 
            if output == '-':
140
 
                outfile = to_file
 
132
            if directive.multiple_output_files:
 
133
                if output == '-':
 
134
                    raise errors.BzrCommandError('- not supported for '
 
135
                        'merge directives that use more than one output file.')
 
136
                if not os.path.exists(output):
 
137
                    os.mkdir(output, 0755)
 
138
                for (filename, lines) in directive.to_files():
 
139
                    path = os.path.join(output, filename)
 
140
                    outfile = open(path, 'wb')
 
141
                    try:
 
142
                        outfile.writelines(lines)
 
143
                    finally:
 
144
                        outfile.close()
141
145
            else:
142
 
                outfile = open(output, 'wb')
143
 
            try:
144
 
                outfile.writelines(directive.to_lines())
145
 
            finally:
146
 
                if outfile is not to_file:
147
 
                    outfile.close()
 
146
                if output == '-':
 
147
                    outfile = to_file
 
148
                else:
 
149
                    outfile = open(output, 'wb')
 
150
                try:
 
151
                    outfile.writelines(directive.to_lines())
 
152
                finally:
 
153
                    if outfile is not to_file:
 
154
                        outfile.close()
148
155
    finally:
149
156
        branch.unlock()
150
157
 
151
158
 
152
159
def _send_4(branch, revision_id, submit_branch, public_branch,
153
160
            no_patch, no_bundle, message, base_revision_id):
 
161
    from bzrlib import merge_directive
154
162
    return merge_directive.MergeDirective2.from_objects(
155
163
        branch.repository, revision_id, time.time(),
156
164
        osutils.local_time_offset(), submit_branch,
172
180
            patch_type = 'diff'
173
181
        else:
174
182
            patch_type = None
 
183
    from bzrlib import merge_directive
175
184
    return merge_directive.MergeDirective.from_objects(
176
185
        branch.repository, revision_id, time.time(),
177
186
        osutils.local_time_offset(), submit_branch,