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

Jason Harris jason.f.harris at gmail.com
Sun Dec 26 06:13:49 CST 2010


On Dec 25, 2010, at 11:46 AM, Adrian Buehlmann wrote:

> 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.

Cool...


> 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.

What about the line in:

http://mercurial.selenic.com/wiki/CodingStyle?action=show&redirect=BasicCodingStyle

which says:
Think twice about using classes, functions are almost always smaller and simpler.

Thus, do we really want a class here copener which can be confused with opener (its one letter different), when the other code as I have it inlined is easily readable, just as simple to maintain as the current code, and totally obvious as to what its doing?  Admittedly if there were lots of cache files running around one might want such a class, but currently there are only two such files right?

If Matt and other crew members say they want a class here, I'll put it in, but to me for the moment it would seem like needless abstraction... Still I am not a guru in the Mercurial code base... so I could well be wrong here. But thanks for the comments...

Cheers,
  Jas


>>             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
> 
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel



More information about the Mercurial-devel mailing list