Rev 3054: Use a Graph.heads() check to determine if the ancestries are compatible. in http://bzr.arbash-meinel.com/branches/bzr/0.93-dev/pull_set_last_revision_info_172970

John Arbash Meinel john at arbash-meinel.com
Fri Nov 30 23:18:41 GMT 2007


At http://bzr.arbash-meinel.com/branches/bzr/0.93-dev/pull_set_last_revision_info_172970

------------------------------------------------------------
revno: 3054
revision-id:john at arbash-meinel.com-20071130231815-0r6ce70307kmv28r
parent: john at arbash-meinel.com-20071130045443-11kpm1ka40aix3mh
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: pull_set_last_revision_info_172970
timestamp: Fri 2007-11-30 17:18:15 -0600
message:
  Use a Graph.heads() check to determine if the ancestries are compatible.
  Whether we should do nothing because source is already ahead,
  raise an exception because we have diverged,
  or move forward because the new revision is a tip revision.
modified:
  bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
  bzrlib/tests/branch_implementations/test_pull.py test_pull.py-20060410103942-83c35b26657414fc
-------------- next part --------------
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py	2007-11-30 04:54:43 +0000
+++ b/bzrlib/branch.py	2007-11-30 23:18:15 +0000
@@ -1457,9 +1457,17 @@
             # already merged can operate on the just fetched graph, which will
             # be cached in memory.
             self.fetch(other, stop_revision)
-            if self.repository.get_graph().is_ancestor(stop_revision,
-                                                       last_rev):
+            # Check to see if one is an ancestor of the other
+            heads = self.repository.get_graph().heads([stop_revision,
+                                                       last_rev])
+            if heads == set([last_rev]):
+                # The current revision is a decendent of the target, nothing to
+                # do
                 return
+            elif heads == set([stop_revision, last_rev]):
+                # These branches have diverged
+                raise errors.DivergedBranches(self, other)
+            assert heads == set([stop_revision])
             if other_last_revision == stop_revision:
                 self.set_last_revision_info(other_last_revno,
                                             other_last_revision)

=== modified file 'bzrlib/tests/branch_implementations/test_pull.py'
--- a/bzrlib/tests/branch_implementations/test_pull.py	2007-11-08 23:36:39 +0000
+++ b/bzrlib/tests/branch_implementations/test_pull.py	2007-11-30 23:18:15 +0000
@@ -88,6 +88,13 @@
         tree_a.commit('message 2', rev_id='rev2a')
         tree_b.commit('message 2', rev_id='rev2b')
         self.assertRaises(errors.DivergedBranches, tree_a.pull, tree_b.branch)
+        self.assertRaises(errors.DivergedBranches,
+                          tree_a.branch.pull, tree_b.branch,
+                          overwrite=False, stop_revision='rev2b')
+        # It should not have updated the branch tip, but it should have fetched
+        # the revision
+        self.assertEqual('rev2a', tree_a.branch.last_revision())
+        self.assertTrue(tree_a.branch.repository.has_revision('rev2b'))
         tree_a.branch.pull(tree_b.branch, overwrite=True,
                            stop_revision='rev2b')
         self.assertEqual('rev2b', tree_a.branch.last_revision())



More information about the bazaar-commits mailing list