[PATCH] revlog: ancestors() takes list of revs rather than a *revs

Joshua Redstone joshua.redstone at fb.com
Fri Jun 1 11:16:20 CDT 2012


# HG changeset patch
# User Joshua Redstone <joshua.redstone at fb.com>
# Date 1338567235 25200
# Node ID 82a0af4e593f0ce9f0bc189b09c3410471a01320
# Parent  2ac08d8b21aa7b6e0a062afed5a3f357ccef67f9
revlog: ancestors() takes list of revs rather than a *revs

This makes ancestors() amenable to the addition of a default
argument.  This is a step towards converting calls to reachable()
to ancestors() and removing reachable().

diff -r 2ac08d8b21aa -r 82a0af4e593f hgext/rebase.py
--- a/hgext/rebase.py	Tue May 22 14:37:20 2012 -0500
+++ b/hgext/rebase.py	Fri Jun 01 09:13:55 2012 -0700
@@ -224,7 +224,7 @@
             else:
                 originalwd, target, state = result
                 if collapsef:
-                    targetancestors = set(repo.changelog.ancestors(target))
+                    targetancestors = set(repo.changelog.ancestors([target]))
                     targetancestors.add(target)
                     external = checkexternal(repo, state, targetancestors)
 
@@ -243,7 +243,7 @@
 
         # Rebase
         if not targetancestors:
-            targetancestors = set(repo.changelog.ancestors(target))
+            targetancestors = set(repo.changelog.ancestors([target]))
             targetancestors.add(target)
 
         # Keep track of the current bookmarks in order to reset them later
diff -r 2ac08d8b21aa -r 82a0af4e593f mercurial/commands.py
--- a/mercurial/commands.py	Tue May 22 14:37:20 2012 -0500
+++ b/mercurial/commands.py	Fri Jun 01 09:13:55 2012 -0700
@@ -5442,12 +5442,12 @@
     cl = repo.changelog
     for a in [cl.rev(n) for n in bheads]:
         new[a] = 1
-    for a in cl.ancestors(*[cl.rev(n) for n in bheads]):
+    for a in cl.ancestors([cl.rev(n) for n in bheads]):
         new[a] = 1
     for a in [p.rev() for p in parents]:
         if a >= 0:
             new[a] = 0
-    for a in cl.ancestors(*[p.rev() for p in parents]):
+    for a in cl.ancestors([p.rev() for p in parents]):
         new[a] = 0
     new = sum(new)
 
diff -r 2ac08d8b21aa -r 82a0af4e593f mercurial/context.py
--- a/mercurial/context.py	Tue May 22 14:37:20 2012 -0500
+++ b/mercurial/context.py	Fri Jun 01 09:13:55 2012 -0700
@@ -223,7 +223,7 @@
         return [changectx(self._repo, x) for x in c]
 
     def ancestors(self):
-        for a in self._repo.changelog.ancestors(self._rev):
+        for a in self._repo.changelog.ancestors([self._rev]):
             yield changectx(self._repo, a)
 
     def descendants(self):
@@ -1019,7 +1019,7 @@
 
     def ancestors(self):
         for a in self._repo.changelog.ancestors(
-            *[p.rev() for p in self._parents]):
+            [p.rev() for p in self._parents]):
             yield changectx(self._repo, a)
 
     def undelete(self, list):
diff -r 2ac08d8b21aa -r 82a0af4e593f mercurial/discovery.py
--- a/mercurial/discovery.py	Tue May 22 14:37:20 2012 -0500
+++ b/mercurial/discovery.py	Fri Jun 01 09:13:55 2012 -0700
@@ -140,7 +140,7 @@
         og._computecommonmissing()
         cl = repo.changelog
         missingrevs = set(cl.rev(n) for n in og._missing)
-        og._common = set(cl.ancestors(*missingrevs)) - missingrevs
+        og._common = set(cl.ancestors(missingrevs)) - missingrevs
         commonheads = set(og.commonheads)
         og.missingheads = [h for h in og.missingheads if h not in commonheads]
 
diff -r 2ac08d8b21aa -r 82a0af4e593f mercurial/localrepo.py
--- a/mercurial/localrepo.py	Tue May 22 14:37:20 2012 -0500
+++ b/mercurial/localrepo.py	Fri Jun 01 09:13:55 2012 -0700
@@ -1791,7 +1791,7 @@
             bases = [nullid]
         csets, bases, heads = cl.nodesbetween(bases, heads)
         # We assume that all ancestors of bases are known
-        common = set(cl.ancestors(*[cl.rev(n) for n in bases]))
+        common = set(cl.ancestors([cl.rev(n) for n in bases]))
         return self._changegroupsubset(common, csets, heads, source)
 
     def getlocalbundle(self, source, outgoing):
diff -r 2ac08d8b21aa -r 82a0af4e593f mercurial/revlog.py
--- a/mercurial/revlog.py	Tue May 22 14:37:20 2012 -0500
+++ b/mercurial/revlog.py	Fri Jun 01 09:13:55 2012 -0700
@@ -381,8 +381,8 @@
                     visit.append(p)
         return reachable
 
-    def ancestors(self, *revs):
-        """Generate the ancestors of 'revs' in reverse topological order.
+    def ancestors(self, revs):
+        """Generate the ancestors of list of revs in reverse topological order.
 
         Yield a sequence of revision numbers starting with the parents
         of each revision in revs, i.e., each revision is *not* considered
@@ -441,7 +441,7 @@
         heads = [self.rev(n) for n in heads]
 
         # we want the ancestors, but inclusive
-        has = set(self.ancestors(*common))
+        has = set(self.ancestors(common))
         has.add(nullrev)
         has.update(common)
 
diff -r 2ac08d8b21aa -r 82a0af4e593f tests/test-revlog-ancestry.py
--- a/tests/test-revlog-ancestry.py	Tue May 22 14:37:20 2012 -0500
+++ b/tests/test-revlog-ancestry.py	Fri Jun 01 09:13:55 2012 -0700
@@ -47,15 +47,15 @@
 
     # Ancestors
     print 'Ancestors of 5'
-    for r in repo.changelog.ancestors(5):
+    for r in repo.changelog.ancestors([5]):
         print r,
 
     print '\nAncestors of 6 and 5'
-    for r in repo.changelog.ancestors(6, 5):
+    for r in repo.changelog.ancestors([6, 5]):
         print r,
 
     print '\nAncestors of 5 and 4'
-    for r in repo.changelog.ancestors(5, 4):
+    for r in repo.changelog.ancestors([5, 4]):
         print r,
 
     # Descendants


More information about the Mercurial-devel mailing list