# HG changeset patch # User Pierre-Yves David # Date 1617618052 -7200 # Node ID 34e1fa4b548aedabaea646a918cba471f5266484 # Parent aba724bf550e69ea6ed1fa5aec2680dcacc86941 revlog: move the details of revlog "v0" index inside revlog.utils.constants the revlog module is quite large and this kind of format information would handy for other module. So let us start to gather this information about the format in a more appropriate place. Differential Revision: https://phab.mercurial-scm.org/D10303 diff -r aba724bf550e -r 34e1fa4b548a mercurial/revlog.py --- a/mercurial/revlog.py Mon Apr 05 12:20:40 2021 +0200 +++ b/mercurial/revlog.py Mon Apr 05 12:20:52 2021 +0200 @@ -41,6 +41,7 @@ from .revlogutils.constants import ( FLAG_GENERALDELTA, FLAG_INLINE_DATA, + INDEX_ENTRY_V0, REVLOGV0, REVLOGV1, REVLOGV1_FLAGS, @@ -218,19 +219,6 @@ node = attr.ib(default=None) -# index v0: -# 4 bytes: offset -# 4 bytes: compressed length -# 4 bytes: base rev -# 4 bytes: link rev -# 20 bytes: parent 1 nodeid -# 20 bytes: parent 2 nodeid -# 20 bytes: nodeid -indexformatv0 = struct.Struct(b">4l20s20s20s") -indexformatv0_pack = indexformatv0.pack -indexformatv0_unpack = indexformatv0.unpack - - class revlogoldindex(list): @property def nodemap(self): @@ -284,7 +272,7 @@ class revlogoldio(object): def __init__(self): - self.size = indexformatv0.size + self.size = INDEX_ENTRY_V0.size def parseindex(self, data, inline): s = self.size @@ -295,7 +283,7 @@ while off + s <= l: cur = data[off : off + s] off += s - e = indexformatv0_unpack(cur) + e = INDEX_ENTRY_V0.unpack(cur) # transform to revlogv1 format e2 = ( offset_type(e[0], 0), @@ -315,6 +303,13 @@ return index, None def packentry(self, entry, node, version, rev): + """return the binary representation of an entry + + entry: a tuple containing all the values (see index.__getitem__) + node: a callback to convert a revision to nodeid + version: the changelog version + rev: the revision number + """ if gettype(entry[0]): raise error.RevlogError( _(b'index entry flags need revlog version 1') @@ -328,7 +323,7 @@ node(entry[6]), entry[7], ) - return indexformatv0_pack(*e2) + return INDEX_ENTRY_V0.pack(*e2) # index ng: diff -r aba724bf550e -r 34e1fa4b548a mercurial/revlogutils/constants.py --- a/mercurial/revlogutils/constants.py Mon Apr 05 12:20:40 2021 +0200 +++ b/mercurial/revlogutils/constants.py Mon Apr 05 12:20:52 2021 +0200 @@ -9,6 +9,8 @@ from __future__ import absolute_import +import struct + from ..interfaces import repository ### main revlog header @@ -32,6 +34,16 @@ ### individual entry +## index v0: +# 4 bytes: offset +# 4 bytes: compressed length +# 4 bytes: base rev +# 4 bytes: link rev +# 20 bytes: parent 1 nodeid +# 20 bytes: parent 2 nodeid +# 20 bytes: nodeid +INDEX_ENTRY_V0 = struct.Struct(b">4l20s20s20s") + # revlog index flags # For historical reasons, revlog's internal flags were exposed via the