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

login
register
mail settings
Submitter Pierre-Yves David
Date Nov. 20, 2014, 3:30 a.m.
Message ID <134e2fe35179f0ff82d6.1416454227@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/6801/
State Accepted
Commit 47091002ae622a9450cebe586b9d8efc28f04a61
Headers show

Comments

Pierre-Yves David - Nov. 20, 2014, 3:30 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@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.

Patch

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: