# HG changeset patch # User jfh # Date 2011-01-04 05:29:08 # Node ID 5ccdca7df211eb326832d72537da1f21c081f6bb # Parent 952baa2f3325039daaefa40519885d89a9ce6fbd 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. diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -439,7 +439,7 @@ class localrepository(repo.repository): 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 @@ class localrepository(repo.repository): 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: 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 @@ -151,7 +152,7 @@ def _readtagcache(ui, repo): 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 @@ def _readtagcache(ui, repo): 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 _readtagcache(ui, repo): 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 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 @@ r4 has hardlinks in the working dir (not $ 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 @@ r4 has hardlinks in the working dir (not 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 @@ Update back to revision 11 in r4 should $ 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 @@ Update back to revision 11 in r4 should 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 @@ group can still write everything $ 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 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/cache/branchheads $ 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 @@ qpop 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 @@ Dump the tag cache to ensure that it has 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 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/cache/branchheads $ 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 @@ one pull 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 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/cache/tags ] && echo "tag cache exists" || echo "no tag cache" > } $ dumptags() { @@ -36,9 +36,9 @@ Setup: 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 @@ Create a tag behind hg's back: 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 @@ Detailed dump of tag info: Dump cache: - $ cat .hg/tags.cache + $ cat .hg/cache/tags 4 0c192d7d5e6b78a714de54a2e9627952a877e25a 0c04f2a8af31de17fab7422878ee5a2dadbc943d 3 6fa450212aeb2a21ed616a54aea39a4a27894cd7 7d3b718c964ef37b89e550ebdafd5789e76ce1b0 2 7a94127795a33c10a370c93f731fd9fea0b79af6 0c04f2a8af31de17fab7422878ee5a2dadbc943d @@ -325,7 +325,7 @@ Strip 2: destroy whole branch, no old he $ 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