[PATCH 1 of 2 V3] templatekw: introduce the changessincelatesttag keyword

Yuya Nishihara yuya at tcha.org
Fri Jul 3 22:49:55 CDT 2015


On Wed, 01 Jul 2015 20:32:22 -0400, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison at yahoo.com>
> # Date 1435374665 14400
> #      Fri Jun 26 23:11:05 2015 -0400
> # Node ID 49d56afc63719c326f7131ad7861090de3ce9102
> # Parent  84518051bc3b851f736872df045d662de548b3c9
> templatekw: introduce the changessincelatesttag keyword
> 
> Archive is putting a value with the same name in the metadata file, to count all
> of the changes not covered by the latest tag, instead of just along the longest
> path.  It seems that this would be useful to have on the command line as well.
> It might be nice for the name to start with 'latesttag' so that it is grouped
> with the other tag keywords, but I can't think of a better name.
> 
> The initial version of this counted a clean wdir() and '.' as the same value,
> and a dirty wdir() as the same value after it is committed.  Yuya objected on
> the grounds of consistency [1].  Since revsets can be used to conditionally
> select a dirty wdir() or '.' when clean, I can build the version string I need
> and will defer to him on this.
> 
> [1] https://www.selenic.com/pipermail/mercurial-devel/2015-June/071588.html
> 
> diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
> --- a/mercurial/templatekw.py
> +++ b/mercurial/templatekw.py
> @@ -334,6 +334,19 @@
>      """:latesttagdistance: Integer. Longest path to the latest tag."""
>      return getlatesttags(repo, ctx, cache)[1]
>  
> +def showchangessincelatesttag(repo, ctx, templ, cache, **args):
> +    """:changessincelatesttag: Integer. All ancestors not in the latest tag."""
> +    latesttag = getlatesttags(repo, ctx, cache)[2][0]
> +    offset = 0
> +    revs = [ctx.rev()]
> +
> +    # 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, latesttag)) + offset

The function looks good to me, but I'm a little unsure if we want new keyword.

If 'only()' can handle 'wdir()', and if '{latesttag}' is singular, it could be
written as:

  {revset("only(%d, %s)", rev, latesttag)|count}


More information about the Mercurial-devel mailing list