[PATCH v2] revlog: ancestors(*revs) becomes ancestors(revs)
Bryan O'Sullivan
bos at serpentine.com
Fri Jun 1 14:22:30 CDT 2012
# HG changeset patch
# User Bryan O'Sullivan <bryano at fb.com>
# Date 1338578441 25200
# Node ID 13da6358c87ef05c89189f7cf584fb0a9b66edf2
# Parent 3e3661a09635758712e3005199b6f8c6dcffffa7
revlog: ancestors(*revs) becomes ancestors(revs)
Accepting a variable number of arguments as the old API did is
deeply ugly, particularly as it means the API can't be extended
with new arguments. Partly as a result, we have at least three
different implementations of the same ancestors algorithm (!?).
Most callers were forced to call ancestors(*somelist), adding to
both inefficiency and ugliness.
diff --git a/contrib/perf.py b/contrib/perf.py
--- a/contrib/perf.py
+++ b/contrib/perf.py
@@ -74,7 +74,7 @@ def perftags(ui, repo):
def perfancestors(ui, repo):
heads = repo.changelog.headrevs()
def d():
- for a in repo.changelog.ancestors(*heads):
+ for a in repo.changelog.ancestors(heads):
pass
timer(d)
diff --git a/hgext/convert/hg.py b/hgext/convert/hg.py
--- a/hgext/convert/hg.py
+++ b/hgext/convert/hg.py
@@ -259,7 +259,7 @@ class mercurial_source(converter_source)
% startnode)
startrev = self.repo.changelog.rev(startnode)
children = {startnode: 1}
- for rev in self.repo.changelog.descendants(startrev):
+ for rev in self.repo.changelog.descendants([startrev]):
children[self.repo.changelog.node(rev)] = 1
self.keep = children.__contains__
else:
diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -2963,7 +2963,7 @@ def strip(ui, repo, *revs, **opts):
if not revs:
raise util.Abort(_('empty revision set'))
- descendants = set(cl.descendants(*revs))
+ descendants = set(cl.descendants(revs))
strippedrevs = revs.union(descendants)
roots = revs.difference(descendants)
diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -224,7 +224,7 @@ def rebase(ui, repo, **opts):
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 @@ def rebase(ui, repo, **opts):
# 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
@@ -321,7 +321,7 @@ def rebase(ui, repo, **opts):
# Remove no more useful revisions
rebased = [rev for rev in state if state[rev] != nullmerge]
if rebased:
- if set(repo.changelog.descendants(min(rebased))) - set(state):
+ if set(repo.changelog.descendants([min(rebased)])) - set(state):
ui.warn(_("warning: new changesets detected "
"on source branch, not stripping\n"))
else:
@@ -575,7 +575,7 @@ def abort(repo, originalwd, target, stat
descendants = set()
if dstates:
- descendants = set(repo.changelog.descendants(*dstates))
+ descendants = set(repo.changelog.descendants(dstates))
if descendants - set(dstates):
repo.ui.warn(_("warning: new changesets detected on target branch, "
"can't abort\n"))
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -5387,12 +5387,12 @@ def summary(ui, repo, **opts):
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 --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -223,11 +223,11 @@ class changectx(object):
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):
- for d in self._repo.changelog.descendants(self._rev):
+ for d in self._repo.changelog.descendants([self._rev]):
yield changectx(self._repo, d)
def _fileinfo(self, path):
@@ -1019,7 +1019,7 @@ class workingctx(changectx):
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 --git a/mercurial/discovery.py b/mercurial/discovery.py
--- a/mercurial/discovery.py
+++ b/mercurial/discovery.py
@@ -140,7 +140,7 @@ def findcommonoutgoing(repo, other, only
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 --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1791,7 +1791,7 @@ class localrepository(repo.repository):
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 --git a/mercurial/phases.py b/mercurial/phases.py
--- a/mercurial/phases.py
+++ b/mercurial/phases.py
@@ -189,7 +189,7 @@ class phasecache(object):
if roots:
for rev in roots:
revs[rev] = phase
- for rev in repo.changelog.descendants(*roots):
+ for rev in repo.changelog.descendants(roots):
revs[rev] = phase
self._phaserevs = revs
return self._phaserevs
diff --git a/mercurial/repair.py b/mercurial/repair.py
--- a/mercurial/repair.py
+++ b/mercurial/repair.py
@@ -74,7 +74,7 @@ def strip(ui, repo, nodelist, backup="al
# base = revision in the set that has no ancestor in the set)
tostrip = set(striplist)
for rev in striplist:
- for desc in cl.descendants(rev):
+ for desc in cl.descendants([rev]):
tostrip.add(desc)
files = _collectfiles(repo, striprev)
@@ -91,7 +91,7 @@ def strip(ui, repo, nodelist, backup="al
# compute base nodes
if saverevs:
- descendants = set(cl.descendants(*saverevs))
+ descendants = set(cl.descendants([saverevs]))
saverevs.difference_update(descendants)
savebases = [cl.node(r) for r in saverevs]
stripbases = [cl.node(r) for r in tostrip]
diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -381,7 +381,7 @@ class revlog(object):
visit.append(p)
return reachable
- def ancestors(self, *revs):
+ def ancestors(self, revs):
"""Generate the ancestors of 'revs' in reverse topological order.
Yield a sequence of revision numbers starting with the parents
@@ -398,7 +398,7 @@ class revlog(object):
seen.add(parent)
yield parent
- def descendants(self, *revs):
+ def descendants(self, revs):
"""Generate the descendants of 'revs' in revision order.
Yield a sequence of revision numbers starting with a child of
@@ -441,7 +441,7 @@ class revlog(object):
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)
@@ -700,7 +700,7 @@ class revlog(object):
def descendant(self, start, end):
if start == nullrev:
return True
- for i in self.descendants(start):
+ for i in self.descendants([start]):
if i == end:
return True
elif i > end:
diff --git a/tests/test-revlog-ancestry.py b/tests/test-revlog-ancestry.py
--- a/tests/test-revlog-ancestry.py
+++ b/tests/test-revlog-ancestry.py
@@ -47,15 +47,15 @@ if __name__ == '__main__':
# 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