[PATCH 1 of 2 V3] move tags.cache and branchheads.cache to a collected cache folder .hg/caches/

Jason Harris jason.f.harris at gmail.com
Tue Jan 4 00:09:25 CST 2011


# HG changeset patch
# User jfh <jason at jasonfharris.com>
# Date 1294118948 -3600
# Node ID 65a39818367f9657a291cade204e7f574e919dbc
# Parent  1f4721de2ca9744b3488bf050a11ed23e89889d6
move tags.cache and branchheads.cache to a collected cache folder .hg/caches/

The generation of cache files like tags.cache and branchheads.cache is not an
actual reflection of things changing in the whole of the .hg directory (like eg
a commit or a rebase or something) but instead these cache files are just part
of bookkeeping. As such its convienant to allow various clients to ignore file
events to do with these cache files which would otherwise cause a double
refresh. Eg one refresh might occur after a commit, but the act of refreshing
after the commit would cause Mercurial to generate a new branchheads.cache which
would then cause a second refresh, for clients.

However if these cache files are moved into a directory like eg .hg/caches/ then
GUI clients on OSX (and possibly other platforms) can happily ignore file events
in this cache directory.

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -439,7 +439,8 @@
     def _readbranchcache(self):
         partial = {}
         try:
-            f = self.opener("branchheads.cache")
+            fn = os.path.join("caches", "branchheads.cache")
+            f = self.opener(fn)
             lines = f.read().split('\n')
             f.close()
         except (IOError, OSError):
@@ -467,7 +468,8 @@
 
     def _writebranchcache(self, branches, tip, tiprev):
         try:
-            f = self.opener("branchheads.cache", "w", atomictemp=True)
+            fn = os.path.join("caches", "branchheads.cache")
+            f = self.opener(fn, "w", atomictemp=True)
             f.write("%s %s\n" % (hex(tip), tiprev))
             for label, nodes in branches.iteritems():
                 for node in nodes:
diff --git a/mercurial/tags.py b/mercurial/tags.py
--- a/mercurial/tags.py
+++ b/mercurial/tags.py
@@ -12,6 +12,7 @@
 
 from node import nullid, bin, hex, short
 from i18n import _
+import os.path
 import encoding
 import error
 
@@ -154,7 +155,7 @@
     set, caller is responsible for reading tag info from each head.'''
 
     try:
-        cachefile = repo.opener('tags.cache', 'r')
+        cachefile = repo.opener(os.path.join('caches', 'tags.cache'), 'r')
         # force reading the file for static-http
         cachelines = iter(cachefile)
     except IOError:
@@ -189,7 +190,7 @@
                     cachefnode[headnode] = fnode
         except (ValueError, TypeError):
             # corruption of tags.cache, just recompute it
-            ui.warn(_('.hg/tags.cache is corrupt, rebuilding it\n'))
+            ui.warn(_('.hg/caches/tags.cache is corrupt, rebuilding it\n'))
             cacheheads = []
             cacherevs = []
             cachefnode = {}
@@ -251,7 +252,8 @@
 def _writetagcache(ui, repo, heads, tagfnode, cachetags):
 
     try:
-        cachefile = repo.opener('tags.cache', 'w', atomictemp=True)
+        fn = os.path.join('caches', 'tags.cache')
+        cachefile = repo.opener(fn, 'w', atomictemp=True)
     except (OSError, IOError):
         return
 
diff --git a/tests/test-hardlinks.t b/tests/test-hardlinks.t
--- a/tests/test-hardlinks.t
+++ b/tests/test-hardlinks.t
@@ -182,7 +182,8 @@
   $ nlinksdir r4
   2 r4/.hg/00changelog.i
   2 r4/.hg/branch
-  2 r4/.hg/branchheads.cache
+  2 r4/.hg/caches/branchheads.cache
+  2 r4/.hg/caches/tags.cache
   2 r4/.hg/dirstate
   2 r4/.hg/hgrc
   2 r4/.hg/last-message.txt
@@ -194,7 +195,6 @@
   2 r4/.hg/store/data/f1.i
   2 r4/.hg/store/fncache
   2 r4/.hg/store/undo
-  2 r4/.hg/tags.cache
   2 r4/.hg/undo.branch
   2 r4/.hg/undo.desc
   2 r4/.hg/undo.dirstate
@@ -210,7 +210,8 @@
   $ nlinksdir r4
   2 r4/.hg/00changelog.i
   1 r4/.hg/branch
-  2 r4/.hg/branchheads.cache
+  2 r4/.hg/caches/branchheads.cache
+  2 r4/.hg/caches/tags.cache
   1 r4/.hg/dirstate
   2 r4/.hg/hgrc
   2 r4/.hg/last-message.txt
@@ -222,7 +223,6 @@
   2 r4/.hg/store/data/f1.i
   2 r4/.hg/store/fncache
   2 r4/.hg/store/undo
-  2 r4/.hg/tags.cache
   2 r4/.hg/undo.branch
   2 r4/.hg/undo.desc
   2 r4/.hg/undo.dirstate
diff --git a/tests/test-inherit-mode.t b/tests/test-inherit-mode.t
--- a/tests/test-inherit-mode.t
+++ b/tests/test-inherit-mode.t
@@ -105,7 +105,8 @@
   $ python ../printmodes.py ../push
   00770 ../push/.hg/
   00660 ../push/.hg/00changelog.i
-  00660 ../push/.hg/branchheads.cache
+  00770 ../push/.hg/caches/
+  00660 ../push/.hg/caches/branchheads.cache
   00660 ../push/.hg/requires
   00770 ../push/.hg/store/
   00660 ../push/.hg/store/00changelog.i
diff --git a/tests/test-mq-caches.t b/tests/test-mq-caches.t
--- a/tests/test-mq-caches.t
+++ b/tests/test-mq-caches.t
@@ -1,4 +1,4 @@
-  $ branches=.hg/branchheads.cache
+  $ branches=.hg/caches/branchheads.cache
   $ echo '[extensions]' >> $HGRCPATH
   $ echo 'mq =' >> $HGRCPATH
 
diff --git a/tests/test-mq.t b/tests/test-mq.t
--- a/tests/test-mq.t
+++ b/tests/test-mq.t
@@ -284,12 +284,12 @@
 qpush with dump of tag cache
 Dump the tag cache to ensure that it has exactly one head after qpush.
 
-  $ rm -f .hg/tags.cache
+  $ rm -f .hg/caches/tags.cache
   $ hg tags > /dev/null
 
-.hg/tags.cache (pre qpush):
+.hg/caches/tags.cache (pre qpush):
 
-  $ cat .hg/tags.cache
+  $ cat .hg/caches/tags.cache
   1 [\da-f]{40} (re)
   
   $ hg qpush
@@ -297,9 +297,9 @@
   now at: test.patch
   $ hg tags > /dev/null
 
-.hg/tags.cache (post qpush):
+.hg/caches/tags.cache (post qpush):
 
-  $ cat .hg/tags.cache
+  $ cat .hg/caches/tags.cache
   2 [\da-f]{40} (re)
   
   $ checkundo qpush
diff --git a/tests/test-newbranch.t b/tests/test-newbranch.t
--- a/tests/test-newbranch.t
+++ b/tests/test-newbranch.t
@@ -1,4 +1,4 @@
-  $ branchcache=.hg/branchheads.cache
+  $ branchcache=.hg/caches/branchheads.cache
 
   $ hg init t
   $ cd t
diff --git a/tests/test-static-http.t b/tests/test-static-http.t
--- a/tests/test-static-http.t
+++ b/tests/test-static-http.t
@@ -64,7 +64,7 @@
 
 check for HTTP opener failures when cachefile does not exist
 
-  $ rm .hg/*.cache
+  $ rm .hg/caches/*.cache
   $ cd ../local
   $ echo '[hooks]' >> .hg/hgrc
   $ echo 'changegroup = python ../printenv.py changegroup' >> .hg/hgrc
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/tags.cache ] && echo "tag cache exists" || echo "no tag cache"
+  >   [ -f .hg/caches/tags.cache ] && echo "tag cache exists" || echo "no tag cache"
   > }
 
   $ dumptags() {
@@ -36,9 +36,9 @@
 
 Try corrupting the cache
 
-  $ printf 'a b' > .hg/tags.cache
+  $ printf 'a b' > .hg/caches/tags.cache
   $ hg identify
-  .hg/tags.cache is corrupt, rebuilding it
+  .hg/caches/tags.cache is corrupt, rebuilding it
   acb14030fe0a tip
   $ cacheexists
   tag cache exists
@@ -69,13 +69,13 @@
 
 Repeat with cold tag cache:
 
-  $ rm -f .hg/tags.cache
+  $ rm -f .hg/caches/tags.cache
   $ hg identify
   b9154636be93 tip
 
 And again, but now unable to write tag cache:
 
-  $ rm -f .hg/tags.cache
+  $ rm -f .hg/caches/tags.cache
   $ chmod 555 .hg
   $ hg identify
   b9154636be93 tip
@@ -216,7 +216,7 @@
 
 Dump cache:
 
-  $ cat .hg/tags.cache
+  $ cat .hg/caches/tags.cache
   4 0c192d7d5e6b78a714de54a2e9627952a877e25a 0c04f2a8af31de17fab7422878ee5a2dadbc943d
   3 6fa450212aeb2a21ed616a54aea39a4a27894cd7 7d3b718c964ef37b89e550ebdafd5789e76ce1b0
   2 7a94127795a33c10a370c93f731fd9fea0b79af6 0c04f2a8af31de17fab7422878ee5a2dadbc943d
@@ -325,7 +325,7 @@
   $ hg tags                  # partly stale
   tip                                4:735c3ca72986
   bar                                0:bbd179dfa0a7
-  $ rm -f .hg/tags.cache
+  $ rm -f .hg/caches/tags.cache
   $ hg tags                  # cold cache
   tip                                4:735c3ca72986
   bar                                0:bbd179dfa0a7


More information about the Mercurial-devel mailing list