Patchwork [1,of,1,STABLE,V2] tags: write tag overwriting history also into tag cache file (issue3911)

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Aug. 28, 2013, 1:23 p.m.
Message ID <fbaec047da325a5ec717.1377696222@feefifofum>
Download mbox | patch
Permalink /patch/2279/
State Accepted
Commit 335a558f81dc73afeab4d7be63617392b130117f
Headers show

Comments

Katsunori FUJIWARA - Aug. 28, 2013, 1:23 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1377695393 -32400
#      Wed Aug 28 22:09:53 2013 +0900
# Branch stable
# Node ID fbaec047da325a5ec7170043b5eb7055a917e660
# Parent  064f7d697852ad6de03b7b2cbf452b69f5de6bef
tags: write tag overwriting history also into tag cache file (issue3911)

Before this patch, tag overwriting history is not written into tag
cache file ".hg/cache/tags".

This may give higher priority to local tag than global one, even if
the former is overwritten by the latter, because tag overwriting
history is used to compare priorities of them (as "rank").

In such cases, "hg tags" invocations using tag cache file shows
incorrect tag information.

This patch writes tag overwriting history also into tag cache file.

This patch also switches tag cache file from ".hg/cache/tags" to
".hg/cache/tags2" for safe backward compatibility.
Matt Mackall - Sept. 3, 2013, 10:56 p.m.
On Wed, 2013-08-28 at 22:23 +0900, FUJIWARA Katsunori wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
> # Date 1377695393 -32400
> #      Wed Aug 28 22:09:53 2013 +0900
> # Branch stable
> # Node ID fbaec047da325a5ec7170043b5eb7055a917e660
> # Parent  064f7d697852ad6de03b7b2cbf452b69f5de6bef
> tags: write tag overwriting history also into tag cache file (issue3911)

Ok, I've decided that changing the name of the tags cache here isn't
necessary as there are no read-side changes needed. So I've taken this
patch and dropped everything but the line that writes out the history
and the related test changes. Queued, thanks for persevering.

Patch

diff --git a/mercurial/tags.py b/mercurial/tags.py
--- a/mercurial/tags.py
+++ b/mercurial/tags.py
@@ -30,9 +30,6 @@ 
     (heads, tagfnode, cachetags, shouldwrite) = _readtagcache(ui, repo)
     if cachetags is not None:
         assert not shouldwrite
-        # XXX is this really 100% correct?  are there oddball special
-        # cases where a global tag should outrank a local tag but won't,
-        # because cachetags does not contain rank info?
         _updatetags(cachetags, 'global', alltags, tagtypes)
         return
 
@@ -137,6 +134,7 @@ 
         ahist.extend([n for n in bhist if n not in ahist])
         alltags[name] = anode, ahist
 
+_cachefile = 'cache/tags2'
 
 # The tag cache only stores info about heads, not the tag contents
 # from each head.  I.e. it doesn't try to squeeze out the maximum
@@ -156,7 +154,7 @@ 
     set, caller is responsible for reading tag info from each head.'''
 
     try:
-        cachefile = repo.opener('cache/tags', 'r')
+        cachefile = repo.opener(_cachefile, 'r')
         # force reading the file for static-http
         cachelines = iter(cachefile)
     except IOError:
@@ -191,7 +189,7 @@ 
                     cachefnode[headnode] = fnode
         except Exception:
             # corruption of the tags cache, just recompute it
-            ui.warn(_('.hg/cache/tags is corrupt, rebuilding it\n'))
+            ui.warn(_('.hg/%s is corrupt, rebuilding it\n') % _cachefile)
             cacheheads = []
             cacherevs = []
             cachefnode = {}
@@ -258,7 +256,7 @@ 
 def _writetagcache(ui, repo, heads, tagfnode, cachetags):
 
     try:
-        cachefile = repo.opener('cache/tags', 'w', atomictemp=True)
+        cachefile = repo.opener(_cachefile, 'w', atomictemp=True)
     except (OSError, IOError):
         return
 
@@ -290,6 +288,8 @@ 
     # the cache.
     cachefile.write('\n')
     for (name, (node, hist)) in cachetags.iteritems():
+        for n in hist:
+            cachefile.write("%s %s\n" % (hex(n), name))
         cachefile.write("%s %s\n" % (hex(node), name))
 
     try:
diff --git a/tests/test-mq.t b/tests/test-mq.t
--- a/tests/test-mq.t
+++ b/tests/test-mq.t
@@ -308,12 +308,12 @@ 
 qpush with dump of tag cache
 Dump the tag cache to ensure that it has exactly one head after qpush.
 
-  $ rm -f .hg/cache/tags
+  $ rm -f .hg/cache/tags2
   $ hg tags > /dev/null
 
-.hg/cache/tags (pre qpush):
+.hg/cache/tags2 (pre qpush):
 
-  $ cat .hg/cache/tags
+  $ cat .hg/cache/tags2
   1 [\da-f]{40} (re)
   
   $ hg qpush
@@ -323,9 +323,9 @@ 
   2: draft
   $ hg tags > /dev/null
 
-.hg/cache/tags (post qpush):
+.hg/cache/tags2 (post qpush):
 
-  $ cat .hg/cache/tags
+  $ cat .hg/cache/tags2
   2 [\da-f]{40} (re)
   
   $ checkundo qpush
diff --git a/tests/test-tags.t b/tests/test-tags.t
--- a/tests/test-tags.t
+++ b/tests/test-tags.t
@@ -1,7 +1,7 @@ 
 Helper functions:
 
   $ cacheexists() {
-  >   [ -f .hg/cache/tags ] && echo "tag cache exists" || echo "no tag cache"
+  >   [ -f .hg/cache/tags2 ] && echo "tag cache exists" || echo "no tag cache"
   > }
 
   $ dumptags() {
@@ -36,9 +36,9 @@ 
 
 Try corrupting the cache
 
-  $ printf 'a b' > .hg/cache/tags
+  $ printf 'a b' > .hg/cache/tags2
   $ hg identify
-  .hg/cache/tags is corrupt, rebuilding it
+  .hg/cache/tags2 is corrupt, rebuilding it
   acb14030fe0a tip
   $ cacheexists
   tag cache exists
@@ -69,14 +69,14 @@ 
 
 Repeat with cold tag cache:
 
-  $ rm -f .hg/cache/tags
+  $ rm -f .hg/cache/tags2
   $ hg identify
   b9154636be93 tip
 
 And again, but now unable to write tag cache:
 
 #if unix-permissions
-  $ rm -f .hg/cache/tags
+  $ rm -f .hg/cache/tags2
   $ chmod 555 .hg
   $ hg identify
   b9154636be93 tip
@@ -216,11 +216,13 @@ 
 
 Dump cache:
 
-  $ cat .hg/cache/tags
+  $ cat .hg/cache/tags2
   4 0c192d7d5e6b78a714de54a2e9627952a877e25a 0c04f2a8af31de17fab7422878ee5a2dadbc943d
   3 6fa450212aeb2a21ed616a54aea39a4a27894cd7 7d3b718c964ef37b89e550ebdafd5789e76ce1b0
   2 7a94127795a33c10a370c93f731fd9fea0b79af6 0c04f2a8af31de17fab7422878ee5a2dadbc943d
   
+  bbd179dfa0a71671c253b3ae0aa1513b60d199fa bar
+  bbd179dfa0a71671c253b3ae0aa1513b60d199fa bar
   78391a272241d70354aa14c874552cad6b51bb42 bar
 
 Test tag removal:
@@ -326,7 +328,7 @@ 
   $ hg tags                  # partly stale
   tip                                4:735c3ca72986
   bar                                0:bbd179dfa0a7
-  $ rm -f .hg/cache/tags
+  $ rm -f .hg/cache/tags2
   $ hg tags                  # cold cache
   tip                                4:735c3ca72986
   bar                                0:bbd179dfa0a7
@@ -396,6 +398,11 @@ 
   localtag                           1:a0b6fe111088
   globaltag                          0:bbd179dfa0a7
 
+  $ hg tags -v
+  tip                                2:5c70a037bb37
+  localtag                           1:a0b6fe111088
+  globaltag                          0:bbd179dfa0a7
+
   $ hg tag -r 1 localtag2
   $ hg tags -v
   tip                                3:bbfb8cd42be2
@@ -403,4 +410,10 @@ 
   localtag                           1:a0b6fe111088
   globaltag                          0:bbd179dfa0a7
 
+  $ hg tags -v
+  tip                                3:bbfb8cd42be2
+  localtag2                          1:a0b6fe111088
+  localtag                           1:a0b6fe111088
+  globaltag                          0:bbd179dfa0a7
+
   $ cd ..