Mercurial > public > mercurial-scm > hg
diff mercurial/revlog.py @ 40000:8af835af0a85
dagop: extract DAG local heads functionality from revlog
As part of implementing an alternate storage backend, I found myself
having to reimplement this function.
The DAG traversal logic is generic and can be factored out into a
standalone function.
We could probably combine this with headrevs(). But I'll leave that
for another time.
Differential Revision: https://phab.mercurial-scm.org/D4795
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Fri, 28 Sep 2018 10:20:37 -0700 |
parents | 0b24fcd88066 |
children | fa3dc85a747e |
line wrap: on
line diff
--- a/mercurial/revlog.py Fri Sep 28 10:03:32 2018 -0700 +++ b/mercurial/revlog.py Fri Sep 28 10:20:37 2018 -0700 @@ -1069,25 +1069,16 @@ return [self.node(r) for r in self.headrevs()] if start is None: - start = nullid - if stop is None: - stop = [] - stoprevs = set([self.rev(n) for n in stop]) - startrev = self.rev(start) - reachable = {startrev} - heads = {startrev} - - parentrevs = self.parentrevs - for r in self.revs(start=startrev + 1): - for p in parentrevs(r): - if p in reachable: - if r not in stoprevs: - reachable.add(r) - heads.add(r) - if p in heads and p not in stoprevs: - heads.remove(p) - - return [self.node(r) for r in heads] + start = nullrev + else: + start = self.rev(start) + + stoprevs = set(self.rev(n) for n in stop or []) + + revs = dagop.headrevssubset(self.revs, self.parentrevs, startrev=start, + stoprevs=stoprevs) + + return [self.node(rev) for rev in revs] def children(self, node): """find the children of a given node"""