Mercurial > public > mercurial-scm > hg-stable
diff mercurial/dagop.py @ 39212:1c3184d7e882
dagop: extract headsetofconnecteds() from dagutil
The functionality for resolving the set of DAG heads from a
subset simply requires a function to resolve parent revisions.
Let's establish a function in the dagop module to do this, which
seems to be where generic DAG functionality goes these days.
Differential Revision: https://phab.mercurial-scm.org/D4327
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Fri, 17 Aug 2018 19:45:13 +0000 |
parents | e7aa113b14f7 |
children | 0a934ee94f09 |
line wrap: on
line diff
--- a/mercurial/dagop.py Fri Aug 17 19:35:24 2018 +0000 +++ b/mercurial/dagop.py Fri Aug 17 19:45:13 2018 +0000 @@ -715,3 +715,26 @@ for g in groups: for r in g[0]: yield r + +def headrevs(revs, parentsfn): + """Resolve the set of heads from a set of revisions. + + Receives an iterable of revision numbers and a callbable that receives a + 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. + + ``nullrev`` is never included in the returned set, even if it is provided in + the input set. + """ + headrevs = set(revs) + + for rev in revs: + for prev in parentsfn(rev): + headrevs.discard(prev) + + headrevs.discard(node.nullrev) + + return headrevs