Patchwork [1,of,3,RFC,V2] archive: store number of changes since latest tag as well

login
register
mail settings
Submitter Siddharth Agarwal
Date Dec. 13, 2014, 1:02 a.m.
Message ID <503a63fab1bbd3623463.1418432548@devbig136.prn2.facebook.com>
Download mbox | patch
Permalink /patch/7072/
State Accepted
Commit 242d11819c6c30c2f23a7109baf6f76fa007d1a0
Delegated to: Matt Mackall
Headers show

Comments

Siddharth Agarwal - Dec. 13, 2014, 1:02 a.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1418426833 28800
#      Fri Dec 12 15:27:13 2014 -0800
# Node ID 503a63fab1bbd3623463fdbb4d3e030503f3f706
# Parent  416c133145ee78c8e83865b7370e185eed69c1be
archive: store number of changes since latest tag as well

This is different from latesttagdistance in that while latesttagdistance is
defined to be the length of the longest path to the latest tag,
changessincelatesttag is the number of changes contained in @ that aren't
contained in the latest tag. So, if 't' is the latest tag in the repository
below:

      t
      |
      v
 --o--o----o
    \       \
     ..o..o..@

then latesttagdistance is 2, but changessincelatesttag is 4.

Note that changessincelatesttag is always greater than or equal to the
latesttagdistance -- that's because changessincelatesttag counts all the
changes in the longest path since the latest tag, and possibly others. This is
an important fact that we'll take advantage of in upcoming patches.

Patch

diff --git a/mercurial/archival.py b/mercurial/archival.py
--- a/mercurial/archival.py
+++ b/mercurial/archival.py
@@ -276,8 +276,11 @@ 
                         'style': '', 'patch': None, 'git': None}
                 cmdutil.show_changeset(repo.ui, repo, opts).show(ctx)
                 ltags, dist = repo.ui.popbuffer().split('\n')
-                tags = ''.join('latesttag: %s\n' % t for t in ltags.split(':'))
+                ltags = ltags.split(':')
+                changessince = len(repo.revs('only(.,%s)', ltags[0]))
+                tags = ''.join('latesttag: %s\n' % t for t in ltags)
                 tags += 'latesttagdistance: %s\n' % dist
+                tags += 'changessincelatesttag: %s\n' % changessince
 
             return base + tags
 
diff --git a/tests/test-archive.t b/tests/test-archive.t
--- a/tests/test-archive.t
+++ b/tests/test-archive.t
@@ -250,6 +250,7 @@ 
   branch: default
   latesttag: null
   latesttagdistance: 4
+  changessincelatesttag: 4
   $ hg tag -r 2 mytag
   $ hg tag -r 2 anothertag
   $ hg archive -r 2 ../test-lasttag
@@ -322,10 +323,10 @@ 
   Archive:  ../old.zip
   \s*Length.* (re)
   *-----* (glob)
-  *147*80*00:00*old/.hg_archival.txt (glob)
+  *172*80*00:00*old/.hg_archival.txt (glob)
   *0*80*00:00*old/old (glob)
   *-----* (glob)
-  \s*147\s+2 files (re)
+  \s*172\s+2 files (re)
 
 show an error when a provided pattern matches no files