[PATCH 2 of 5] templatekw: allow getlatesttags() to match a specific tag pattern
Matt Harbison
mharbison72 at gmail.com
Sun Oct 4 16:47:35 CDT 2015
# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1440386575 14400
# Sun Aug 23 23:22:55 2015 -0400
# Node ID 1df0499bb7e527cab3a15114a549e40842abee37
# Parent 7f2137d49acc0b68499d046bde67e3d53db8c676
templatekw: allow getlatesttags() to match a specific tag pattern
This will allow the latest class of tag to be found, such as a release candidate
or final build, instead of just the absolute latest. It will be exposed in a
future patch.
It's unfortunate that the original 'latesttags' cache can't be used to determine
the proper values, but it isn't fully populated for the entire repo. For
example, the {latesttagdistance} keyword on the Mecurial repo builds the cache
up back to the revision for 1.4. If the pattern was 're:^0\.\d$', that wouldn't
be in the cache. Maybe this can be optimized some other way, but for now, this
is the simpliest implementation.
diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -122,14 +122,21 @@
revcache['files'] = repo.status(ctx.p1(), ctx)[:3]
return revcache['files']
-def getlatesttags(repo, ctx, cache):
+def getlatesttags(repo, ctx, cache, pattern=None):
'''return date, distance and name for the latest tag of rev'''
- if 'latesttags' not in cache:
+ cachename = 'latesttags'
+ if pattern is not None:
+ cachename += '-' + pattern
+ match = util.stringmatcher(pattern)[2]
+ else:
+ match = util.always
+
+ if cachename not in cache:
# Cache mapping from rev to a tuple with tag date, tag
# distance and tag name
- cache['latesttags'] = {-1: (0, 0, ['null'])}
- latesttags = cache['latesttags']
+ cache[cachename] = {-1: (0, 0, ['null'])}
+ latesttags = cache[cachename]
rev = ctx.rev()
todo = [rev]
@@ -139,7 +146,8 @@
continue
ctx = repo[rev]
tags = [t for t in ctx.tags()
- if (repo.tagtype(t) and repo.tagtype(t) != 'local')]
+ if (repo.tagtype(t) and repo.tagtype(t) != 'local'
+ and match(t))]
if tags:
latesttags[rev] = ctx.date()[0], 0, [t for t in sorted(tags)]
continue
More information about the Mercurial-devel
mailing list