Patchwork [4,of,6,V2] templatekw: introduce showlatesttags() to handle {latesttag} keywords

login
register
mail settings
Submitter Matt Harbison
Date Oct. 6, 2015, 1:40 a.m.
Message ID <272d3031cd481f599d0f.1444095656@Envy>
Download mbox | patch
Permalink /patch/10825/
State Accepted
Commit 93c80e7ed8c82c733a121a990bb70291bba797e6
Headers show

Comments

Matt Harbison - Oct. 6, 2015, 1:40 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1440472020 14400
#      Mon Aug 24 23:07:00 2015 -0400
# Node ID 272d3031cd481f599d0fd0a22f3a9c348623c639
# Parent  c974da0b9203471fcb0a640a4837b247056c8b23
templatekw: introduce showlatesttags() to handle {latesttag} keywords

The keywords {changes}, {distance} and {tag} will be available on a future
template method that will allow pattern matching against tag names.  For
consistency, these should be available on the existing {latesttag} keyword as
well.

I debated whether or not to add {tag} instead of just continuing with the
existing {latesttag}.  But it seems clearer not to have the same name for two
distinct things (a list in the LHS of %, and an individual tag value on the
right).

The value of latesttags[0] is the date of commit for the cset to which the tag
is applied (i.e. not the date the tag was applied), and therefore isn't made
visible because it doesn't seem interesting.  It appears that this is merely an
internal implementation detail for sorting csets in a stable manner when there
are different branches.

Patch

diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -350,6 +350,26 @@ 
 
     return showlist('latesttag', latesttags, separator=':', **args)
 
+def showlatesttags(pattern, **args):
+    """helper method for the latesttag keyword and function"""
+    repo, ctx = args['repo'], args['ctx']
+    cache = args['cache']
+    latesttags = getlatesttags(repo, ctx, cache, pattern)
+
+    # latesttag[0] is an implementation detail for sorting csets on different
+    # branches in a stable manner- it is the date the tagged cset was created,
+    # not the date the tag was created.  Therefore it isn't made visible here.
+    makemap = lambda v: {
+        'changes': _showchangessincetag,
+        'distance': latesttags[1],
+        'latesttag': v,   # BC with {latesttag % '{latesttag}'}
+        'tag': v
+    }
+
+    tags = latesttags[2]
+    f = _showlist('latesttag', tags, separator=':', **args)
+    return _hybrid(f, tags, makemap, lambda x: x['latesttag'])
+
 def showlatesttagdistance(repo, ctx, templ, cache, **args):
     """:latesttagdistance: Integer. Longest path to the latest tag."""
     return getlatesttags(repo, ctx, cache)[1]