diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py --- a/mercurial/templatekw.py +++ b/mercurial/templatekw.py @@ -554,6 +554,14 @@ def shownamespaces(context, mapping): return _hybrid(f, namespaces, makemap, pycompat.identity) +@templatekeyword('negrev', requires={'repo', 'ctx'}) +def shownegrev(context, mapping): + """Integer. The repository-local changeset negative revision number, + which counts in the opposite direction.""" + ctx = context.resource(mapping, 'ctx') + repo = context.resource(mapping, 'repo') + return scmutil.intrev(ctx) - len(repo) + @templatekeyword('node', requires={'ctx'}) def shownode(context, mapping): """String. The changeset identification hash, as a 40 hexadecimal diff --git a/tests/test-obsmarker-template.t b/tests/test-obsmarker-template.t --- a/tests/test-obsmarker-template.t +++ b/tests/test-obsmarker-template.t @@ -2429,6 +2429,23 @@ Check other fatelog implementations date: Thu Jan 01 00:00:00 1970 +0000 summary: ROOT +Check that {negrev} shows usable negative revisions despite hidden commits + + $ hg log -G -T "{negrev}\n" + @ -3 + | + o -4 + + + $ hg log -G -T "{negrev}\n" --hidden + x -1 + | + | x -2 + |/ + | @ -3 + |/ + o -4 + Test templates with splitted and pruned commit ============================================== @@ -2639,3 +2656,10 @@ metadata should be converted back to loc |/ Obsfate: rewritten using amend as 2:718c0d00cee1 by test (at 1970-01-01 00:00 +0000); o ea207398892e + $ hg log -G -T "{negrev}\n" + @ -1 + | + o -2 + | + o -5 +