Patchwork [5,of,5,main-line-of-work] repoview: generate the hidden cache within a transaction if it exist

mail settings
Submitter Pierre-Yves David
Date Nov. 20, 2014, 3:30 a.m.
Message ID <>
Download mbox | patch
Permalink /patch/6804/
State Changes Requested
Headers show


Pierre-Yves David - Nov. 20, 2014, 3:30 a.m.
# HG changeset patch
# User Pierre-Yves David <>
# Date 1415877755 0
#      Thu Nov 13 11:22:35 2014 +0000
# Node ID 367d005d081a80e94a7538cbef137b105df890e0
# Parent  1e3843795c2cc7b154d9dcdd7cd249175f449361
repoview: generate the hidden cache within a transaction if it exist

If the cache is recomputed within a transaction, it will be written to disk as
part of the transaction. If such cache is recomputed during a transaction, the
new value are most likely attached to change in the transaction. So writing it
early would makes it invalid for reader until the transaction is closed. This
also offer a free rollback if the transaction abort.


diff --git a/mercurial/ b/mercurial/
--- a/mercurial/
+++ b/mercurial/
@@ -70,15 +70,15 @@  def cachehash(repo, hideable):
     h = util.sha1()
     return h.digest()
-def _writehiddencache(cachefile, cachehash, hidden):
+def _writehiddencache(cachefile, cachekey, 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(cachekey)
 def trywritehiddencache(repo, hideable, hidden):
     """write cache of hidden changesets to disk
@@ -86,10 +86,18 @@  def trywritehiddencache(repo, hideable, 
     The cache consists of a head of 22byte:
        2 byte    version number of the cache
       20 byte    sha1 to validate the cache
      n*4 byte    hidden revs
+    tr = repo.currenttransaction()
+    if tr is not None:
+        cachekey = cachehash(repo, hideable)
+        def writecache(fh):
+            _writehiddencache(fh, cachekey, hidden)
+        tr.addfilegenerator('hiddencache', (cachefile,), writecache,
+                            location='plain', cache=True)
+        return
     wlock = fh = None
             wlock = repo.wlock(wait=False)
             # write cache to file