comparison hgext/sparse.py @ 33295:c72e9c61d2b1

sparse: refactor sparsechecksum() This was relying on garbage collection to close the opened file, which is a bug. Both callers simply called into self.vfs to resolve the path. So refactor to use the vfs layer. While we're here, rename the method to reflect it is internal and to break anyone relying on the old behavior.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 01 Jul 2017 11:56:39 -0700
parents a5921ad2eb99
children ee616196227c
comparison
equal deleted inserted replaced
33294:a5921ad2eb99 33295:c72e9c61d2b1
491 def getrawprofile(self, profile, changeid): 491 def getrawprofile(self, profile, changeid):
492 # TODO add some kind of cache here because this incurs a manifest 492 # TODO add some kind of cache here because this incurs a manifest
493 # resolve and can be slow. 493 # resolve and can be slow.
494 return self.filectx(profile, changeid=changeid).data() 494 return self.filectx(profile, changeid=changeid).data()
495 495
496 def sparsechecksum(self, filepath): 496 def _sparsechecksum(self, path):
497 fh = open(filepath) 497 data = self.vfs.read(path)
498 return hashlib.sha1(fh.read()).hexdigest() 498 return hashlib.sha1(data).hexdigest()
499 499
500 def _sparsesignature(self, includetemp=True): 500 def _sparsesignature(self, includetemp=True):
501 """Returns the signature string representing the contents of the 501 """Returns the signature string representing the contents of the
502 current project sparse configuration. This can be used to cache the 502 current project sparse configuration. This can be used to cache the
503 sparse matcher for a given set of revs.""" 503 sparse matcher for a given set of revs."""
509 tempsignature = 0 509 tempsignature = 0
510 510
511 if signature is None or (includetemp and tempsignature is None): 511 if signature is None or (includetemp and tempsignature is None):
512 signature = 0 512 signature = 0
513 try: 513 try:
514 sparsepath = self.vfs.join('sparse') 514 signature = self._sparsechecksum('sparse')
515 signature = self.sparsechecksum(sparsepath)
516 except (OSError, IOError): 515 except (OSError, IOError):
517 pass 516 pass
518 signaturecache['signature'] = signature 517 signaturecache['signature'] = signature
519 518
520 tempsignature = 0 519 tempsignature = 0
521 if includetemp: 520 if includetemp:
522 try: 521 try:
523 tempsparsepath = self.vfs.join('tempsparse') 522 tempsignature = self._sparsechecksum('tempsparse')
524 tempsignature = self.sparsechecksum(tempsparsepath)
525 except (OSError, IOError): 523 except (OSError, IOError):
526 pass 524 pass
527 signaturecache['tempsignature'] = tempsignature 525 signaturecache['tempsignature'] = tempsignature
528 return '%s %s' % (str(signature), str(tempsignature)) 526 return '%s %s' % (str(signature), str(tempsignature))
529 527