This revision was automatically updated to reflect the committed changes. Closed by commit rHGb0fbd1792e2d: storageutil: extract most of peek_censored from revlog (authored by indygreg, committed by ).
REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D5118?vs=12166&id=12199 REVISION DETAIL https://phab.mercurial-scm.org/D5118 AFFECTED FILES mercurial/revlog.py mercurial/utils/storageutil.py CHANGE DETAILS diff --git a/mercurial/utils/storageutil.py b/mercurial/utils/storageutil.py --- a/mercurial/utils/storageutil.py +++ b/mercurial/utils/storageutil.py @@ -9,6 +9,7 @@ import hashlib import re +import struct from ..i18n import _ from ..node import ( @@ -449,3 +450,31 @@ delta=delta) 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 diff --git a/mercurial/revlog.py b/mercurial/revlog.py --- a/mercurial/revlog.py +++ b/mercurial/revlog.py @@ -2109,23 +2109,7 @@ if not self._censorable: return False - # 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 = 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 + return storageutil.deltaiscensored(delta, baserev, self.rawsize) def getstrippoint(self, minlink): """find the minimum rev that must be stripped to strip the linkrev To: indygreg, #hg-reviewers Cc: mercurial-devel _______________________________________________ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel