# HG changeset patch
# User Gregory Szorc <gregory.sz...@gmail.com>
# Date 1499382096 25200
#      Thu Jul 06 16:01:36 2017 -0700
# Node ID 1d856c7fb9c08bd71ed9bb802917d45f07fb8714
# Parent  01f89a68e9269eec249207478e1e8344e90b7496
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.

diff --git a/mercurial/sparse.py b/mercurial/sparse.py
--- a/mercurial/sparse.py
+++ b/mercurial/sparse.py
@@ -132,10 +132,6 @@ def activeprofiles(repo):
 def invalidatesignaturecache(repo):
     repo._sparsesignaturecache.clear()
 
-def _checksum(self, path):
-    data = self.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 @@ def configsignature(repo, includetemp=Tr
     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('sparse')
-        except (OSError, IOError):
-            pass
+        signature = hashlib.sha1(repo.vfs.tryread('sparse')).hexdigest()
         cache['signature'] = signature
 
-        tempsignature = 0
         if includetemp:
-            try:
-                tempsignature = _checksum('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."""
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to