~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: 2010-09-29 22:03:03 UTC
  • mfrom: (5416.2.6 jam-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20100929220303-cr95h8iwtggco721
(mbp) Add 'break-lock --force'

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,
37
37
 
38
38
 
39
39
def send(submit_branch, revision, public_branch, remember, format,
40
 
         no_bundle, no_patch, output, from_, mail_to, message, body, 
41
 
         to_file):
 
40
         no_bundle, no_patch, output, from_, mail_to, message, body,
 
41
         to_file, strict=None):
42
42
    tree, branch = bzrdir.BzrDir.open_containing_tree_or_branch(from_)[:2]
43
43
    # we may need to write data into branch's repository to calculate
44
44
    # the data to send.
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
80
83
            submit_br = Branch.open(submit_branch)
81
84
            submit_config = submit_br.get_config()
82
85
            if mail_to is None:
107
110
            if len(revision) == 2:
108
111
                base_revision_id = revision[0].as_revision_id(branch)
109
112
        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
118
            revision_id = branch.last_revision()
111
119
        if revision_id == NULL_REVISION:
112
120
            raise errors.BzrCommandError('No revisions to submit.')
113
121
        if format is None:
114
 
            # TODO: Query submit branch for its preferred format
115
122
            format = format_registry.get()
116
 
        directive = format(branch, revision_id, submit_branch, 
 
123
        directive = format(branch, revision_id, submit_branch,
117
124
            public_branch, no_patch, no_bundle, message, base_revision_id)
118
125
        if output is None:
119
126
            directive.compose_merge_request(mail_client, mail_to, body,
120
127
                                            branch, tree)
121
128
        else:
122
 
            if output == '-':
123
 
                outfile = to_file
 
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()
124
142
            else:
125
 
                outfile = open(output, 'wb')
126
 
            try:
127
 
                outfile.writelines(directive.to_lines())
128
 
            finally:
129
 
                if outfile is not to_file:
130
 
                    outfile.close()
 
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()
131
152
    finally:
132
153
        branch.unlock()
133
154
 
134
155
 
135
156
def _send_4(branch, revision_id, submit_branch, public_branch,
136
157
            no_patch, no_bundle, message, base_revision_id):
 
158
    from bzrlib import merge_directive
137
159
    return merge_directive.MergeDirective2.from_objects(
138
160
        branch.repository, revision_id, time.time(),
139
161
        osutils.local_time_offset(), submit_branch,
155
177
            patch_type = 'diff'
156
178
        else:
157
179
            patch_type = None
 
180
    from bzrlib import merge_directive
158
181
    return merge_directive.MergeDirective.from_objects(
159
182
        branch.repository, revision_id, time.time(),
160
183
        osutils.local_time_offset(), submit_branch,