Mercurial > hg
comparison mercurial/repoview.py @ 23378:47091002ae62
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.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Thu, 13 Nov 2014 11:11:17 +0000 |
parents | 90200e864ffc |
children | ced3ecfc2e57 |
comparison
equal
deleted
inserted
replaced
23375:a179db3db9b9 | 23378:47091002ae62 |
---|---|
69 """ | 69 """ |
70 h = util.sha1() | 70 h = util.sha1() |
71 h.update(''.join(repo.heads())) | 71 h.update(''.join(repo.heads())) |
72 h.update(str(hash(frozenset(hideable)))) | 72 h.update(str(hash(frozenset(hideable)))) |
73 return h.digest() | 73 return h.digest() |
74 | |
75 def _writehiddencache(cachefile, cachehash, hidden): | |
76 """write hidden data to a cache file""" | |
77 data = struct.pack('>%ii' % len(hidden), *sorted(hidden)) | |
78 cachefile.write(struct.pack(">H", cacheversion)) | |
79 cachefile.write(cachehash) | |
80 cachefile.write(data) | |
74 | 81 |
75 def trywritehiddencache(repo, hideable, hidden): | 82 def trywritehiddencache(repo, hideable, hidden): |
76 """write cache of hidden changesets to disk | 83 """write cache of hidden changesets to disk |
77 | 84 |
78 Will not write the cache if a wlock cannot be obtained lazily. | 85 Will not write the cache if a wlock cannot be obtained lazily. |
85 try: | 92 try: |
86 try: | 93 try: |
87 wlock = repo.wlock(wait=False) | 94 wlock = repo.wlock(wait=False) |
88 # write cache to file | 95 # write cache to file |
89 newhash = cachehash(repo, hideable) | 96 newhash = cachehash(repo, hideable) |
90 sortedset = sorted(hidden) | |
91 data = struct.pack('>%ii' % len(sortedset), *sortedset) | |
92 fh = repo.vfs.open(cachefile, 'w+b', atomictemp=True) | 97 fh = repo.vfs.open(cachefile, 'w+b', atomictemp=True) |
93 fh.write(struct.pack(">H", cacheversion)) | 98 _writehiddencache(fh, newhash, hidden) |
94 fh.write(newhash) | |
95 fh.write(data) | |
96 except (IOError, OSError): | 99 except (IOError, OSError): |
97 repo.ui.debug('error writing hidden changesets cache') | 100 repo.ui.debug('error writing hidden changesets cache') |
98 except error.LockHeld: | 101 except error.LockHeld: |
99 repo.ui.debug('cannot obtain lock to write hidden changesets cache') | 102 repo.ui.debug('cannot obtain lock to write hidden changesets cache') |
100 finally: | 103 finally: |