Commit 5931ad39 authored by Anton Shestakov's avatar Anton Shestakov
Browse files

evolve: make stablesortcache.save/load use struct.unpack/pack (issue6354)

arraytobytes() and arrayfrombytes() is not cross-platform.
parent d7ed88810457
Pipeline #20044 passed with stage
in 6 minutes and 10 seconds
......@@ -894,5 +894,6 @@
assert repo.filtername is None
data = repo.cachevfs.tryread(self._filepath)
self._cachekey = self.emptykey
self._index = array.array(r'l')
self._data = array.array(r'l')
......@@ -897,6 +898,4 @@
self._index = array.array(r'l')
self._data = array.array(r'l')
if not data:
self._cachekey = self.emptykey
else:
if data:
headerdata = data[:self._cachekeysize]
......@@ -902,6 +901,6 @@
headerdata = data[:self._cachekeysize]
self._cachekey = self._deserializecachekey(headerdata)
cachekey = self._deserializecachekey(headerdata)
offset = self._cachekeysize
indexsizedata = data[offset:offset + S_INDEXSIZE.size]
indexsize = S_INDEXSIZE.unpack(indexsizedata)[0]
offset += S_INDEXSIZE.size
......@@ -904,10 +903,22 @@
offset = self._cachekeysize
indexsizedata = data[offset:offset + S_INDEXSIZE.size]
indexsize = S_INDEXSIZE.unpack(indexsizedata)[0]
offset += S_INDEXSIZE.size
compat.arrayfrombytes(self._index, data[offset:offset + indexsize])
offset += indexsize
compat.arrayfrombytes(self._data, data[offset:])
if len(data) - offset >= indexsize:
index = list(self._deserializedata(data[offset:offset + indexsize]))
offset += indexsize
expected = index[-1] * self._datastruct.size * 3
data = data[offset:]
else:
# index cannot be read, so we need to abort somehow
expected = None
if len(data) == expected:
self._index.extend(index)
self._data.extend(self._deserializedata(data))
self._cachekey = cachekey
else:
repo.ui.debug(b'stablesortcache file seems to be corrupted, '
b'it will be rebuilt from scratch\n')
self._ondiskkey = self._cachekey
pass
......@@ -923,8 +934,8 @@
# data to write
headerdata = self._serializecachekey()
indexdata = compat.arraytobytes(self._index)
data = compat.arraytobytes(self._data)
indexdata = self._serializedata(self._index)
data = self._serializedata(self._data)
indexsize = S_INDEXSIZE.pack(len(indexdata))
# writing
......
......@@ -336,3 +336,19 @@
number of revisions: 8
number of merge: 0
number of jumps: 0
$ "$PYTHON" truncate.py main/.hg/cache/evoext-stablesortcache-00 -4
$ f -H main/.hg/cache/evoext-stablesortcache-00
main/.hg/cache/evoext-stablesortcache-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 00 00 00 40 00 00 00 00 |A'z...Q....@....|
0020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
0030: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
0040: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
0050: 00 00 00 00 00 00 00 00 |........|
$ hg -R main debugstablesortcache --debug
number of revisions: 8
stablesortcache file seems to be corrupted, it will be rebuilt from scratch
number of merge: 0
number of jumps: 0
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment