Patchwork [2,of,5] rank: add context and template keyword

login
register
mail settings
Submitter via Mercurial-devel
Date Jan. 31, 2022, 2:03 p.m.
Message ID <a5e1331be0ffa00772e4.1643637825@localhost>
Download mbox | patch
Permalink /patch/50454/
State New
Headers show

Comments

via Mercurial-devel - Jan. 31, 2022, 2:03 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@octobus.net>
# Date 1643366141 -3600
#      Fri Jan 28 11:35:41 2022 +0100
# Node ID a5e1331be0ffa00772e4de07c982dfd36cd4f8c7
# Parent  ff043e0e1aacc81f8d5238f89bed5a6b355ba9cf
# EXP-Topic cl2-rank
rank: add context and template keyword

This makes the stored rank property accessible, to be expanded and printed.

Patch

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)
 
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')