Mercurial > public > mercurial-scm > hg-stable
diff mercurial/dagop.py @ 51394:a0d88b021a98
unbundle: faster computation of changed heads
To compute the set of changed heads it's sufficient to look at the recent commits,
instead of looking at all heads currently in existence.
author | Arseniy Alekseyev <aalekseyev@janestreet.com> |
---|---|
date | Thu, 21 Dec 2023 17:38:04 +0000 |
parents | d44e3c45f0e4 |
children | 278af66e6595 |
line wrap: on
line diff
--- a/mercurial/dagop.py Wed Feb 21 11:53:30 2024 +0100 +++ b/mercurial/dagop.py Thu Dec 21 17:38:04 2023 +0000 @@ -1035,6 +1035,37 @@ return headrevs +def headrevsdiff(parentsfn, start, stop): + """Compute how the set of heads changed between + revisions `start-1` and `stop-1`. + """ + parents = set() + + heads_added = set() + heads_removed = set() + + for rev in range(stop - 1, start - 1, -1): + if rev in parents: + parents.remove(rev) + else: + heads_added.add(rev) + for p in parentsfn(rev): + parents.add(p) + + # now `parents` is the collection of candidate removed heads + rev = start - 1 + while parents: + if rev in parents: + heads_removed.add(rev) + parents.remove(rev) + + for p in parentsfn(rev): + parents.discard(p) + rev = rev - 1 + + return (heads_removed, heads_added) + + def headrevssubset(revsfn, parentrevsfn, startrev=None, stoprevs=None): """Returns the set of all revs that have no children with control.