marmoute created this revision. Herald added a reviewer: indygreg. Herald added a reviewer: hg-reviewers. Herald added a subscriber: mercurial-patches.
REVISION SUMMARY 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. REPOSITORY rHG Mercurial BRANCH default REVISION DETAIL https://phab.mercurial-scm.org/D10303 AFFECTED FILES mercurial/revlog.py mercurial/revlogutils/constants.py CHANGE DETAILS diff --git a/mercurial/revlogutils/constants.py b/mercurial/revlogutils/constants.py --- a/mercurial/revlogutils/constants.py +++ b/mercurial/revlogutils/constants.py @@ -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 diff --git a/mercurial/revlog.py b/mercurial/revlog.py --- a/mercurial/revlog.py +++ b/mercurial/revlog.py @@ -40,6 +40,7 @@ from .revlogutils.constants import ( FLAG_GENERALDELTA, FLAG_INLINE_DATA, + INDEX_ENTRY_V0, REVLOGV0, REVLOGV1, REVLOGV1_FLAGS, @@ -217,19 +218,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): @@ -283,7 +271,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 @@ -294,7 +282,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), @@ -314,6 +302,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') @@ -327,7 +322,7 @@ node(entry[6]), entry[7], ) - return indexformatv0_pack(*e2) + return INDEX_ENTRY_V0.pack(*e2) # index ng: To: marmoute, indygreg, #hg-reviewers Cc: mercurial-patches, mercurial-devel _______________________________________________ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel