[PATCH 1 of 3 V2 fixes-subrepo-test] templatekw: use a list of tags in getlatesttags() instead of joining them

Matt Harbison mharbison72 at gmail.com
Tue Jun 30 23:30:25 CDT 2015


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1435375390 14400
#      Fri Jun 26 23:23:10 2015 -0400
# Node ID 11c68afbb60f3b41689a2fe24d9f72bfd399c350
# Parent  c76e8d14383a44a740d986d87db6f58276fb57e8
templatekw: use a list of tags in getlatesttags() instead of joining them

This will be used in the next patch.

It also points out that the documentation for '{latesttag}' is not quite
accurate, since it says "most recent global tag" (singular).  I assume it is too
radical of a change to convert it to a list of strings.  At least ':' is
currently a reserved character in tag names.

diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -120,7 +120,7 @@
     if 'latesttags' not in cache:
         # Cache mapping from rev to a tuple with tag date, tag
         # distance and tag name
-        cache['latesttags'] = {-1: (0, 0, 'null')}
+        cache['latesttags'] = {-1: (0, 0, ['null'])}
     latesttags = cache['latesttags']
 
     rev = ctx.rev()
@@ -133,7 +133,7 @@
         tags = [t for t in ctx.tags()
                 if (repo.tagtype(t) and repo.tagtype(t) != 'local')]
         if tags:
-            latesttags[rev] = ctx.date()[0], 0, ':'.join(sorted(tags))
+            latesttags[rev] = ctx.date()[0], 0, [t for t in sorted(tags)]
             continue
         try:
             # The tuples are laid out so the right one can be found by
@@ -328,7 +328,7 @@
     """:latesttag: String. Most recent global tag in the ancestors of this
     changeset.
     """
-    return getlatesttags(repo, ctx, cache)[2]
+    return ':'.join(getlatesttags(repo, ctx, cache)[2])
 
 def showlatesttagdistance(repo, ctx, templ, cache, **args):
     """:latesttagdistance: Integer. Longest path to the latest tag."""
diff --git a/tests/test-tag.t b/tests/test-tag.t
--- a/tests/test-tag.t
+++ b/tests/test-tag.t
@@ -439,6 +439,8 @@
   $ hg tag -f t4 t5 t6
   $ hg tag --remove t5
   $ echo c4 > f4
+  $ hg log -r '.' -T "{latesttag}\n"
+  t4:t6
   $ hg ci -A -m4
   adding f4
   $ hg tag t2


More information about the Mercurial-devel mailing list