packentry() currently accepts tuples. Let's pass in index entry types
instead.
The censor extension was calling into this low-level code. It has
been refactored to use our new type and to look up fields in index
entries by name instead of offset.
durin42 |
hg-reviewers |
packentry() currently accepts tuples. Let's pass in index entry types
instead.
The censor extension was calling into this low-level code. It has
been refactored to use our new type and to look up fields in index
entries by name instead of offset.
Lint Skipped |
Unit Tests Skipped |
Path | Packages | |||
---|---|---|---|---|
M | hgext/censor.py (17 lines) | |||
M | mercurial/revlog.py (17 lines) |
Status | Author | Revision | |
---|---|---|---|
Accepted | indygreg | ||
Accepted | indygreg | ||
Accepted | indygreg | ||
Accepted | indygreg | ||
Accepted | indygreg | ||
Accepted | indygreg | ||
Accepted | indygreg | ||
Accepted | indygreg | ||
Accepted | indygreg | ||
Accepted | indygreg | ||
Needs Revision | indygreg | ||
Needs Revision | indygreg | ||
Needs Revision | indygreg | ||
Accepted | indygreg | ||
Needs Revision | indygreg | ||
Closed | indygreg |
from mercurial.i18n import _ | from mercurial.i18n import _ | ||||
from mercurial.node import short | from mercurial.node import short | ||||
from mercurial import ( | from mercurial import ( | ||||
error, | error, | ||||
filelog, | filelog, | ||||
lock as lockmod, | lock as lockmod, | ||||
policy, | |||||
registrar, | registrar, | ||||
revlog, | revlog, | ||||
scmutil, | scmutil, | ||||
util, | util, | ||||
) | ) | ||||
parsers = policy.importmod(r'parsers') | |||||
cmdtable = {} | cmdtable = {} | ||||
command = registrar.command(cmdtable) | command = registrar.command(cmdtable) | ||||
# Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for | # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for | ||||
# extensions which SHIP WITH MERCURIAL. Non-mainline extensions should | # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should | ||||
# be specifying the version(s) of Mercurial they are tested with, or | # be specifying the version(s) of Mercurial they are tested with, or | ||||
# leave the attribute unspecified. | # leave the attribute unspecified. | ||||
testedwith = 'ships-with-hg-core' | testedwith = 'ships-with-hg-core' | ||||
datawrite.write(chunk) | datawrite.write(chunk) | ||||
def rewriteindex(r, newoffs, newdata=None): | def rewriteindex(r, newoffs, newdata=None): | ||||
"""Rewrite the index entry with a new data offset and optional new data. | """Rewrite the index entry with a new data offset and optional new data. | ||||
The newdata argument, if given, is a tuple of three positive integers: | The newdata argument, if given, is a tuple of three positive integers: | ||||
(new compressed, new uncompressed, added flag bits). | (new compressed, new uncompressed, added flag bits). | ||||
""" | """ | ||||
offlags, comp, uncomp, base, link, p1, p2, nodeid = flog.index[r] | idx = flog.index[r] | ||||
flags = revlog.gettype(offlags) | flags = revlog.gettype(idx.offsetflags) | ||||
comp = idx.chunklength | |||||
uncomp = idx.rawlength | |||||
if newdata: | if newdata: | ||||
comp, uncomp, nflags = newdata | comp, uncomp, nflags = newdata | ||||
flags |= nflags | flags |= nflags | ||||
offlags = revlog.offset_type(newoffs, flags) | offlags = revlog.offset_type(newoffs, flags) | ||||
e = (offlags, comp, uncomp, r, link, p1, p2, nodeid) | entry = parsers.IndexV1Entry(offlags, comp, uncomp, r, | ||||
idxwrite.write(rio.packentry(e, None, flog.version, r)) | idx.linkrev, idx.p1rev, idx.p2rev, | ||||
idx.node) | |||||
idxwrite.write(rio.packentry(entry, None, flog.version, r)) | |||||
idxread.seek(rio.size, 1) | idxread.seek(rio.size, 1) | ||||
def rewrite(r, offs, data, nflags=revlog.REVIDX_DEFAULT_FLAGS): | def rewrite(r, offs, data, nflags=revlog.REVIDX_DEFAULT_FLAGS): | ||||
"""Write the given full text to the filelog with the given data offset. | """Write the given full text to the filelog with the given data offset. | ||||
Returns: | Returns: | ||||
The integer number of data bytes written, for tracking data offsets. | The integer number of data bytes written, for tracking data offsets. | ||||
""" | """ |
n += 1 | n += 1 | ||||
# add the magic null revision at -1 | # add the magic null revision at -1 | ||||
index.append(parsers.IndexV1Entry(0, 0, 0, -1, -1, -1, -1, nullid)) | index.append(parsers.IndexV1Entry(0, 0, 0, -1, -1, -1, -1, nullid)) | ||||
return index, nodemap, None | return index, nodemap, None | ||||
def packentry(self, entry, node, version, rev): | def packentry(self, entry, node, version, rev): | ||||
if gettype(entry[0]): | if gettype(entry.offsetflags): | ||||
raise RevlogError(_('index entry flags need revlog version 1')) | raise RevlogError(_('index entry flags need revlog version 1')) | ||||
e2 = (getoffset(entry[0]), entry[1], entry[3], entry[4], | return indexformatv0_pack(entry.offsetflags, entry.chunklength, | ||||
node(entry[5]), node(entry[6]), entry[7]) | entry.baserev, entry.linkrev, | ||||
return indexformatv0_pack(*e2) | node(entry.p1rev), node(entry.p2rev), | ||||
entry.node) | |||||
# index ng: | # index ng: | ||||
# 6 bytes: offset | # 6 bytes: offset | ||||
# 2 bytes: flags | # 2 bytes: flags | ||||
# 4 bytes: compressed length | # 4 bytes: compressed length | ||||
# 4 bytes: uncompressed length | # 4 bytes: uncompressed length | ||||
# 4 bytes: base rev | # 4 bytes: base rev | ||||
# 4 bytes: link rev | # 4 bytes: link rev | ||||
self.size = indexformatng.size | self.size = indexformatng.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, getattr(index, 'nodemap', None), cache | return index, getattr(index, 'nodemap', None), cache | ||||
def packentry(self, entry, node, version, rev): | def packentry(self, entry, node, version, rev): | ||||
p = indexformatng_pack(*entry) | p = indexformatng_pack(entry.offsetflags, entry.chunklength, | ||||
entry.rawlength, entry.baserev, entry.linkrev, | |||||
entry.p1rev, entry.p2rev, entry.node) | |||||
if rev == 0: | if rev == 0: | ||||
p = versionformat_pack(version) + p[4:] | p = versionformat_pack(version) + p[4:] | ||||
return p | return p | ||||
class revlog(object): | class revlog(object): | ||||
""" | """ | ||||
the underlying revision storage object | the underlying revision storage object | ||||
if delta is not None: | if delta is not None: | ||||
dist, l, data, base, chainbase, chainlen, compresseddeltalen = delta | dist, l, data, base, chainbase, chainlen, compresseddeltalen = delta | ||||
else: | else: | ||||
rawtext = buildtext() | rawtext = buildtext() | ||||
data = self.compress(rawtext) | data = self.compress(rawtext) | ||||
l = len(data[1]) + len(data[0]) | l = len(data[1]) + len(data[0]) | ||||
base = chainbase = curr | base = chainbase = curr | ||||
e = (offset_type(offset, flags), l, textlen, | e = parsers.IndexV1Entry(offset_type(offset, flags), l, textlen, | ||||
base, link, p1r, p2r, node) | base, link, p1r, p2r, node) | ||||
self.index.insert(-1, e) | self.index.insert(-1, e) | ||||
self.nodemap[node] = curr | self.nodemap[node] = curr | ||||
entry = self._io.packentry(e, self.node, self.version, curr) | entry = self._io.packentry(e, self.node, self.version, curr) | ||||
self._writeentry(transaction, ifh, dfh, entry, data, link, offset) | self._writeentry(transaction, ifh, dfh, entry, data, link, offset) | ||||
if alwayscache and rawtext is None: | if alwayscache and rawtext is None: | ||||
rawtext = buildtext() | rawtext = buildtext() |