Mercurial > hg-stable
changeset 25724:4474a750413f
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
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Fri, 26 Jun 2015 23:11:05 -0400 |
parents | 2a8d8b4097c8 |
children | f5f43178bdde |
files | mercurial/templatekw.py tests/test-tag.t |
diffstat | 2 files changed, 29 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/templatekw.py Sat Jul 04 23:11:32 2015 -0400 +++ b/mercurial/templatekw.py Fri Jun 26 23:11:05 2015 -0400 @@ -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 + def showmanifest(**args): repo, ctx, templ = args['repo'], args['ctx'], args['templ'] mnode = ctx.manifestnode() @@ -427,6 +440,7 @@ 'branch': showbranch, 'branches': showbranches, 'bookmarks': showbookmarks, + 'changessincelatesttag': showchangessincelatesttag, 'children': showchildren, # currentbookmark is deprecated 'currentbookmark': showcurrentbookmark,
--- a/tests/test-tag.t Sat Jul 04 23:11:32 2015 -0400 +++ b/tests/test-tag.t Fri Jun 26 23:11:05 2015 -0400 @@ -443,12 +443,25 @@ $ hg ci -A -m3 adding f3 $ hg tag -f t4 t5 t6 + + $ hg up -q '.^' + $ hg log -r 'wdir()' -T "{changessincelatesttag} changes since {latesttag}\n" + 1 changes since t4:t5:t6 + $ hg log -r '.' -T "{changessincelatesttag} changes since {latesttag}\n" + 0 changes since t4:t5:t6 + $ echo c5 > f3 + $ hg log -r 'wdir()' -T "{changessincelatesttag} changes since {latesttag}\n" + 1 changes since t4:t5:t6 + $ hg up -qC + $ hg tag --remove t5 $ echo c4 > f4 - $ hg log -r '.' -T "{latesttag}\n" - t4:t6 + $ hg log -r '.' -T "{changessincelatesttag} changes since {latesttag}\n" + 2 changes since t4:t6 $ hg ci -A -m4 adding f4 + $ hg log -r 'wdir()' -T "{changessincelatesttag} changes since {latesttag}\n" + 4 changes since t4:t6 $ hg tag t2 $ hg tag -f t6