Mercurial > public > mercurial-scm > hg-stable
comparison 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 |
comparison
equal
deleted
inserted
replaced
40324:6637b079ae45 | 40325:b0fbd1792e2d |
---|---|
7 | 7 |
8 from __future__ import absolute_import | 8 from __future__ import absolute_import |
9 | 9 |
10 import hashlib | 10 import hashlib |
11 import re | 11 import re |
12 import struct | |
12 | 13 |
13 from ..i18n import _ | 14 from ..i18n import _ |
14 from ..node import ( | 15 from ..node import ( |
15 bin, | 16 bin, |
16 nullid, | 17 nullid, |
447 baserevisionsize=baserevisionsize, | 448 baserevisionsize=baserevisionsize, |
448 revision=revision, | 449 revision=revision, |
449 delta=delta) | 450 delta=delta) |
450 | 451 |
451 prevrev = rev | 452 prevrev = rev |
453 | |
454 def deltaiscensored(delta, baserev, baselenfn): | |
455 """Determine if a delta represents censored revision data. | |
456 | |
457 ``baserev`` is the base revision this delta is encoded against. | |
458 ``baselenfn`` is a callable receiving a revision number that resolves the | |
459 length of the revision fulltext. | |
460 | |
461 Returns a bool indicating if the result of the delta represents a censored | |
462 revision. | |
463 """ | |
464 # Fragile heuristic: unless new file meta keys are added alphabetically | |
465 # preceding "censored", all censored revisions are prefixed by | |
466 # "\1\ncensored:". A delta producing such a censored revision must be a | |
467 # full-replacement delta, so we inspect the first and only patch in the | |
468 # delta for this prefix. | |
469 hlen = struct.calcsize(">lll") | |
470 if len(delta) <= hlen: | |
471 return False | |
472 | |
473 oldlen = baselenfn(baserev) | |
474 newlen = len(delta) - hlen | |
475 if delta[:hlen] != mdiff.replacediffheader(oldlen, newlen): | |
476 return False | |
477 | |
478 add = "\1\ncensored:" | |
479 addlen = len(add) | |
480 return newlen >= addlen and delta[hlen:hlen + addlen] == add |