Patchwork [1,of,3] templater: evaluate each item of revset() as integer revision

login
register
mail settings
Submitter Yuya Nishihara
Date Feb. 20, 2016, 10:09 a.m.
Message ID <6b9ac7eb3428685c4167.1455962964@mimosa>
Download mbox | patch
Permalink /patch/13270/
State Accepted
Headers show

Comments

Yuya Nishihara - Feb. 20, 2016, 10:09 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1455268133 -32400
#      Fri Feb 12 18:08:53 2016 +0900
# Node ID 6b9ac7eb3428685c41672c8a859e58a896490722
# Parent  1f036626b633a057498a619afb9907728a085061
templater: evaluate each item of revset() as integer revision

Because templater.revset() returns a list of strings, repo["-1"] was mapped to
the tipmost revision. Ideally, we should make revset() return a list of integer
revisions, but it turned out not simple. If revset() is a list of integers,
"{ifcontains(rev, revset(), ...)}" would fail because "ifcontains" casts "rev"
to a string.

So this patch just converts a string back to an integer revision.

Patch

diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -492,7 +492,7 @@  def showrevslist(name, revs, **args):
     repo = args['ctx'].repo()
     f = _showlist(name, revs, **args)
     return _hybrid(f, revs,
-                   lambda x: {name: x, 'ctx': repo[x], 'revcache': {}})
+                   lambda x: {name: x, 'ctx': repo[int(x)], 'revcache': {}})
 
 def showsubrepos(**args):
     """:subrepos: List of strings. Updated subrepositories in the changeset."""
diff --git a/tests/test-command-template.t b/tests/test-command-template.t
--- a/tests/test-command-template.t
+++ b/tests/test-command-template.t
@@ -3310,6 +3310,13 @@  Test revset function
   0 a
   p 
 
+a revset item must be evaluated as an integer revision, not an offset from tip
+
+  $ hg log -l 1 -T '{revset("null") % "{rev}:{node|short}"}\n'
+  -1:000000000000
+  $ hg log -l 1 -T '{revset("%s", "null") % "{rev}:{node|short}"}\n'
+  -1:000000000000
+
 Test active bookmark templating
 
   $ hg book foo