# HG changeset patch # User Pierre-Yves David # Date 1643366141 -3600 # Node ID d5121df04808691b19e994e8b2ba078abf14fef7 # Parent 2e949ede7350d0d9ec654d0c709118c979eb5519 rank: add context and template keyword This makes the stored rank property accessible, to be expanded and printed. Differential Revision: https://phab.mercurial-scm.org/D12140 diff -r 2e949ede7350 -r d5121df04808 mercurial/context.py --- a/mercurial/context.py Fri Jan 28 11:33:01 2022 +0100 +++ b/mercurial/context.py Fri Jan 28 11:35:41 2022 +0100 @@ -684,6 +684,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) diff -r 2e949ede7350 -r d5121df04808 mercurial/templatekw.py --- a/mercurial/templatekw.py Fri Jan 28 11:33:01 2022 +0100 +++ b/mercurial/templatekw.py Fri Jan 28 11:35:41 2022 +0100 @@ -304,6 +304,21 @@ ) +@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 the sub-graph it defines as a head. + Equivalently, the rank of a revision `r` is the size of the set + `ancestors(r)`, `r` 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')