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

login
register
mail settings
Submitter phabricator
Date Nov. 21, 2017, 7:53 a.m.
Message ID <differential-rev-PHID-DREV-qfwww352iurdg7sc4tec-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/25707/
State Superseded
Headers show

Comments

phabricator - Nov. 21, 2017, 7:53 a.m.
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




To: indygreg, #hg-reviewers
Cc: mercurial-devel
phabricator - Nov. 21, 2017, 12:41 p.m.
yuja added a comment.


  We can do `nodemod.hex(h.digest())` instead.

REPOSITORY
  rHG Mercurial

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

To: indygreg, #hg-reviewers
Cc: yuja, mercurial-devel
phabricator - Jan. 14, 2018, 7:41 p.m.
indygreg abandoned this revision.
indygreg added a comment.


  This was addressed in https://phab.mercurial-scm.org/D1792.

REPOSITORY
  rHG Mercurial

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

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

Patch

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)