D1481: py3: ensure hashes are bytes in sparse.py

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Tue Nov 21 02:53:46 EST 2017


indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  hashlib's .hexdigest() returns a unicode in Python 3. We need to use
  bytes to make the rest of Mercurial happy.
  
  This was in the top #25 crashes in Python 3.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D1481

AFFECTED FILES
  mercurial/sparse.py

CHANGE DETAILS

diff --git a/mercurial/sparse.py b/mercurial/sparse.py
--- a/mercurial/sparse.py
+++ b/mercurial/sparse.py
@@ -173,12 +173,13 @@
         tempsignature = '0'
 
     if signature is None or (includetemp and tempsignature is None):
-        signature = hashlib.sha1(repo.vfs.tryread('sparse')).hexdigest()
+        signature = pycompat.bytestr(
+            hashlib.sha1(repo.vfs.tryread('sparse')).hexdigest())
         cache['signature'] = signature
 
         if includetemp:
             raw = repo.vfs.tryread('tempsparse')
-            tempsignature = hashlib.sha1(raw).hexdigest()
+            tempsignature = pycompat.bytestr(hashlib.sha1(raw).hexdigest())
             cache['tempsignature'] = tempsignature
 
     return '%s %s' % (signature, tempsignature)



To: indygreg, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list