Mercurial > public > mercurial-scm > hg-stable
diff mercurial/revlogutils/revlogv0.py @ 51999:22da1dc97281
head-revs: teach the pure indexes about the `headrevs` method
Having this computation done at the index level unify the API and remove revlog
side complexity. It might also be a front runner of handing more responsability
to the index.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Wed, 25 Sep 2024 17:18:40 +0200 |
parents | f4733654f144 |
children | 609700e5d8df |
line wrap: on
line diff
--- a/mercurial/revlogutils/revlogv0.py Thu Sep 26 00:50:21 2024 +0200 +++ b/mercurial/revlogutils/revlogv0.py Wed Sep 25 17:18:40 2024 +0200 @@ -111,6 +111,22 @@ ) return INDEX_ENTRY_V0.pack(*e2) + def headrevs(self, excluded_revs=None): + count = len(self) + if not count: + return [node.nullrev] + # we won't iter over filtered rev so nobody is a head at start + ishead = [0] * (count + 1) + revs = range(count) + if excluded_revs is not None: + revs = (r for r in revs if r not in excluded_revs) + + for r in revs: + ishead[r] = 1 # I may be an head + e = self[r] + ishead[e[5]] = ishead[e[6]] = 0 # my parent are not + return [r for r, val in enumerate(ishead) if val] + def parse_index_v0(data, inline): s = INDEX_ENTRY_V0.size