Rev 3055: deprecate revision.is_ancestor, update the callers and the tests. in http://bzr.arbash-meinel.com/branches/bzr/0.93-dev/is_ancestor_fix

John Arbash Meinel john at arbash-meinel.com
Fri Nov 30 14:53:00 GMT 2007


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

------------------------------------------------------------
revno: 3055
revision-id:john at arbash-meinel.com-20071130145230-njpq31mmf39l2zow
parent: john at arbash-meinel.com-20071130141824-p3e0r9p6gf5xth5n
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: is_ancestor_fix
timestamp: Fri 2007-11-30 08:52:30 -0600
message:
  deprecate revision.is_ancestor, update the callers and the tests.
modified:
  bzrlib/graph.py                graph_walker.py-20070525030359-y852guab65d4wtn0-1
  bzrlib/merge.py                merge.py-20050513021216-953b65a438527106
  bzrlib/revision.py             revision.py-20050309040759-e77802c08f3999d5
  bzrlib/tests/test_ancestry.py  test_ancestry.py-20050913023709-69768e94848312c6
-------------- next part --------------
=== modified file 'bzrlib/graph.py'
--- a/bzrlib/graph.py	2007-11-28 00:59:30 +0000
+++ b/bzrlib/graph.py	2007-11-30 14:52:30 +0000
@@ -16,6 +16,7 @@
 
 from bzrlib import (
     errors,
+    revision,
     tsort,
     )
 from bzrlib.deprecated_graph import (node_distances, select_farthest)
@@ -347,6 +348,8 @@
         smallest number of parent looksup to determine the ancestral
         relationship between N revisions.
         """
+        if revision.is_null(candidate_ancestor):
+            return True
         return set([candidate_descendant]) == self.heads(
             [candidate_ancestor, candidate_descendant])
 

=== modified file 'bzrlib/merge.py'
--- a/bzrlib/merge.py	2007-10-26 19:18:48 +0000
+++ b/bzrlib/merge.py	2007-11-30 14:52:30 +0000
@@ -44,7 +44,7 @@
 from bzrlib.merge3 import Merge3
 from bzrlib.osutils import rename, pathjoin
 from progress import DummyProgress, ProgressPhase
-from bzrlib.revision import (is_ancestor, NULL_REVISION, ensure_null)
+from bzrlib.revision import (NULL_REVISION, ensure_null)
 from bzrlib.textfile import check_text_lines
 from bzrlib.trace import mutter, warning, note
 from bzrlib.transform import (TreeTransform, resolve_conflicts, cook_conflicts,
@@ -296,12 +296,11 @@
         self.base_branch = branch
         self._maybe_fetch(branch, self.this_branch, revision_id)
         self.base_tree = self.revision_tree(revision_id)
-        self.base_is_ancestor = is_ancestor(self.this_basis,
-                                            self.base_rev_id,
-                                            self.this_branch)
-        self.base_is_other_ancestor = is_ancestor(self.other_basis,
-                                                  self.base_rev_id,
-                                                  self.this_branch)
+        graph = self.this_branch.repository.get_graph()
+        self.base_is_ancestor = graph.is_ancestor(self.base_rev_id,
+                                                  self.this_basis)
+        self.base_is_other_ancestor = graph.is_ancestor(self.base_rev_id,
+                                                        self.other_basis)
 
     def _maybe_fetch(self, source, target, revision_id):
         if not source.repository.has_same_location(target.repository):
@@ -340,12 +339,11 @@
                 self.base_rev_id = _mod_revision.ensure_null(
                     base_branch.get_rev_id(base_revision[1]))
             self._maybe_fetch(base_branch, self.this_branch, self.base_rev_id)
-            self.base_is_ancestor = is_ancestor(self.this_basis, 
-                                                self.base_rev_id,
-                                                self.this_branch)
-            self.base_is_other_ancestor = is_ancestor(self.other_basis,
-                                                      self.base_rev_id,
-                                                      self.this_branch)
+            graph = self.this_branch.repository.get_graph()
+            self.base_is_ancestor = graph.is_ancestor(self.base_rev_id,
+                                                      self.this_basis)
+            self.base_is_other_ancestor = graph.is_ancestor(self.base_rev_id,
+                                                            self.other_basis)
 
     def do_merge(self):
         kwargs = {'working_tree':self.this_tree, 'this_tree': self.this_tree,

=== modified file 'bzrlib/revision.py'
--- a/bzrlib/revision.py	2007-11-30 03:34:33 +0000
+++ b/bzrlib/revision.py	2007-11-30 14:52:30 +0000
@@ -125,6 +125,7 @@
         return self.properties.get('author', self.committer)
 
 
+ at deprecated_function(symbol_versioning.zero_ninetythree)
 def is_ancestor(revision_id, candidate_id, branch):
     """Return true if candidate_id is an ancestor of revision_id.
 
@@ -133,9 +134,10 @@
     
     revisions_source is an object supporting a get_revision operation that
     behaves like Branch's.
+
+    This function is deprecated, it is better for callers to directly use
+    Graph.is_ancestor() (just watch out that the parameter order is switched)
     """
-    if is_null(candidate_id):
-        return True
     return branch.repository.get_graph().is_ancestor(candidate_id, revision_id)
 
 

=== modified file 'bzrlib/tests/test_ancestry.py'
--- a/bzrlib/tests/test_ancestry.py	2007-11-30 14:18:24 +0000
+++ b/bzrlib/tests/test_ancestry.py	2007-11-30 14:52:30 +0000
@@ -23,6 +23,7 @@
 from bzrlib.branch import Branch
 from bzrlib.branchbuilder import BranchBuilder
 from bzrlib.revision import is_ancestor
+from bzrlib.symbol_versioning import zero_ninetythree
 
 
 class TestAncestry(TestCaseWithMemoryTransport):
@@ -44,7 +45,8 @@
 
     def test_none_is_ancestor_empty_branch(self):
         branch = self.make_branch('.')
-        self.assertTrue(is_ancestor('null:', 'null:', branch))
+        self.assertTrue(self.applyDeprecated(zero_ninetythree,
+                        is_ancestor, 'null:', 'null:', branch))
 
     def test_none_is_ancestor_non_empty_branch(self):
         builder = BranchBuilder(self.get_transport())
@@ -52,9 +54,12 @@
         branch = builder.get_branch()
         branch.lock_read()
         self.addCleanup(branch.unlock)
-        self.assertTrue(is_ancestor('null:', 'null:', branch))
-        self.assertTrue(is_ancestor(rev_id, 'null:',  branch))
-        self.assertFalse(is_ancestor('null:', rev_id, branch))
+        self.assertTrue(self.applyDeprecated(zero_ninetythree,
+                        is_ancestor, 'null:', 'null:', branch))
+        self.assertTrue(self.applyDeprecated(zero_ninetythree,
+                        is_ancestor, rev_id, 'null:',  branch))
+        self.assertFalse(self.applyDeprecated(zero_ninetythree,
+                         is_ancestor, 'null:', rev_id, branch))
 
 
 # TODO: check that ancestry is updated to include indirectly merged revisions



More information about the bazaar-commits mailing list