diff --git a/mercurial/dagop.py b/mercurial/dagop.py --- a/mercurial/dagop.py +++ b/mercurial/dagop.py @@ -723,13 +723,18 @@ revision number and returns an iterable of parent revision numbers, possibly including nullrev. - Returns a set of revision numbers that are DAG heads within the passed subset. + Returns a set of revision numbers that are DAG heads within the passed + subset. + + ``nullrev`` is never included in the returned set, even if it is provided in + the input set. """ - headrevs = set() + headrevs = set(revs) for rev in revs: for prev in parentsfn(rev): - if prev != node.nullrev: - headrevs.discard(prev) + headrevs.discard(prev) + + headrevs.discard(node.nullrev) return headrevs diff --git a/mercurial/dagutil.py b/mercurial/dagutil.py --- a/mercurial/dagutil.py +++ b/mercurial/dagutil.py @@ -20,21 +20,6 @@ def __init__(self, revlog): self._revlog = revlog - def parents(self, ix): - rlog = self._revlog - idx = rlog.index - revdata = idx[ix] - prev = revdata[5] - if prev != nullrev: - prev2 = revdata[6] - if prev2 == nullrev: - return [prev] - return [prev, prev2] - prev2 = revdata[6] - if prev2 != nullrev: - return [prev2] - return [] - def linearize(self, ixs): '''linearize and topologically sort a list of revisions @@ -45,7 +30,7 @@ parent, then adding the rev itself to the output list. ''' sorted = [] - visit = list(dagop.headrevs(ixs, self.parents)) + visit = list(dagop.headrevs(ixs, self._revlog.parentrevs)) visit.sort(reverse=True) finished = set() @@ -58,7 +43,7 @@ finished.add(cur) else: visit.append(-cur - 1) - visit += [p for p in self.parents(cur) - if p in ixs and p not in finished] + visit += [p for p in self._revlog.parentrevs(cur) + if p != nullrev and p in ixs and p not in finished] assert len(sorted) == len(ixs) return sorted