--- a/contrib/perf.py Sat May 01 14:47:33 2021 +0200
+++ b/contrib/perf.py Sat May 01 14:47:39 2021 +0200
@@ -2598,11 +2598,14 @@
header = struct.unpack(b'>I', data[0:4])[0]
version = header & 0xFFFF
if version == 1:
- revlogio = revlog.revlogio()
inline = header & (1 << 16)
else:
raise error.Abort(b'unsupported revlog version: %d' % version)
+ parse_index_v1 = getattr(revlog, 'parse_index_v1', None)
+ if parse_index_v1 is None:
+ parse_index_v1 = revlog.revlogio().parseindex
+
rllen = len(rl)
node0 = rl.node(0)
@@ -2624,26 +2627,24 @@
fh.read()
def parseindex():
- revlogio.parseindex(data, inline)
+ parse_index_v1(data, inline)
def getentry(revornode):
- index = revlogio.parseindex(data, inline)[0]
+ index = parse_index_v1(data, inline)[0]
index[revornode]
def getentries(revs, count=1):
- index = revlogio.parseindex(data, inline)[0]
+ index = parse_index_v1(data, inline)[0]
for i in range(count):
for rev in revs:
index[rev]
def resolvenode(node):
- index = revlogio.parseindex(data, inline)[0]
+ index = parse_index_v1(data, inline)[0]
rev = getattr(index, 'rev', None)
if rev is None:
- nodemap = getattr(
- revlogio.parseindex(data, inline)[0], 'nodemap', None
- )
+ nodemap = getattr(parse_index_v1(data, inline)[0], 'nodemap', None)
# This only works for the C code.
if nodemap is None:
return
@@ -2655,12 +2656,10 @@
pass
def resolvenodes(nodes, count=1):
- index = revlogio.parseindex(data, inline)[0]
+ index = parse_index_v1(data, inline)[0]
rev = getattr(index, 'rev', None)
if rev is None:
- nodemap = getattr(
- revlogio.parseindex(data, inline)[0], 'nodemap', None
- )
+ nodemap = getattr(parse_index_v1(data, inline)[0], 'nodemap', None)
# This only works for the C code.
if nodemap is None:
return
--- a/mercurial/revlog.py Sat May 01 14:47:33 2021 +0200
+++ b/mercurial/revlog.py Sat May 01 14:47:39 2021 +0200
@@ -37,8 +37,6 @@
FLAG_GENERALDELTA,
FLAG_INLINE_DATA,
INDEX_ENTRY_V0,
- INDEX_ENTRY_V1,
- INDEX_ENTRY_V2,
INDEX_HEADER,
REVLOGV0,
REVLOGV1,
@@ -287,34 +285,61 @@
return INDEX_ENTRY_V0.pack(*e2)
-class revlogoldio(object):
- def parseindex(self, data, inline):
- s = INDEX_ENTRY_V0.size
- index = []
- nodemap = nodemaputil.NodeMap({sha1nodeconstants.nullid: nullrev})
- n = off = 0
- l = len(data)
- while off + s <= l:
- cur = data[off : off + s]
- off += s
- e = INDEX_ENTRY_V0.unpack(cur)
- # transform to revlogv1 format
- e2 = (
- offset_type(e[0], 0),
- e[1],
- -1,
- e[2],
- e[3],
- nodemap.get(e[4], nullrev),
- nodemap.get(e[5], nullrev),
- e[6],
- )
- index.append(e2)
- nodemap[e[6]] = n
- n += 1
-
- index = revlogoldindex(index)
- return index, None
+def parse_index_v0(data, inline):
+ s = INDEX_ENTRY_V0.size
+ index = []
+ nodemap = nodemaputil.NodeMap({sha1nodeconstants.nullid: nullrev})
+ n = off = 0
+ l = len(data)
+ while off + s <= l:
+ cur = data[off : off + s]
+ off += s
+ e = INDEX_ENTRY_V0.unpack(cur)
+ # transform to revlogv1 format
+ e2 = (
+ offset_type(e[0], 0),
+ e[1],
+ -1,
+ e[2],
+ e[3],
+ nodemap.get(e[4], nullrev),
+ nodemap.get(e[5], nullrev),
+ e[6],
+ )
+ index.append(e2)
+ nodemap[e[6]] = n
+ n += 1
+
+ index = revlogoldindex(index)
+ return index, None
+
+
+def parse_index_v1(data, inline):
+ # call the C implementation to parse the index data
+ index, cache = parsers.parse_index2(data, inline)
+ return index, cache
+
+
+def parse_index_v2(data, inline):
+ # call the C implementation to parse the index data
+ index, cache = parsers.parse_index2(data, inline, revlogv2=True)
+ return index, cache
+
+
+if util.safehasattr(parsers, 'parse_index_devel_nodemap'):
+
+ def parse_index_v1_nodemap(data, inline):
+ index, cache = parsers.parse_index_devel_nodemap(data, inline)
+ return index, cache
+
+
+else:
+ parse_index_v1_nodemap = None
+
+
+def parse_index_v1_mixed(data, inline):
+ index, cache = parse_index_v1(data, inline)
+ return rustrevlog.MixedIndex(index), cache
# corresponds to uncompressed length of indexformatng (2 gigs, 4-byte
@@ -322,40 +347,6 @@
_maxentrysize = 0x7FFFFFFF
-class revlogio(object):
- def parseindex(self, data, inline):
- # call the C implementation to parse the index data
- index, cache = parsers.parse_index2(data, inline)
- return index, cache
-
-
-class revlogv2io(object):
- def parseindex(self, data, inline):
- index, cache = parsers.parse_index2(data, inline, revlogv2=True)
- return index, cache
-
-
-NodemapRevlogIO = None
-
-if util.safehasattr(parsers, 'parse_index_devel_nodemap'):
-
- class NodemapRevlogIO(revlogio):
- """A debug oriented IO class that return a PersistentNodeMapIndexObject
-
- The PersistentNodeMapIndexObject object is meant to test the persistent nodemap feature.
- """
-
- def parseindex(self, data, inline):
- index, cache = parsers.parse_index_devel_nodemap(data, inline)
- return index, cache
-
-
-class rustrevlogio(revlogio):
- def parseindex(self, data, inline):
- index, cache = super(rustrevlogio, self).parseindex(data, inline)
- return rustrevlog.MixedIndex(index), cache
-
-
class revlog(object):
"""
the underlying revision storage object
@@ -614,7 +605,7 @@
devel_nodemap = (
self.nodemap_file
and opts.get(b'devel-force-nodemap', False)
- and NodemapRevlogIO is not None
+ and parse_index_v1_nodemap is not None
)
use_rust_index = False
@@ -624,17 +615,17 @@
else:
use_rust_index = self.opener.options.get(b'rust.index')
- self._io = revlogio()
+ self._parse_index = parse_index_v1
if self.version == REVLOGV0:
- self._io = revlogoldio()
+ self._parse_index = parse_index_v0
elif fmt == REVLOGV2:
- self._io = revlogv2io()
+ self._parse_index = parse_index_v2
elif devel_nodemap:
- self._io = NodemapRevlogIO()
+ self._parse_index = parse_index_v1_nodemap
elif use_rust_index:
- self._io = rustrevlogio()
+ self._parse_index = parse_index_v1_mixed
try:
- d = self._io.parseindex(indexdata, self._inline)
+ d = self._parse_index(indexdata, self._inline)
index, _chunkcache = d
use_nodemap = (
not self._inline
@@ -2049,7 +2040,6 @@
with self._indexfp(b'w') as fp:
self.version &= ~FLAG_INLINE_DATA
self._inline = False
- io = self._io
for i in self:
e = self.index.entry_binary(i, self.version)
fp.write(e)
@@ -2984,7 +2974,7 @@
newrl = revlog(self.opener, newindexfile, newdatafile, censorable=True)
newrl.version = self.version
newrl._generaldelta = self._generaldelta
- newrl._io = self._io
+ newrl._parse_index = self._parse_index
for rev in self.revs():
node = self.node(rev)