changeset 33318:526255fe7899

sparse: clean up config signature code Before, 0 was being used as the default signature value and we cast the int to a string. We also handled I/O exceptions manually. The new code uses cfs.tryread() so we always feed data into the hasher. The empty string does hash and and should be suitable for input into a cache key. The changes made the code simple enough that the separate checksum function could be inlined.
author Gregory Szorc <gregory.szorc@gmail.com>
date Thu, 06 Jul 2017 16:01:36 -0700
parents df1287268cc0
children 3c84591e7321
files mercurial/sparse.py
diffstat 1 files changed, 5 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/sparse.py	Thu Jul 06 16:11:56 2017 -0700
+++ b/mercurial/sparse.py	Thu Jul 06 16:01:36 2017 -0700
@@ -132,10 +132,6 @@
 def invalidatesignaturecache(repo):
     repo._sparsesignaturecache.clear()
 
-def _checksum(repo, path):
-    data = repo.vfs.read(path)
-    return hashlib.sha1(data).hexdigest()
-
 def configsignature(repo, includetemp=True):
     """Obtain the signature string for the current sparse configuration.
 
@@ -148,25 +144,18 @@
     if includetemp:
         tempsignature = cache.get('tempsignature')
     else:
-        tempsignature = 0
+        tempsignature = '0'
 
     if signature is None or (includetemp and tempsignature is None):
-        signature = 0
-        try:
-            signature = _checksum(repo, 'sparse')
-        except (OSError, IOError):
-            pass
+        signature = hashlib.sha1(repo.vfs.tryread('sparse')).hexdigest()
         cache['signature'] = signature
 
-        tempsignature = 0
         if includetemp:
-            try:
-                tempsignature = _checksum(repo, 'tempsparse')
-            except (OSError, IOError):
-                pass
+            raw = repo.vfs.tryread('tempsparse')
+            tempsignature = hashlib.sha1(raw).hexdigest()
             cache['tempsignature'] = tempsignature
 
-    return '%s %s' % (str(signature), str(tempsignature))
+    return '%s %s' % (signature, tempsignature)
 
 def writeconfig(repo, includes, excludes, profiles):
     """Write the sparse config file given a sparse configuration."""