repoview: extract actual hidden cache writing in its own function
This will allow the generation of this cache within the transaction. Relying on
the transaction will reduce the chance of reader seeing bad cache.
--- a/mercurial/repoview.py Wed Nov 19 23:15:07 2014 -0800
+++ b/mercurial/repoview.py Thu Nov 13 11:11:17 2014 +0000
@@ -72,6 +72,13 @@
h.update(str(hash(frozenset(hideable))))
return h.digest()
+def _writehiddencache(cachefile, cachehash, hidden):
+ """write hidden data to a cache file"""
+ data = struct.pack('>%ii' % len(hidden), *sorted(hidden))
+ cachefile.write(struct.pack(">H", cacheversion))
+ cachefile.write(cachehash)
+ cachefile.write(data)
+
def trywritehiddencache(repo, hideable, hidden):
"""write cache of hidden changesets to disk
@@ -87,12 +94,8 @@
wlock = repo.wlock(wait=False)
# write cache to file
newhash = cachehash(repo, hideable)
- sortedset = sorted(hidden)
- data = struct.pack('>%ii' % len(sortedset), *sortedset)
fh = repo.vfs.open(cachefile, 'w+b', atomictemp=True)
- fh.write(struct.pack(">H", cacheversion))
- fh.write(newhash)
- fh.write(data)
+ _writehiddencache(fh, newhash, hidden)
except (IOError, OSError):
repo.ui.debug('error writing hidden changesets cache')
except error.LockHeld: