~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge.py

  • Committer: aaron.bentley at utoronto
  • Date: 2005-08-23 05:25:51 UTC
  • mto: (1092.1.41) (1185.3.4)
  • mto: This revision was merged to the branch mainline in revision 1110.
  • Revision ID: aaron.bentley@utoronto.ca-20050823052551-f3401a8b57d9126f
Committed it even though the test case doesn't work

Show diffs side-by-side

added added

removed removed

Lines of Context:
122
122
    location, revno = treespec
123
123
    branch = find_branch(location)
124
124
    if revno is None:
 
125
        revision = None
 
126
    elif revno == -1:
 
127
        revision = branch.last_patch()
 
128
    else:
 
129
        revision = branch.lookup_revision(revno)
 
130
    return branch, get_revid_tree(branch, revision, temp_root, label,
 
131
                                  local_branch)
 
132
 
 
133
def get_revid_tree(branch, revision, temp_root, label, local_branch):
 
134
    if revision is None:
125
135
        base_tree = branch.working_tree()
126
136
    else:
127
 
        if revno == -1:
128
 
            revision = branch.last_patch()
129
 
        else:
130
 
            revision = branch.lookup_revision(revno)
131
137
        if local_branch is not None:
132
 
            if revision is not None:
133
 
                greedy_fetch(local_branch, branch, revision)
 
138
            greedy_fetch(local_branch, branch, revision)
134
139
            base_tree = local_branch.revision_tree(revision)
135
140
        else:
136
141
            base_tree = branch.revision_tree(revision)
137
142
    temp_path = os.path.join(temp_root, label)
138
143
    os.mkdir(temp_path)
139
 
    return branch, MergeTree(base_tree, temp_path)
 
144
    return MergeTree(base_tree, temp_path)
140
145
 
141
146
 
142
147
def file_exists(tree, file_id):
209
214
    all available ancestors of other_revision and base_revision are
210
215
    automatically pulled into the branch.
211
216
    """
 
217
    from bzrlib.revision import common_ancestor, MultipleRevisionSources
 
218
    from bzrlib.errors import NoSuchRevision
212
219
    tempdir = tempfile.mkdtemp(prefix="bzr-")
213
220
    try:
214
221
        if this_dir is None:
215
222
            this_dir = '.'
216
223
        this_branch = find_branch(this_dir)
 
224
        this_rev_id = this_branch.last_patch()
 
225
        if this_rev_id is None:
 
226
            raise BzrCommandError("This branch has no commits")
217
227
        if check_clean:
218
228
            changes = compare_trees(this_branch.working_tree(), 
219
229
                                    this_branch.basis_tree(), False)
221
231
                raise BzrCommandError("Working tree has uncommitted changes.")
222
232
        other_branch, other_tree = get_tree(other_revision, tempdir, "other",
223
233
                                            this_branch)
 
234
        if other_revision[1] == -1:
 
235
            other_rev_id = other_branch.last_patch()
 
236
            other_basis = other_rev_id
 
237
        elif other_revision[1] is not None:
 
238
            other_rev_id = other_branch.lookup_revision(other_revision[1])
 
239
            other_basis = other_rev_id
 
240
        else:
 
241
            other_rev_id = None
 
242
            other_basis = other_branch.last_patch()
224
243
        if base_revision == [None, None]:
225
244
            if other_revision[1] == -1:
226
245
                o_revno = None
227
246
            else:
228
247
                o_revno = other_revision[1]
229
 
            base_revno = this_branch.common_ancestor(other_branch, 
230
 
                                                     other_revno=o_revno)[0]
231
 
            if base_revno is None:
232
248
                raise UnrelatedBranches()
233
 
            base_revision = ['.', base_revno]
234
 
        base_branch, base_tree = get_tree(base_revision, tempdir, "base",
235
 
                                          this_branch)
 
249
            try:
 
250
                base_revision = this_branch.get_revision(base_rev_id)
 
251
                base_branch = this_branch
 
252
            except NoSuchRevision:
 
253
                base_branch = other_branch
 
254
            base_tree = get_revid_tree(base_branch, base_rev_id, tempdir, 
 
255
                                       "base")
 
256
            base_is_ancestor = True
 
257
        else:
 
258
            base_branch, base_tree = get_tree(base_revision, tempdir, "base")
 
259
            if base_revision[1] == -1:
 
260
                base_rev_id = base_branch.last_patch()
 
261
            elif base_revision[1] is None:
 
262
                base_rev_id = None
 
263
            else:
 
264
                base_rev_id = base_branch.lookup_revision(base_revision[1])
 
265
            if base_rev_id is not None:
 
266
                base_is_ancestor = is_ancestor(this_rev_id, base_rev_id, 
 
267
                                               MultipleRevisionSources(
 
268
                                               this_branch, 
 
269
                                               base_branch))
 
270
            else:
 
271
                base_is_ancestor = False
236
272
        if file_list is None:
237
273
            interesting_ids = None
238
274
        else:
252
288
        merge_inner(this_branch, other_tree, base_tree, tempdir, 
253
289
                    ignore_zero=ignore_zero, backup_files=backup_files, 
254
290
                    merge_type=merge_type, interesting_ids=interesting_ids)
 
291
        if base_is_ancestor and other_rev_id is not None:
 
292
            this_branch.add_pending_merge(other_rev_id)
255
293
    finally:
256
294
        shutil.rmtree(tempdir)
257
295