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

Jason Harris jason.f.harris at gmail.com
Fri Dec 24 16:22:10 CST 2010


# HG changeset patch
# User jfh <jason at jasonfharris.com>
# Date 1293195683 -3600
# Node ID 53a4b25e7165c3842c8cd9e376a4240738070aab
# Parent  5314cbb775f6e2034be96bc64a54a0ec7c553a19
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,7 @@
     def _readbranchcache(self):
         partial = {}
         try:
-            f = self.opener("branchheads.cache")
+            f = self.opener(os.path.join("caches","branchheads.cache"))
             lines = f.read().split('\n')
             f.close()
         except (IOError, OSError):
@@ -467,7 +467,7 @@
 
     def _writebranchcache(self, branches, tip, tiprev):
         try:
-            f = self.opener("branchheads.cache", "w", atomictemp=True)
+            f = self.opener(os.path.join("caches","branchheads.cache"), "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,7 @@
 def _writetagcache(ui, repo, heads, tagfnode, cachetags):
 
     try:
-        cachefile = repo.opener('tags.cache', 'w', atomictemp=True)
+        cachefile = repo.opener(os.path.join('caches','tags.cache'), 'w', atomictemp=True)
     except (OSError, IOError):
         return
 


More information about the Mercurial-devel mailing list