diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py --- a/mercurial/templatekw.py +++ b/mercurial/templatekw.py @@ -334,6 +334,19 @@ def showlatesttagdistance(repo, ctx, tem """: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 @@ keywords = { 'branch': showbranch, 'branches': showbranches, 'bookmarks': showbookmarks, + 'changessincelatesttag': showchangessincelatesttag, 'children': showchildren, # currentbookmark is deprecated 'currentbookmark': showcurrentbookmark, diff --git a/tests/test-tag.t b/tests/test-tag.t --- a/tests/test-tag.t +++ b/tests/test-tag.t @@ -443,12 +443,25 @@ check that we can merge tags that differ $ 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