From patchwork Mon Feb 7 17:26:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: D12140: rank: add context and template keyword From: phabricator X-Patchwork-Id: 50477 Message-Id: To: Phabricator Cc: mercurial-devel@mercurial-scm.org Date: Mon, 7 Feb 2022 17:26:23 +0000 pacien created this revision. Herald added a reviewer: hg-reviewers. Herald added a subscriber: mercurial-patches. REVISION SUMMARY This makes the stored rank property accessible, to be expanded and printed. REPOSITORY rHG Mercurial BRANCH default REVISION DETAIL https://phab.mercurial-scm.org/D12140 AFFECTED FILES mercurial/context.py mercurial/templatekw.py CHANGE DETAILS To: pacien, #hg-reviewers Cc: mercurial-patches, mercurial-devel diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py --- a/mercurial/templatekw.py +++ b/mercurial/templatekw.py @@ -304,6 +304,20 @@ ) +@templatekeyword(b'_fast_rank', requires={b'ctx'}) +def fast_rank(context, mapping): + """the rank of a changeset if cached + + The rank of a revision is the size of sub-graph it defines as a head. In + other words, the rank of X is the size of `ancestors(X)` (X included). + """ + ctx = context.resource(mapping, b'ctx') + rank = ctx.fast_rank() + if rank is None: + return None + return b"%d" % rank + + def _getfilestatus(context, mapping, listall=False): ctx = context.resource(mapping, b'ctx') revcache = context.resource(mapping, b'revcache') diff --git a/mercurial/context.py b/mercurial/context.py --- a/mercurial/context.py +++ b/mercurial/context.py @@ -685,6 +685,14 @@ """Return a list of byte bookmark names.""" return self._repo.nodebookmarks(self._node) + def fast_rank(self): + repo = self._repo + if self._maybe_filtered: + cl = repo.changelog + else: + cl = repo.unfiltered().changelog + return cl.fast_rank(self._rev) + def phase(self): return self._repo._phasecache.phase(self._repo, self._rev)