Mercurial > public > mercurial-scm > hg-stable
diff mercurial/utils/storageutil.py @ 40325:b0fbd1792e2d
storageutil: extract most of peek_censored from revlog
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.
Differential Revision: https://phab.mercurial-scm.org/D5118
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Tue, 16 Oct 2018 15:36:19 +0200 |
parents | 6994a8be3663 |
children | 634b45317459 59a870a4ad6e |
line wrap: on
line diff
--- a/mercurial/utils/storageutil.py Thu Sep 20 17:27:01 2018 -0700 +++ b/mercurial/utils/storageutil.py Tue Oct 16 15:36:19 2018 +0200 @@ -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