Patchwork [4,of,5,V2,in-clowncopter] tags: write a separate tags cache file for unfiltered repos

login
register
mail settings
Submitter Pierre-Yves David
Date April 16, 2015, 7:21 p.m.
Message ID <6f7f1cf7284b160d5ccb.1429212115@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/8724/
State Accepted
Headers show

Comments

Pierre-Yves David - April 16, 2015, 7:21 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1429199653 14400
#      Thu Apr 16 11:54:13 2015 -0400
# Node ID 6f7f1cf7284b160d5ccb16bc5920134f0ed851ff
# Parent  95ff070e3d341b67c4d4bce84782db94ea038a9b
tags: write a separate tags cache file for unfiltered repos

Since we changed the format of the tags cache, we should bump the
filename. Before this patch, "tags" was being used for unfiltered
repositories. Change the naming scheme to be consistent and ensure
that a new cache file is used.

While I was here, I updated the docs to describe the existence of
multiple caches. I also added explicit test coverage for the creation of
the unfiltered tags cache.

Patch

diff --git a/mercurial/tags.py b/mercurial/tags.py
--- a/mercurial/tags.py
+++ b/mercurial/tags.py
@@ -34,14 +34,15 @@  import time
 # of finding global tags, which is looking up the .hgtags filenode in the
 # manifest for each head. This can take dozens or over 100ms for
 # repositories with very large manifests. Multiplied by dozens or even
 # hundreds of heads and there is a significant performance concern.
 #
-# The "tags" cache stores information about the history of tags.
+# There also exist a separate cache file for each repository filter.
+# These "tags-*" files store information about the history of tags.
 #
-# The cache file consists of a cache validation line followed by a history
-# of tags.
+# The tags cache files consists of a cache validation line followed by
+# a history of tags.
 #
 # The cache validation line has the format:
 #
 #   <tiprev> <tipnode> [<filteredhash>]
 #
@@ -237,11 +238,11 @@  def _updatetags(filetags, tagtype, allta
         ahist.extend([n for n in bhist if n not in ahist])
         alltags[name] = anode, ahist
 
 def _filename(repo):
     """name of a tagcache file for a given repo or repoview"""
-    filename = 'cache/tags'
+    filename = 'cache/tags2'
     if repo.filtername:
         filename = '%s-%s' % (filename, repo.filtername)
     return filename
 
 def _readtagcache(ui, repo):
diff --git a/tests/test-obsolete-tag-cache.t b/tests/test-obsolete-tag-cache.t
--- a/tests/test-obsolete-tag-cache.t
+++ b/tests/test-obsolete-tag-cache.t
@@ -45,11 +45,11 @@  Trigger tags cache population by doing s
   tip                                5:2942a772f72a
   head2                              4:042eb6bfcc49
   test2                              2:d75775ffbc6b
   test1                              0:55482a6fb4b1
 
-  $ cat .hg/cache/tags-visible
+  $ cat .hg/cache/tags2-visible
   5 2942a772f72a444bef4bef13874d515f50fa27b6
   042eb6bfcc4909bad84a1cbf6eb1ddf0ab587d41 head2
   55482a6fb4b1881fa8f746fd52cf6f096bb21c89 test1
   d75775ffbc6bca1794d300f5571272879bd280da test2
 
@@ -60,11 +60,11 @@  Hiding a non-tip changeset should change
   $ hg tags
   tip                                5:2942a772f72a
   head2                              4:042eb6bfcc49
   test1                              0:55482a6fb4b1
 
-  $ cat .hg/cache/tags-visible
+  $ cat .hg/cache/tags2-visible
   5 2942a772f72a444bef4bef13874d515f50fa27b6 f34fbc9a9769ba9eff5aff3d008a6b49f85c08b1
   042eb6bfcc4909bad84a1cbf6eb1ddf0ab587d41 head2
   55482a6fb4b1881fa8f746fd52cf6f096bb21c89 test1
 
   $ hg blackbox -l 4
@@ -80,14 +80,34 @@  Hiding another changeset should cause th
 
   $ hg tags
   tip                                5:2942a772f72a
   head2                              4:042eb6bfcc49
 
-  $ cat .hg/cache/tags-visible
+  $ cat .hg/cache/tags2-visible
   5 2942a772f72a444bef4bef13874d515f50fa27b6 2fce1eec33263d08a4d04293960fc73a555230e4
   042eb6bfcc4909bad84a1cbf6eb1ddf0ab587d41 head2
 
   $ hg blackbox -l 4
   1970/01/01 00:00:00 bob> tags
   1970/01/01 00:00:00 bob> 1/1 cache hits/lookups in * seconds (glob)
   1970/01/01 00:00:00 bob> writing tags cache file with 1 tags
   1970/01/01 00:00:00 bob> tags exited 0 after * seconds (glob)
+
+Resolving tags on an unfiltered repo writes a separate tags cache
+
+  $ hg --hidden tags
+  tip                                5:2942a772f72a
+  head2                              4:042eb6bfcc49
+  test2                              2:d75775ffbc6b
+  test1                              0:55482a6fb4b1
+
+  $ cat .hg/cache/tags2
+  5 2942a772f72a444bef4bef13874d515f50fa27b6
+  042eb6bfcc4909bad84a1cbf6eb1ddf0ab587d41 head2
+  55482a6fb4b1881fa8f746fd52cf6f096bb21c89 test1
+  d75775ffbc6bca1794d300f5571272879bd280da test2
+
+  $ hg blackbox -l 4
+  1970/01/01 00:00:00 bob> --hidden tags
+  1970/01/01 00:00:00 bob> 2/2 cache hits/lookups in * seconds (glob)
+  1970/01/01 00:00:00 bob> writing tags cache file with 3 tags
+  1970/01/01 00:00:00 bob> --hidden tags exited 0 after * seconds (glob)
diff --git a/tests/test-tags.t b/tests/test-tags.t
--- a/tests/test-tags.t
+++ b/tests/test-tags.t
@@ -7,11 +7,11 @@  setup
   > EOF
 
 Helper functions:
 
   $ cacheexists() {
-  >   [ -f .hg/cache/tags-visible ] && echo "tag cache exists" || echo "no tag cache"
+  >   [ -f .hg/cache/tags2-visible ] && echo "tag cache exists" || echo "no tag cache"
   > }
 
   $ fnodescacheexists() {
   >   [ -f .hg/cache/hgtagsfnodes1 ] && echo "fnodes cache exists" || echo "no fnodes cache"
   > }
@@ -54,11 +54,11 @@  No fnodes cache because .hgtags file doe
   $ fnodescacheexists
   no fnodes cache
 
 Try corrupting the cache
 
-  $ printf 'a b' > .hg/cache/tags-visible
+  $ printf 'a b' > .hg/cache/tags2-visible
   $ hg identify
   acb14030fe0a tip
   $ cacheexists
   tag cache exists
   $ fnodescacheexists
@@ -100,11 +100,11 @@  The cache should have an empty entry for
   0010: ff ff ff ff ff ff ff ff b9 15 46 36 26 b7 b4 a7 |..........F6&...|
   0020: 73 e0 9e e3 c5 2f 51 0e 19 e0 5e 1f f9 66 d8 59 |s..../Q...^..f.Y|
 
 Repeat with cold tag cache:
 
-  $ rm -f .hg/cache/tags-visible .hg/cache/hgtagsfnodes1
+  $ rm -f .hg/cache/tags2-visible .hg/cache/hgtagsfnodes1
   $ hg identify
   b9154636be93 tip
 
   $ fnodescacheexists
   fnodes cache exists
@@ -115,20 +115,20 @@  Repeat with cold tag cache:
   0020: 73 e0 9e e3 c5 2f 51 0e 19 e0 5e 1f f9 66 d8 59 |s..../Q...^..f.Y|
 
 And again, but now unable to write tag cache:
 
 #if unix-permissions
-  $ rm -f .hg/cache/tags-visible .hg/cache/hgtagsfnodes1
+  $ rm -f .hg/cache/tags2-visible .hg/cache/hgtagsfnodes1
   $ chmod 555 .hg/cache
   $ hg identify
   b9154636be93 tip
   $ chmod 755 .hg/cache
 #endif
 
 Tag cache debug info written to blackbox log
 
-  $ rm -f .hg/cache/tags-visible .hg/cache/hgtagsfnodes1
+  $ rm -f .hg/cache/tags2-visible .hg/cache/hgtagsfnodes1
   $ hg identify
   b9154636be93 tip
   $ hg blackbox -l 5
   1970/01/01 00:00:00 bob> identify
   1970/01/01 00:00:00 bob> writing 48 bytes to cache/hgtagsfnodes1
@@ -136,11 +136,11 @@  Tag cache debug info written to blackbox
   1970/01/01 00:00:00 bob> writing tags cache file with 1 tags
   1970/01/01 00:00:00 bob> identify exited 0 after ?.?? seconds (glob)
 
 Failure to acquire lock results in no write
 
-  $ rm -f .hg/cache/tags-visible .hg/cache/hgtagsfnodes1
+  $ rm -f .hg/cache/tags2-visible .hg/cache/hgtagsfnodes1
   $ echo 'foo:1' > .hg/wlock
   $ hg identify
   b9154636be93 tip
   $ hg blackbox -l 5
   1970/01/01 00:00:00 bob> identify
@@ -152,11 +152,11 @@  Failure to acquire lock results in no wr
   $ fnodescacheexists
   no fnodes cache
 
   $ rm .hg/wlock
 
-  $ rm -f .hg/cache/tags-visible .hg/cache/hgtagsfnodes1
+  $ rm -f .hg/cache/tags2-visible .hg/cache/hgtagsfnodes1
   $ hg identify
   b9154636be93 tip
 
 Create a branch:
 
@@ -309,11 +309,11 @@  Detailed dump of tag info:
   rev 4: .hgtags:
   bbd179dfa0a71671c253b3ae0aa1513b60d199fa bar
 
 Dump cache:
 
-  $ cat .hg/cache/tags-visible
+  $ cat .hg/cache/tags2-visible
   4 0c192d7d5e6b78a714de54a2e9627952a877e25a
   bbd179dfa0a71671c253b3ae0aa1513b60d199fa bar
   bbd179dfa0a71671c253b3ae0aa1513b60d199fa bar
   78391a272241d70354aa14c874552cad6b51bb42 bar
 
@@ -351,11 +351,11 @@  Errors writing to .hgtags fnodes cache a
 
   $ echo dummy2 > foo
   $ hg commit -m throwaway2
 
   $ chmod a-w .hg/cache/hgtagsfnodes1
-  $ rm -f .hg/cache/tags-visible
+  $ rm -f .hg/cache/tags2-visible
 
   $ hg tags
   tip                                6:b968051b5cf3
   bar                                1:78391a272241
 
@@ -367,11 +367,11 @@  Errors writing to .hgtags fnodes cache a
   1970/01/01 00:00:00 bob> tags exited 0 after * seconds (glob)
 
   $ chmod a+w .hg/cache/hgtagsfnodes1
 #endif
 
-  $ rm -f .hg/cache/tags-visible
+  $ rm -f .hg/cache/tags2-visible
   $ hg tags
   tip                                6:b968051b5cf3
   bar                                1:78391a272241
 
   $ hg blackbox -l 5
@@ -519,11 +519,11 @@  Strip 2: destroy whole branch, no old he
   $ hg --config extensions.mq= strip 4
   saved backup bundle to $TESTTMP/t3/.hg/strip-backup/*-backup.hg (glob)
   $ hg tags                  # partly stale
   tip                                4:735c3ca72986
   bar                                0:bbd179dfa0a7
-  $ rm -f .hg/cache/tags-visible
+  $ rm -f .hg/cache/tags2-visible
   $ hg tags                  # cold cache
   tip                                4:735c3ca72986
   bar                                0:bbd179dfa0a7
 
 Test tag rank with 3 heads: