1
*** modified file 'bzrlib/merge.py'
 
 
5
     location, revno = treespec
 
 
6
     branch = find_branch(location)
 
 
10
+        rev_id = branch.last_patch()
 
 
12
+        rev_id = branch.lookup_revision(revno)
 
 
13
+    return branch, get_revid_tree(branch, rev_id, temp_root, label)
 
 
15
+def get_revid_tree(branch, rev_id, temp_root, label):
 
 
17
         base_tree = branch.working_tree()
 
 
19
-        base_tree = branch.basis_tree()
 
 
21
-        base_tree = branch.revision_tree(branch.lookup_revision(revno))
 
 
22
+        base_tree = branch.revision_tree(rev_id)
 
 
23
     temp_path = os.path.join(temp_root, label)
 
 
25
-    return branch, MergeTree(base_tree, temp_path)
 
 
26
+    return MergeTree(base_tree, temp_path)
 
 
29
 def abspath(tree, file_id):
 
 
31
         If true, this_dir must have no uncommitted changes before the
 
 
34
+    from bzrlib.revision import common_ancestor, MultipleRevisionSources
 
 
35
+    from bzrlib.branch import NoSuchRevision
 
 
36
     tempdir = tempfile.mkdtemp(prefix="bzr-")
 
 
40
         this_branch = find_branch(this_dir)
 
 
41
+        this_rev_id = this_branch.last_patch()
 
 
42
+        if this_rev_id is None:
 
 
43
+            raise BzrCommandError("This branch has no commits")
 
 
45
             changes = compare_trees(this_branch.working_tree(), 
 
 
46
                                     this_branch.basis_tree(), False)
 
 
47
             if changes.has_changed():
 
 
48
                 raise BzrCommandError("Working tree has uncommitted changes.")
 
 
49
         other_branch, other_tree = get_tree(other_revision, tempdir, "other")
 
 
50
+        if other_revision[1] == -1:
 
 
51
+            other_rev_id = other_branch.last_patch()
 
 
52
+            other_basis = other_rev_id
 
 
53
+        elif other_revision[1] is not None:
 
 
54
+            other_rev_id = other_branch.lookup_revision(other_revision[1])
 
 
55
+            other_basis = other_rev_id
 
 
58
+            other_basis = other_branch.last_patch()
 
 
59
         if base_revision == [None, None]:
 
 
60
             if other_revision[1] == -1:
 
 
63
                 o_revno = other_revision[1]
 
 
64
-            base_revno = this_branch.common_ancestor(other_branch, 
 
 
65
-                                                     other_revno=o_revno)[0]
 
 
66
-            if base_revno is None:
 
 
67
+            base_rev_id = common_ancestor(this_rev_id, other_basis,
 
 
68
+                                          MultipleRevisionSources(this_branch, 
 
 
70
+            if base_rev_id is None:
 
 
71
                 raise UnrelatedBranches()
 
 
72
-            base_revision = ['.', base_revno]
 
 
73
-        base_branch, base_tree = get_tree(base_revision, tempdir, "base")
 
 
75
+                base_revision = this_branch.get_revision(base_rev_id)
 
 
76
+                base_branch = this_branch
 
 
77
+            except NoSuchRevision:
 
 
78
+                base_branch = other_branch
 
 
79
+            base_tree = get_revid_tree(base_branch, base_rev_id, tempdir, 
 
 
81
+            base_is_ancestor = True
 
 
83
+            base_branch, base_tree = get_tree(base_revision, tempdir, "base")
 
 
84
+            if base_revision[1] == -1:
 
 
85
+                base_rev_id = base_branch.last_patch()
 
 
86
+            elif base_revision[1] is None:
 
 
89
+                base_rev_id = base_branch.lookup_revision(base_revision[1])
 
 
90
+            if base_rev_id is not None:
 
 
91
+                base_is_ancestor = is_ancestor(this_rev_id, base_rev_id, 
 
 
92
+                                               MultipleRevisionSources(
 
 
96
+                base_is_ancestor = False
 
 
97
         merge_inner(this_branch, other_tree, base_tree, tempdir, 
 
 
98
                     ignore_zero=ignore_zero)
 
 
99
+        if base_is_ancestor and other_rev_id is not None:
 
 
100
+            this_branch.add_pending_merge(other_rev_id)
 
 
102
         shutil.rmtree(tempdir)