Mercurial > evolve
changeset 5865:d7ed88810457 stable
evolve: make firstmergecache.save/load use struct.unpack/pack (issue6354)
arraytobytes() and arrayfrombytes() is not cross-platform.
author | Anton Shestakov <av6@dwimlabs.net> |
---|---|
date | Tue, 30 Mar 2021 19:35:52 +0800 |
parents | 97f5b5b25299 |
children | 5931ad39ea37 |
files | hgext3rd/evolve/firstmergecache.py tests/test-discovery-obshashrange-cache.t |
diffstat | 2 files changed, 52 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext3rd/evolve/firstmergecache.py Wed Mar 31 20:13:31 2021 +0800 +++ b/hgext3rd/evolve/firstmergecache.py Tue Mar 30 19:35:52 2021 +0800 @@ -129,20 +129,23 @@ assert repo.filtername is None data = repo.cachevfs.tryread(self._filepath) + self._cachekey = self.emptykey self._data = array.array(r'l') - if not data: - self._cachekey = self.emptykey - else: + if data: headerdata = data[:self._cachekeysize] - self._cachekey = self._deserializecachekey(headerdata) - compat.arrayfrombytes(self._data, data[self._cachekeysize:]) + cachekey = self._deserializecachekey(headerdata) + expected = self._datastruct.size * (cachekey[0] + 1) + data = data[self._cachekeysize:] + if len(data) == expected: + self._data.extend(self._deserializedata(data)) + self._cachekey = cachekey + else: + repo.ui.debug(b'firstmergecache file seems to be corrupted, ' + b'it will be rebuilt from scratch\n') self._ondiskkey = self._cachekey def save(self, repo): """save the data to disk - - Format is pretty simple, we serialise the cache key and then drop the - bytearray. """ if self._cachekey is None or self._cachekey == self._ondiskkey: return @@ -151,7 +154,7 @@ cachefile = repo.cachevfs(self._filepath, b'w', atomictemp=True) headerdata = self._serializecachekey() cachefile.write(headerdata) - cachefile.write(compat.arraytobytes(self._data)) + cachefile.write(self._serializedata(self._data)) cachefile.close() self._ondiskkey = self._cachekey except (IOError, OSError) as exc:
--- a/tests/test-discovery-obshashrange-cache.t Wed Mar 31 20:13:31 2021 +0800 +++ b/tests/test-discovery-obshashrange-cache.t Tue Mar 30 19:35:52 2021 +0800 @@ -292,6 +292,46 @@ f69452c5b1af -1 4de32a90b66c -1 + $ "$PYTHON" repack.py main/.hg/cache/evoext-firstmerge-00 + $ f -H main/.hg/cache/evoext-firstmerge-00 + main/.hg/cache/evoext-firstmerge-00: + 0000: 00 00 00 07 4d e3 2a 90 b6 6c d0 83 eb f3 c0 0b |....M.*..l......| + 0010: 41 27 7a a7 ab ca 51 dd ff ff ff ff ff ff ff ff |A'z...Q.........| + 0020: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| + 0030: ff ff ff ff ff ff ff ff |........| + + $ hg -R main debugfirstmergecache --debug + firstmergecache file seems to be corrupted, it will be rebuilt from scratch + 1ea73414a91b -1 + 66f7d451a68b -1 + 01241442b3c2 -1 + 2dc09a01254d -1 + bebd167eb94d -1 + c8d03c1b5e94 -1 + f69452c5b1af -1 + 4de32a90b66c -1 + + $ "$PYTHON" truncate.py main/.hg/cache/evoext-firstmerge-00 -4 + $ f -H main/.hg/cache/evoext-firstmerge-00 + main/.hg/cache/evoext-firstmerge-00: + 0000: 00 00 00 07 4d e3 2a 90 b6 6c d0 83 eb f3 c0 0b |....M.*..l......| + 0010: 41 27 7a a7 ab ca 51 dd ff ff ff ff ff ff ff ff |A'z...Q.........| + 0020: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| + 0030: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| + 0040: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| + 0050: ff ff ff ff |....| + + $ hg -R main debugfirstmergecache --debug + firstmergecache file seems to be corrupted, it will be rebuilt from scratch + 1ea73414a91b -1 + 66f7d451a68b -1 + 01241442b3c2 -1 + 2dc09a01254d -1 + bebd167eb94d -1 + c8d03c1b5e94 -1 + f69452c5b1af -1 + 4de32a90b66c -1 + $ hg -R main debugstablesortcache --debug number of revisions: 8 number of merge: 0