Mercurial > public > mercurial-scm > hg
comparison mercurial/revlog.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 | 9cadb0f5f227 |
children | 59a870a4ad6e 256b1f0c24e8 |
comparison
equal
deleted
inserted
replaced
40324:6637b079ae45 | 40325:b0fbd1792e2d |
---|---|
2107 def _peek_iscensored(self, baserev, delta, flush): | 2107 def _peek_iscensored(self, baserev, delta, flush): |
2108 """Quickly check if a delta produces a censored revision.""" | 2108 """Quickly check if a delta produces a censored revision.""" |
2109 if not self._censorable: | 2109 if not self._censorable: |
2110 return False | 2110 return False |
2111 | 2111 |
2112 # Fragile heuristic: unless new file meta keys are added alphabetically | 2112 return storageutil.deltaiscensored(delta, baserev, self.rawsize) |
2113 # preceding "censored", all censored revisions are prefixed by | |
2114 # "\1\ncensored:". A delta producing such a censored revision must be a | |
2115 # full-replacement delta, so we inspect the first and only patch in the | |
2116 # delta for this prefix. | |
2117 hlen = struct.calcsize(">lll") | |
2118 if len(delta) <= hlen: | |
2119 return False | |
2120 | |
2121 oldlen = self.rawsize(baserev) | |
2122 newlen = len(delta) - hlen | |
2123 if delta[:hlen] != mdiff.replacediffheader(oldlen, newlen): | |
2124 return False | |
2125 | |
2126 add = "\1\ncensored:" | |
2127 addlen = len(add) | |
2128 return newlen >= addlen and delta[hlen:hlen + addlen] == add | |
2129 | 2113 |
2130 def getstrippoint(self, minlink): | 2114 def getstrippoint(self, minlink): |
2131 """find the minimum rev that must be stripped to strip the linkrev | 2115 """find the minimum rev that must be stripped to strip the linkrev |
2132 | 2116 |
2133 Returns a tuple containing the minimum rev and a set of all revs that | 2117 Returns a tuple containing the minimum rev and a set of all revs that |