[PATCH 5 of 5 main-line-of-work] repoview: generate the hidden cache within a transaction if it exist
Pierre-Yves David
pierre-yves.david at ens-lyon.org
Thu Nov 20 03:30:31 UTC 2014
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# 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/repoview.py b/mercurial/repoview.py
--- a/mercurial/repoview.py
+++ b/mercurial/repoview.py
@@ -70,15 +70,15 @@ 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):
+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)
cachefile.write(data)
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
try:
try:
wlock = repo.wlock(wait=False)
# write cache to file
More information about the Mercurial-devel
mailing list