move tags.cache and branchheads.cache to a collected cache folder .hg/cache/
authorjfh <jason@jasonfharris.com>
Tue, 04 Jan 2011 06:29:08 +0100
changeset 13272 5ccdca7df211
parent 13271 952baa2f3325
child 13273 764441ecbf2e
move tags.cache and branchheads.cache to a collected cache folder .hg/cache/ 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/cache/ then GUI clients on OSX (and possibly other platforms) can happily ignore file events in this cache directory.
mercurial/localrepo.py
mercurial/tags.py
tests/test-hardlinks.t
tests/test-inherit-mode.t
tests/test-mq-caches.t
tests/test-mq.t
tests/test-newbranch.t
tests/test-static-http.t
tests/test-tags.t
--- a/mercurial/localrepo.py	Sun Jan 16 17:26:34 2011 +0100
+++ b/mercurial/localrepo.py	Tue Jan 04 06:29:08 2011 +0100
@@ -439,7 +439,7 @@
     def _readbranchcache(self):
         partial = {}
         try:
-            f = self.opener("branchheads.cache")
+            f = self.opener(os.path.join("cache", "branchheads"))
             lines = f.read().split('\n')
             f.close()
         except (IOError, OSError):
@@ -467,7 +467,8 @@
 
     def _writebranchcache(self, branches, tip, tiprev):
         try:
-            f = self.opener("branchheads.cache", "w", atomictemp=True)
+            f = self.opener(os.path.join("cache", "branchheads"), "w",
+                            atomictemp=True)
             f.write("%s %s\n" % (hex(tip), tiprev))
             for label, nodes in branches.iteritems():
                 for node in nodes:
--- a/mercurial/tags.py	Sun Jan 16 17:26:34 2011 +0100
+++ b/mercurial/tags.py	Tue Jan 04 06:29:08 2011 +0100
@@ -12,6 +12,7 @@
 
 from node import nullid, bin, hex, short
 from i18n import _
+import os.path
 import encoding
 import error
 
@@ -151,7 +152,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('cache', 'tags'), 'r')
         # force reading the file for static-http
         cachelines = iter(cachefile)
     except IOError:
@@ -185,8 +186,8 @@
                     fnode = bin(line[2])
                     cachefnode[headnode] = fnode
         except (ValueError, TypeError):
-            # corruption of tags.cache, just recompute it
-            ui.warn(_('.hg/tags.cache is corrupt, rebuilding it\n'))
+            # corruption of the tags cache, just recompute it
+            ui.warn(_('.hg/cache/tags is corrupt, rebuilding it\n'))
             cacheheads = []
             cacherevs = []
             cachefnode = {}
@@ -248,7 +249,8 @@
 def _writetagcache(ui, repo, heads, tagfnode, cachetags):
 
     try:
-        cachefile = repo.opener('tags.cache', 'w', atomictemp=True)
+        cachefile = repo.opener(os.path.join('cache', 'tags'), 'w',
+                                atomictemp=True)
     except (OSError, IOError):
         return
 
--- a/tests/test-hardlinks.t	Sun Jan 16 17:26:34 2011 +0100
+++ b/tests/test-hardlinks.t	Tue Jan 04 06:29:08 2011 +0100
@@ -182,7 +182,8 @@
   $ nlinksdir r4
   2 r4/.hg/00changelog.i
   2 r4/.hg/branch
-  2 r4/.hg/branchheads.cache
+  2 r4/.hg/cache/branchheads
+  2 r4/.hg/cache/tags
   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/cache/branchheads
+  2 r4/.hg/cache/tags
   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
--- a/tests/test-inherit-mode.t	Sun Jan 16 17:26:34 2011 +0100
+++ b/tests/test-inherit-mode.t	Tue Jan 04 06:29:08 2011 +0100
@@ -105,7 +105,8 @@
   $ python ../printmodes.py ../push
   00770 ../push/.hg/
   00660 ../push/.hg/00changelog.i
-  00660 ../push/.hg/branchheads.cache
+  00770 ../push/.hg/cache/
+  00660 ../push/.hg/cache/branchheads
   00660 ../push/.hg/requires
   00770 ../push/.hg/store/
   00660 ../push/.hg/store/00changelog.i
--- a/tests/test-mq-caches.t	Sun Jan 16 17:26:34 2011 +0100
+++ b/tests/test-mq-caches.t	Tue Jan 04 06:29:08 2011 +0100
@@ -1,4 +1,4 @@
-  $ branches=.hg/branchheads.cache
+  $ branches=.hg/cache/branchheads
   $ echo '[extensions]' >> $HGRCPATH
   $ echo 'mq =' >> $HGRCPATH
 
--- a/tests/test-mq.t	Sun Jan 16 17:26:34 2011 +0100
+++ b/tests/test-mq.t	Tue Jan 04 06:29:08 2011 +0100
@@ -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/cache/tags
   $ hg tags > /dev/null
 
-.hg/tags.cache (pre qpush):
+.hg/cache/tags (pre qpush):
 
-  $ cat .hg/tags.cache
+  $ cat .hg/cache/tags
   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/cache/tags (post qpush):
 
-  $ cat .hg/tags.cache
+  $ cat .hg/cache/tags
   2 [\da-f]{40} (re)
   
   $ checkundo qpush
--- a/tests/test-newbranch.t	Sun Jan 16 17:26:34 2011 +0100
+++ b/tests/test-newbranch.t	Tue Jan 04 06:29:08 2011 +0100
@@ -1,4 +1,4 @@
-  $ branchcache=.hg/branchheads.cache
+  $ branchcache=.hg/cache/branchheads
 
   $ hg init t
   $ cd t
--- a/tests/test-static-http.t	Sun Jan 16 17:26:34 2011 +0100
+++ b/tests/test-static-http.t	Tue Jan 04 06:29:08 2011 +0100
@@ -64,7 +64,7 @@
 
 check for HTTP opener failures when cachefile does not exist
 
-  $ rm .hg/*.cache
+  $ rm .hg/cache/*
   $ cd ../local
   $ echo '[hooks]' >> .hg/hgrc
   $ echo 'changegroup = python ../printenv.py changegroup' >> .hg/hgrc
--- a/tests/test-tags.t	Sun Jan 16 17:26:34 2011 +0100
+++ b/tests/test-tags.t	Tue Jan 04 06:29:08 2011 +0100
@@ -1,7 +1,7 @@
 Helper functions:
 
   $ cacheexists() {
-  >   [ -f .hg/tags.cache ] && echo "tag cache exists" || echo "no tag cache"
+  >   [ -f .hg/cache/tags ] && 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/cache/tags
   $ hg identify
-  .hg/tags.cache is corrupt, rebuilding it
+  .hg/cache/tags 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/cache/tags
   $ hg identify
   b9154636be93 tip
 
 And again, but now unable to write tag cache:
 
-  $ rm -f .hg/tags.cache
+  $ rm -f .hg/cache/tags
   $ chmod 555 .hg
   $ hg identify
   b9154636be93 tip
@@ -216,7 +216,7 @@
 
 Dump cache:
 
-  $ cat .hg/tags.cache
+  $ cat .hg/cache/tags
   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/cache/tags
   $ hg tags                  # cold cache
   tip                                4:735c3ca72986
   bar                                0:bbd179dfa0a7