~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/send.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-08-03 07:15:11 UTC
  • mfrom: (4580.1.2 408199-check-2a)
  • Revision ID: pqm@pqm.ubuntu.com-20090803071511-dwb041qzak0vjzdk
(mbp) check blackbox tests now handle the root being included in the
        file-id count

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2009 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
19
18
import time
20
19
 
21
20
from bzrlib import (
22
21
    bzrdir,
23
22
    errors,
 
23
    merge_directive,
24
24
    osutils,
25
25
    registry,
26
26
    trace,
77
77
                       submit_branch)
78
78
 
79
79
        if mail_to is None or format is None:
80
 
            # TODO: jam 20090716 we open the submit_branch here, but we *don't*
81
 
            #       pass it down into the format creation, so it will have to
82
 
            #       open it again
83
80
            submit_br = Branch.open(submit_branch)
84
81
            submit_config = submit_br.get_config()
85
82
            if mail_to is None:
110
107
            if len(revision) == 2:
111
108
                base_revision_id = revision[0].as_revision_id(branch)
112
109
        if revision_id is None:
113
 
            if tree is not None:
114
 
                tree.check_changed_or_out_of_date(
115
 
                    strict, 'send_strict',
116
 
                    more_error='Use --no-strict to force the send.',
117
 
                    more_warning='Uncommitted changes will not be sent.')
 
110
            if strict is None:
 
111
                strict = branch.get_config(
 
112
                    ).get_user_option_as_bool('send_strict')
 
113
            if strict is None: strict = True # default value
 
114
            if strict and tree is not None:
 
115
                if (tree.has_changes(tree.basis_tree())
 
116
                    or len(tree.get_parent_ids()) > 1):
 
117
                    raise errors.UncommittedChanges(
 
118
                        tree, more='Use --no-strict to force the send.')
 
119
                if tree.last_revision() != tree.branch.last_revision():
 
120
                    # The tree has lost sync with its branch, there is little
 
121
                    # chance that the user is aware of it but he can still force
 
122
                    # the push with --no-strict
 
123
                    raise errors.OutOfDateTree(
 
124
                        tree, more='Use --no-strict to force the send.')
118
125
            revision_id = branch.last_revision()
119
126
        if revision_id == NULL_REVISION:
120
127
            raise errors.BzrCommandError('No revisions to submit.')
121
128
        if format is None:
 
129
            # TODO: Query submit branch for its preferred format
122
130
            format = format_registry.get()
123
131
        directive = format(branch, revision_id, submit_branch,
124
132
            public_branch, no_patch, no_bundle, message, base_revision_id)
126
134
            directive.compose_merge_request(mail_client, mail_to, body,
127
135
                                            branch, tree)
128
136
        else:
129
 
            if directive.multiple_output_files:
130
 
                if output == '-':
131
 
                    raise errors.BzrCommandError('- not supported for '
132
 
                        'merge directives that use more than one output file.')
133
 
                if not os.path.exists(output):
134
 
                    os.mkdir(output, 0755)
135
 
                for (filename, lines) in directive.to_files():
136
 
                    path = os.path.join(output, filename)
137
 
                    outfile = open(path, 'wb')
138
 
                    try:
139
 
                        outfile.writelines(lines)
140
 
                    finally:
141
 
                        outfile.close()
 
137
            if output == '-':
 
138
                outfile = to_file
142
139
            else:
143
 
                if output == '-':
144
 
                    outfile = to_file
145
 
                else:
146
 
                    outfile = open(output, 'wb')
147
 
                try:
148
 
                    outfile.writelines(directive.to_lines())
149
 
                finally:
150
 
                    if outfile is not to_file:
151
 
                        outfile.close()
 
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()
152
146
    finally:
153
147
        branch.unlock()
154
148
 
155
149
 
156
150
def _send_4(branch, revision_id, submit_branch, public_branch,
157
151
            no_patch, no_bundle, message, base_revision_id):
158
 
    from bzrlib import merge_directive
159
152
    return merge_directive.MergeDirective2.from_objects(
160
153
        branch.repository, revision_id, time.time(),
161
154
        osutils.local_time_offset(), submit_branch,
177
170
            patch_type = 'diff'
178
171
        else:
179
172
            patch_type = None
180
 
    from bzrlib import merge_directive
181
173
    return merge_directive.MergeDirective.from_objects(
182
174
        branch.repository, revision_id, time.time(),
183
175
        osutils.local_time_offset(), submit_branch,