[PATCH 3 of 5] templatekw: introduce showlatesttags() to handle {latesttag} keywords

Yuya Nishihara yuya at tcha.org
Mon Oct 5 08:16:26 CDT 2015


On Sun, 04 Oct 2015 17:47:36 -0400, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison at yahoo.com>
> # Date 1440472020 14400
> #      Mon Aug 24 23:07:00 2015 -0400
> # Node ID 18044dbb9f7ea8f3d015fed7c49f3ad24d8027ac
> # Parent  1df0499bb7e527cab3a15114a549e40842abee37
> 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.
> 
> diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
> --- a/mercurial/templatekw.py
> +++ b/mercurial/templatekw.py
> @@ -350,6 +350,35 @@
>  
>      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)
> +
> +    def changes(**args):
> +        offset = 0
> +        revs = [ctx.rev()]
> +        tag = args['latesttag']
> +
> +        # The only() revset doesn't currently support wdir()
> +        if ctx.rev() is None:
> +            offset = 1
> +            revs = [p.rev() for p in ctx.parents()]
> +
> +        return len(repo.revs('only(%ld, %s)', revs, tag)) + offset
> +
> +    makemap = lambda v: {
> +        'changes': changes,

My two cents. This "changes" function can be factored out to
"'changes': _showchangessincelatesttag". Only difference is how the latesttag
is obtained.

I've queued the first two patches, thanks.


More information about the Mercurial-devel mailing list