The struct was previous called "version", but this is actually "version" +
"flags". So header seems like a better name.
The move to the constants module has the same motivation as the INDEX_ENTRY_V#
ones.
| indygreg | |
| Alphare | |
| pulkit | 
| hg-reviewers | 
The struct was previous called "version", but this is actually "version" +
"flags". So header seems like a better name.
The move to the constants module has the same motivation as the INDEX_ENTRY_V#
ones.
| Automatic diff as part of commit; lint not applicable. | 
| Automatic diff as part of commit; unit tests not applicable. | 
| Path | Packages | |||
|---|---|---|---|---|
| M | mercurial/revlog.py (11 lines) | |||
| M | mercurial/revlogutils/constants.py (2 lines) | 
| from .i18n import _ | from .i18n import _ | ||||
| from .pycompat import getattr | from .pycompat import getattr | ||||
| from .revlogutils.constants import ( | from .revlogutils.constants import ( | ||||
| FLAG_GENERALDELTA, | FLAG_GENERALDELTA, | ||||
| FLAG_INLINE_DATA, | FLAG_INLINE_DATA, | ||||
| INDEX_ENTRY_V0, | INDEX_ENTRY_V0, | ||||
| INDEX_ENTRY_V1, | INDEX_ENTRY_V1, | ||||
| INDEX_ENTRY_V2, | INDEX_ENTRY_V2, | ||||
| INDEX_HEADER, | |||||
| REVLOGV0, | REVLOGV0, | ||||
| REVLOGV1, | REVLOGV1, | ||||
| REVLOGV1_FLAGS, | REVLOGV1_FLAGS, | ||||
| REVLOGV2, | REVLOGV2, | ||||
| REVLOGV2_FLAGS, | REVLOGV2_FLAGS, | ||||
| REVLOG_DEFAULT_FLAGS, | REVLOG_DEFAULT_FLAGS, | ||||
| REVLOG_DEFAULT_FORMAT, | REVLOG_DEFAULT_FORMAT, | ||||
| REVLOG_DEFAULT_VERSION, | REVLOG_DEFAULT_VERSION, | ||||
| entry[4], | entry[4], | ||||
| node(entry[5]), | node(entry[5]), | ||||
| node(entry[6]), | node(entry[6]), | ||||
| entry[7], | entry[7], | ||||
| ) | ) | ||||
| return INDEX_ENTRY_V0.pack(*e2) | return INDEX_ENTRY_V0.pack(*e2) | ||||
| versionformat = struct.Struct(b">I") | |||||
| versionformat_pack = versionformat.pack | |||||
| versionformat_unpack = versionformat.unpack | |||||
| # corresponds to uncompressed length of indexformatng (2 gigs, 4-byte | # corresponds to uncompressed length of indexformatng (2 gigs, 4-byte | ||||
| # signed integer) | # signed integer) | ||||
| _maxentrysize = 0x7FFFFFFF | _maxentrysize = 0x7FFFFFFF | ||||
| class revlogio(object): | class revlogio(object): | ||||
| def __init__(self): | def __init__(self): | ||||
| self.size = INDEX_ENTRY_V1.size | self.size = INDEX_ENTRY_V1.size | ||||
| def parseindex(self, data, inline): | def parseindex(self, data, inline): | ||||
| # call the C implementation to parse the index data | # call the C implementation to parse the index data | ||||
| index, cache = parsers.parse_index2(data, inline) | index, cache = parsers.parse_index2(data, inline) | ||||
| return index, cache | return index, cache | ||||
| def packentry(self, entry, node, version, rev): | def packentry(self, entry, node, version, rev): | ||||
| p = INDEX_ENTRY_V1.pack(*entry) | p = INDEX_ENTRY_V1.pack(*entry) | ||||
| if rev == 0: | if rev == 0: | ||||
| p = versionformat_pack(version) + p[4:] | p = INDEX_HEADER.pack(version) + p[4:] | ||||
| return p | return p | ||||
| class revlogv2io(object): | class revlogv2io(object): | ||||
| def __init__(self): | def __init__(self): | ||||
| self.size = INDEX_ENTRY_V2.size | self.size = INDEX_ENTRY_V2.size | ||||
| def parseindex(self, data, inline): | def parseindex(self, data, inline): | ||||
| index, cache = parsers.parse_index2(data, inline, revlogv2=True) | index, cache = parsers.parse_index2(data, inline, revlogv2=True) | ||||
| return index, cache | return index, cache | ||||
| def packentry(self, entry, node, version, rev): | def packentry(self, entry, node, version, rev): | ||||
| p = INDEX_ENTRY_V2.pack(*entry) | p = INDEX_ENTRY_V2.pack(*entry) | ||||
| if rev == 0: | if rev == 0: | ||||
| p = versionformat_pack(version) + p[4:] | p = INDEX_HEADER.pack(version) + p[4:] | ||||
| return p | return p | ||||
| NodemapRevlogIO = None | NodemapRevlogIO = None | ||||
| if util.safehasattr(parsers, 'parse_index_devel_nodemap'): | if util.safehasattr(parsers, 'parse_index_devel_nodemap'): | ||||
| class NodemapRevlogIO(revlogio): | class NodemapRevlogIO(revlogio): | ||||
| and self.opener.fstat(f).st_size >= mmapindexthreshold | and self.opener.fstat(f).st_size >= mmapindexthreshold | ||||
| ): | ): | ||||
| # TODO: should .close() to release resources without | # TODO: should .close() to release resources without | ||||
| # relying on Python GC | # relying on Python GC | ||||
| indexdata = util.buffer(util.mmapread(f)) | indexdata = util.buffer(util.mmapread(f)) | ||||
| else: | else: | ||||
| indexdata = f.read() | indexdata = f.read() | ||||
| if len(indexdata) > 0: | if len(indexdata) > 0: | ||||
| versionflags = versionformat_unpack(indexdata[:4])[0] | versionflags = INDEX_HEADER.unpack(indexdata[:4])[0] | ||||
| self._initempty = False | self._initempty = False | ||||
| else: | else: | ||||
| versionflags = newversionflags | versionflags = newversionflags | ||||
| except IOError as inst: | except IOError as inst: | ||||
| if inst.errno != errno.ENOENT: | if inst.errno != errno.ENOENT: | ||||
| raise | raise | ||||
| versionflags = newversionflags | versionflags = newversionflags | ||||
| from __future__ import absolute_import | from __future__ import absolute_import | ||||
| import struct | import struct | ||||
| from ..interfaces import repository | from ..interfaces import repository | ||||
| ### main revlog header | ### main revlog header | ||||
| INDEX_HEADER = struct.Struct(b">I") | |||||
| ## revlog version | ## revlog version | ||||
| REVLOGV0 = 0 | REVLOGV0 = 0 | ||||
| REVLOGV1 = 1 | REVLOGV1 = 1 | ||||
| # Dummy value until file format is finalized. | # Dummy value until file format is finalized. | ||||
| REVLOGV2 = 0xDEAD | REVLOGV2 = 0xDEAD | ||||
| ## global revlog header flags | ## global revlog header flags | ||||
| # Shared across v1 and v2. | # Shared across v1 and v2. | ||||