Mercurial > hg-stable
changeset 41733:37b33c34bf4f
templatekw: add a {negrev} keyword
Revision numbers are getting much maligned for two reasons: they are
too long in large repos and users get confused by their local-only
nature. It just occurred to me that negative revision numbers avoid
both of those problems. Since negative revision numbers change
whenever the repo changes, it's much more obvious that they are a
local-only convenience. Additionally, for the recent commits that we
usually care about the most, negative revision numbers are always near
zero.
This commit adds a negrev templatekw to more easily expose negative
revision numbers. It's not easy to reliably produce this output with
existing keywords due to hidden commits while at the same time
ensuring good performance.
author | Jordi Gutiérrez Hermoso <jordigh@octave.org> |
---|---|
date | Fri, 15 Feb 2019 14:43:31 -0500 |
parents | eb8a8af4cbd0 |
children | ebbc4e70ebd1 |
files | mercurial/templatekw.py tests/test-obsmarker-template.t |
diffstat | 2 files changed, 32 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/templatekw.py Sun Feb 17 22:39:12 2019 -0500 +++ b/mercurial/templatekw.py Fri Feb 15 14:43:31 2019 -0500 @@ -554,6 +554,14 @@ 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
--- a/tests/test-obsmarker-template.t Sun Feb 17 22:39:12 2019 -0500 +++ b/tests/test-obsmarker-template.t Fri Feb 15 14:43:31 2019 -0500 @@ -2429,6 +2429,23 @@ 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 @@ |/ 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 +