This function is super hacky and isn't correct 100% of the time. I'm going
to need this functionality on a future non-revlog store.
Let's copy things to storageutil so this code only exists once.
hg-reviewers |
This function is super hacky and isn't correct 100% of the time. I'm going
to need this functionality on a future non-revlog store.
Let's copy things to storageutil so this code only exists once.
Lint Skipped |
Unit Tests Skipped |
Path | Packages | |||
---|---|---|---|---|
M | mercurial/revlog.py (18 lines) | |||
M | mercurial/utils/storageutil.py (29 lines) |
Commit | Parents | Author | Summary | Date |
---|---|---|---|---|
Gregory Szorc | Oct 16 2018, 9:36 AM |
return self.flags(rev) & REVIDX_ISCENSORED | return self.flags(rev) & REVIDX_ISCENSORED | ||||
def _peek_iscensored(self, baserev, delta, flush): | def _peek_iscensored(self, baserev, delta, flush): | ||||
"""Quickly check if a delta produces a censored revision.""" | """Quickly check if a delta produces a censored revision.""" | ||||
if not self._censorable: | if not self._censorable: | ||||
return False | return False | ||||
# Fragile heuristic: unless new file meta keys are added alphabetically | return storageutil.deltaiscensored(delta, baserev, self.rawsize) | ||||
# preceding "censored", all censored revisions are prefixed by | |||||
# "\1\ncensored:". A delta producing such a censored revision must be a | |||||
# full-replacement delta, so we inspect the first and only patch in the | |||||
# delta for this prefix. | |||||
hlen = struct.calcsize(">lll") | |||||
if len(delta) <= hlen: | |||||
return False | |||||
oldlen = self.rawsize(baserev) | |||||
newlen = len(delta) - hlen | |||||
if delta[:hlen] != mdiff.replacediffheader(oldlen, newlen): | |||||
return False | |||||
add = "\1\ncensored:" | |||||
addlen = len(add) | |||||
return newlen >= addlen and delta[hlen:hlen + addlen] == add | |||||
def getstrippoint(self, minlink): | def getstrippoint(self, minlink): | ||||
"""find the minimum rev that must be stripped to strip the linkrev | """find the minimum rev that must be stripped to strip the linkrev | ||||
Returns a tuple containing the minimum rev and a set of all revs that | Returns a tuple containing the minimum rev and a set of all revs that | ||||
have linkrevs that will be broken by this strip. | have linkrevs that will be broken by this strip. | ||||
""" | """ | ||||
return storageutil.resolvestripinfo(minlink, len(self) - 1, | return storageutil.resolvestripinfo(minlink, len(self) - 1, |
# storageutil.py - Storage functionality agnostic of backend implementation. | # storageutil.py - Storage functionality agnostic of backend implementation. | ||||
# | # | ||||
# Copyright 2018 Gregory Szorc <gregory.szorc@gmail.com> | # Copyright 2018 Gregory Szorc <gregory.szorc@gmail.com> | ||||
# | # | ||||
# This software may be used and distributed according to the terms of the | # This software may be used and distributed according to the terms of the | ||||
# GNU General Public License version 2 or any later version. | # GNU General Public License version 2 or any later version. | ||||
from __future__ import absolute_import | from __future__ import absolute_import | ||||
import hashlib | import hashlib | ||||
import re | import re | ||||
import struct | |||||
from ..i18n import _ | from ..i18n import _ | ||||
from ..node import ( | from ..node import ( | ||||
bin, | bin, | ||||
nullid, | nullid, | ||||
nullrev, | nullrev, | ||||
) | ) | ||||
from .. import ( | from .. import ( | ||||
p2node=fnode(p2rev), | p2node=fnode(p2rev), | ||||
basenode=fnode(baserev), | basenode=fnode(baserev), | ||||
flags=flagsfn(rev) if flagsfn else 0, | flags=flagsfn(rev) if flagsfn else 0, | ||||
baserevisionsize=baserevisionsize, | baserevisionsize=baserevisionsize, | ||||
revision=revision, | revision=revision, | ||||
delta=delta) | delta=delta) | ||||
prevrev = rev | prevrev = rev | ||||
def deltaiscensored(delta, baserev, baselenfn): | |||||
"""Determine if a delta represents censored revision data. | |||||
``baserev`` is the base revision this delta is encoded against. | |||||
``baselenfn`` is a callable receiving a revision number that resolves the | |||||
length of the revision fulltext. | |||||
Returns a bool indicating if the result of the delta represents a censored | |||||
revision. | |||||
""" | |||||
# Fragile heuristic: unless new file meta keys are added alphabetically | |||||
# preceding "censored", all censored revisions are prefixed by | |||||
# "\1\ncensored:". A delta producing such a censored revision must be a | |||||
# full-replacement delta, so we inspect the first and only patch in the | |||||
# delta for this prefix. | |||||
hlen = struct.calcsize(">lll") | |||||
if len(delta) <= hlen: | |||||
return False | |||||
oldlen = baselenfn(baserev) | |||||
newlen = len(delta) - hlen | |||||
if delta[:hlen] != mdiff.replacediffheader(oldlen, newlen): | |||||
return False | |||||
add = "\1\ncensored:" | |||||
addlen = len(add) | |||||
return newlen >= addlen and delta[hlen:hlen + addlen] == add |