[PATCH] move tags.cache and branchheads.cache to a collected cache folder .hg/caches/
Adrian Buehlmann
adrian at cadifra.com
Sat Dec 25 04:46:36 CST 2010
On 2010-12-24 23:22, Jason Harris wrote:
> # 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.
Sounds reasonable.
Perhaps you can implement it a bit differently though. See inline
comment below
> 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"))
What about setting up an new cache opener ('copener') and using it like this
f = self.copener("branchheads")
I envision having the cacheopener's base directory in '.hg/cache'. Also,
we can drop the '.cache' suffix on the files in there while we're at it.
> 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