~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/push.py

  • Committer: Martin Pool
  • Date: 2009-03-13 03:01:14 UTC
  • mfrom: (4138 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4144.
  • Revision ID: mbp@sourcefrog.net-20090313030114-y723gefxl8tfynsd
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
from bzrlib.trace import note, warning
22
22
 
23
23
 
 
24
class PushResult(object):
 
25
    """Result of a push operation.
 
26
 
 
27
    :ivar branch_push_result: Result of a push between branches
 
28
    :ivar stacked_on: URL of the branch on which the result is stacked
 
29
    """
 
30
 
 
31
    def __init__(self):
 
32
        self.branch_push_result = None
 
33
        self.stacked_on = None
 
34
 
 
35
    def report(self, to_file):
 
36
        """Write a human-readable description of the result."""
 
37
        if self.branch_push_result is None:
 
38
            if self.stacked_on is not None:
 
39
                note('Created new stacked branch referring to %s.' %
 
40
                    self.stacked_on)
 
41
            else:
 
42
                note('Created new branch.')
 
43
        else:
 
44
            self.branch_push_result.report(to_file)
 
45
 
 
46
 
24
47
def _show_push_branch(br_from, revision_id, location, to_file, verbose=False,
25
48
    overwrite=False, remember=False, stacked_on=None, create_prefix=False,
26
49
    use_existing_dir=False):
63
86
            # Found a branch, so we must have found a repository
64
87
            repository_to = br_to.repository
65
88
 
66
 
    push_result = None
 
89
    push_result = PushResult()
67
90
    if dir_to is None:
68
91
        # The destination doesn't exist; create it.
69
92
        # XXX: Refactor the create_prefix/no_create_prefix code into a
105
128
            revision_id=revision_id, stacked_on=stacked_on)
106
129
        # TODO: Some more useful message about what was copied
107
130
        try:
108
 
            finally_stacked_on = br_to.get_stacked_on_url()
 
131
            push_result.stacked_on = br_to.get_stacked_on_url()
109
132
        except (errors.UnstackableBranchFormat,
110
133
                errors.UnstackableRepositoryFormat,
111
134
                errors.NotStacked):
112
 
            finally_stacked_on = None
113
 
        if finally_stacked_on is not None:
114
 
            note('Created new stacked branch referring to %s.' %
115
 
                 finally_stacked_on)
116
 
        else:
117
 
            note('Created new branch.')
 
135
            push_result.stacked_on = None
118
136
        # We successfully created the target, remember it
119
137
        if br_from.get_push_location() is None or remember:
120
138
            br_from.set_push_location(br_to.base)
134
152
                    "already exists at the destination location.")
135
153
        repository_to.fetch(br_from.repository, revision_id=revision_id)
136
154
        br_to = br_from.clone(dir_to, revision_id=revision_id)
137
 
        note('Created new branch.')
138
155
        if br_from.get_push_location() is None or remember:
139
156
            br_from.set_push_location(br_to.base)
140
157
    else: # We have a valid to branch
150
167
                tree_to = dir_to.open_workingtree()
151
168
            except errors.NotLocalUrl:
152
169
                note("This transport does not update the working "
153
 
                     "tree of: %s. See 'bzr help working-trees' for "
154
 
                     "more information." % br_to.base)
155
 
                push_result = br_from.push(br_to, overwrite,
156
 
                                           stop_revision=revision_id)
 
170
                        "tree of: %s. See 'bzr help working-trees' for "
 
171
                        "more information." % br_to.base)
 
172
                push_result.branch_push_result = br_from.push(br_to, overwrite,
 
173
                                                   stop_revision=revision_id)
157
174
            except errors.NoWorkingTree:
158
 
                push_result = br_from.push(br_to, overwrite,
159
 
                                           stop_revision=revision_id)
 
175
                push_result.branch_push_result = br_from.push(br_to, overwrite,
 
176
                                                   stop_revision=revision_id)
160
177
            else:
161
178
                tree_to.lock_write()
162
179
                try:
163
 
                    push_result = br_from.push(tree_to.branch, overwrite,
164
 
                                               stop_revision=revision_id)
 
180
                    push_result.branch_push_result = br_from.push(tree_to.branch,
 
181
                        overwrite, stop_revision=revision_id)
165
182
                    tree_to.update()
166
183
                finally:
167
184
                    tree_to.unlock()
168
185
        except errors.DivergedBranches:
169
186
            raise errors.BzrCommandError('These branches have diverged.'
170
187
                                    '  Try using "merge" and then "push".')
171
 
    if push_result is not None:
172
 
        push_result.report(to_file)
173
 
        old_revid = push_result.old_revid
174
 
        old_revno = push_result.old_revno
 
188
    push_result.report(to_file)
 
189
    if push_result.branch_push_result is not None:
 
190
        old_revid = push_result.branch_push_result.old_revid
 
191
        old_revno = push_result.branch_push_result.old_revno
175
192
    else:
176
193
        old_revid = _mod_revision.NULL_REVISION
177
194
        old_revno = 0