~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/send.py

  • Committer: John Arbash Meinel
  • Date: 2009-07-06 20:21:34 UTC
  • mto: This revision was merged to the branch mainline in revision 4522.
  • Revision ID: john@arbash-meinel.com-20090706202134-19iakgxrs3yxi7k7
Tests that VF implementations support .get_annotator()
This also meant supporting no-graph style VF implementations, which
wasn't too bad.

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,
63
63
            submit_branch = stored_submit_branch
64
64
            remembered_submit_branch = "submit"
65
65
        else:
66
 
            # Remembers if asked explicitly or no previous location is set
67
 
            if remember or (remember is None and stored_submit_branch is None):
 
66
            if stored_submit_branch is None or remember:
68
67
                branch.set_submit_branch(submit_branch)
69
68
        if submit_branch is None:
70
69
            submit_branch = branch.get_parent()
78
77
                       submit_branch)
79
78
 
80
79
        if mail_to is None or format is None:
81
 
            # TODO: jam 20090716 we open the submit_branch here, but we *don't*
82
 
            #       pass it down into the format creation, so it will have to
83
 
            #       open it again
84
80
            submit_br = Branch.open(submit_branch)
85
81
            submit_config = submit_br.get_config()
86
82
            if mail_to is None:
96
92
        stored_public_branch = branch.get_public_branch()
97
93
        if public_branch is None:
98
94
            public_branch = stored_public_branch
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)):
 
95
        elif stored_public_branch is None or remember:
102
96
            branch.set_public_branch(public_branch)
103
97
        if no_bundle and public_branch is None:
104
98
            raise errors.BzrCommandError('No public branch specified or'
113
107
            if len(revision) == 2:
114
108
                base_revision_id = revision[0].as_revision_id(branch)
115
109
        if revision_id is None:
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.')
 
110
            if strict is None:
 
111
                strict = branch.get_config().get_user_option('send_strict')
 
112
                if strict is not None:
 
113
                    # FIXME: This should be better supported by config
 
114
                    # -- vila 20090626
 
115
                    bools = dict(yes=True, no=False, on=True, off=False,
 
116
                                 true=True, false=False)
 
117
                    try:
 
118
                        strict = bools[strict.lower()]
 
119
                    except KeyError:
 
120
                        strict = None
 
121
            if tree is not None and (strict is None or strict):
 
122
                changes = tree.changes_from(tree.basis_tree())
 
123
                if changes.has_changed() or len(tree.get_parent_ids()) > 1:
 
124
                    raise errors.UncommittedChanges(
 
125
                        tree, more='Use --no-strict to force the send.')
 
126
                if tree.last_revision() != tree.branch.last_revision():
 
127
                    # The tree has lost sync with its branch, there is little
 
128
                    # chance that the user is aware of it but he can still force
 
129
                    # the push with --no-strict
 
130
                    raise errors.OutOfDateTree(
 
131
                        tree, more='Use --no-strict to force the send.')
121
132
            revision_id = branch.last_revision()
122
133
        if revision_id == NULL_REVISION:
123
134
            raise errors.BzrCommandError('No revisions to submit.')
124
135
        if format is None:
 
136
            # TODO: Query submit branch for its preferred format
125
137
            format = format_registry.get()
126
138
        directive = format(branch, revision_id, submit_branch,
127
139
            public_branch, no_patch, no_bundle, message, base_revision_id)
129
141
            directive.compose_merge_request(mail_client, mail_to, body,
130
142
                                            branch, tree)
131
143
        else:
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()
 
144
            if output == '-':
 
145
                outfile = to_file
145
146
            else:
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()
 
147
                outfile = open(output, 'wb')
 
148
            try:
 
149
                outfile.writelines(directive.to_lines())
 
150
            finally:
 
151
                if outfile is not to_file:
 
152
                    outfile.close()
155
153
    finally:
156
154
        branch.unlock()
157
155
 
158
156
 
159
157
def _send_4(branch, revision_id, submit_branch, public_branch,
160
158
            no_patch, no_bundle, message, base_revision_id):
161
 
    from bzrlib import merge_directive
162
159
    return merge_directive.MergeDirective2.from_objects(
163
160
        branch.repository, revision_id, time.time(),
164
161
        osutils.local_time_offset(), submit_branch,
180
177
            patch_type = 'diff'
181
178
        else:
182
179
            patch_type = None
183
 
    from bzrlib import merge_directive
184
180
    return merge_directive.MergeDirective.from_objects(
185
181
        branch.repository, revision_id, time.time(),
186
182
        osutils.local_time_offset(), submit_branch,