[PATCH 1 of 5 main-line-of-work] repoview: extract actual hidden cache writing in its own function

Pierre-Yves David pierre-yves.david at ens-lyon.org
Thu Nov 20 03:30:27 UTC 2014


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1415877077 0
#      Thu Nov 13 11:11:17 2014 +0000
# Node ID 134e2fe35179f0ff82d63a3a9ed7c55d9d5f4098
# Parent  936b0ff3434668e2b8c25476664056764ce3b498
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.

diff --git a/mercurial/repoview.py b/mercurial/repoview.py
--- a/mercurial/repoview.py
+++ b/mercurial/repoview.py
@@ -70,10 +70,17 @@ def cachehash(repo, hideable):
     h = util.sha1()
     h.update(''.join(repo.heads()))
     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
 
     Will not write the cache if a wlock cannot be obtained lazily.
     The cache consists of a head of 22byte:
@@ -85,16 +92,12 @@ def trywritehiddencache(repo, hideable, 
     try:
         try:
             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:
             repo.ui.debug('cannot obtain lock to write hidden changesets cache')
     finally:


More information about the Mercurial-devel mailing list