comparison mercurial/revlog.py @ 30584:be5b2098a817

revlog: merge hash checking subfunctions This patch factors the behavior of both methods into 'checkhash'.
author Remi Chaintron <remi@fb.com>
date Tue, 13 Dec 2016 14:21:36 +0000
parents 03fae9048fa1
children 2df983125d37
comparison
equal deleted inserted replaced
30583:8f8211903b83 30584:be5b2098a817
1245 if text is None: 1245 if text is None:
1246 text = str(bins[0]) 1246 text = str(bins[0])
1247 bins = bins[1:] 1247 bins = bins[1:]
1248 1248
1249 text = mdiff.patches(text, bins) 1249 text = mdiff.patches(text, bins)
1250 1250 self.checkhash(text, node, rev=rev)
1251 text = self._checkhash(text, node, rev)
1252
1253 self._cache = (node, rev, text) 1251 self._cache = (node, rev, text)
1254 return text 1252 return text
1255 1253
1256 def hash(self, text, p1, p2): 1254 def hash(self, text, p1, p2):
1257 """Compute a node hash. 1255 """Compute a node hash.
1259 Available as a function so that subclasses can replace the hash 1257 Available as a function so that subclasses can replace the hash
1260 as needed. 1258 as needed.
1261 """ 1259 """
1262 return hash(text, p1, p2) 1260 return hash(text, p1, p2)
1263 1261
1264 def _checkhash(self, text, node, rev): 1262 def checkhash(self, text, node, p1=None, p2=None, rev=None):
1265 p1, p2 = self.parents(node) 1263 """Check node hash integrity.
1266 self.checkhash(text, p1, p2, node, rev) 1264
1267 return text 1265 Available as a function so that subclasses can extend hash mismatch
1268 1266 behaviors as needed.
1269 def checkhash(self, text, p1, p2, node, rev=None): 1267 """
1268 if p1 is None and p2 is None:
1269 p1, p2 = self.parents(node)
1270 if node != self.hash(text, p1, p2): 1270 if node != self.hash(text, p1, p2):
1271 revornode = rev 1271 revornode = rev
1272 if revornode is None: 1272 if revornode is None:
1273 revornode = templatefilters.short(hex(node)) 1273 revornode = templatefilters.short(hex(node))
1274 raise RevlogError(_("integrity check failed on %s:%s") 1274 raise RevlogError(_("integrity check failed on %s:%s")
1439 else: 1439 else:
1440 fh = dfh 1440 fh = dfh
1441 basetext = self.revision(self.node(baserev), _df=fh) 1441 basetext = self.revision(self.node(baserev), _df=fh)
1442 btext[0] = mdiff.patch(basetext, delta) 1442 btext[0] = mdiff.patch(basetext, delta)
1443 try: 1443 try:
1444 self.checkhash(btext[0], p1, p2, node) 1444 self.checkhash(btext[0], node, p1=p1, p2=p2)
1445 if flags & REVIDX_ISCENSORED: 1445 if flags & REVIDX_ISCENSORED:
1446 raise RevlogError(_('node %s is not censored') % node) 1446 raise RevlogError(_('node %s is not censored') % node)
1447 except CensoredNodeError: 1447 except CensoredNodeError:
1448 # must pass the censored index flag to add censored revisions 1448 # must pass the censored index flag to add censored revisions
1449 if not flags & REVIDX_ISCENSORED: 1449 if not flags & REVIDX_ISCENSORED: