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

Matt Harbison mharbison72 at gmail.com
Fri Jun 26 23:01:24 CDT 2015


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1435374665 14400
#      Fri Jun 26 23:11:05 2015 -0400
# Node ID 7391298f5b4d78e7d6e56eb2e9ebaf61dbd98be9
# Parent  c673a9cb5668ed84c13d69505cd6523a5469e385
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.

Using p1() instead of wdir() is partially for practicality- wctx.rev() returns
None, which crashes %d, and repo[ff..ff] doesn't currently work.  There's also
a correctness factor- if you update to a tag and change nothing, there are 0
changes since the latest tag.  A change without a commit (dirty) is 1 change.

Current precedent for wdir() mascarading as p1() is the fact that wctx.tags()
reports whatever tags the parents have.  Maybe that's not a good idea (at least
for non virtual tags like 'tip'), because a side effect of that is
'-r wdir() -T {latesttagdistance}' after updating to a tag is 0, whether or not
wdir() is dirty.  Committing once then jumps the value to 2, and it continues
sequentially from there.

diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -334,6 +334,18 @@
     """: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
+
+    if ctx.rev() is None:
+        if ctx.dirty(missing=True):
+            offset = 1
+        ctx = ctx.p1()
+
+    return len(repo.revs('only(%d, %s)', ctx.rev(), latesttag)) + offset
+
 def showmanifest(**args):
     repo, ctx, templ = args['repo'], args['ctx'], args['templ']
     mnode = ctx.manifestnode()
@@ -427,6 +439,7 @@
     '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
@@ -437,12 +437,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"
+  0 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"
+  3 changes since t4:t6
   $ hg tag t2
   $ hg tag -f t6
 


More information about the Mercurial-devel mailing list