Patchwork [6,of,9] py3: use pycompat.bytestr to convert str(unicode) to bytes

login
register
mail settings
Submitter Pulkit Goyal
Date June 23, 2017, 7:55 p.m.
Message ID <a1a4111876b69cb34fef.1498247700@workspace>
Download mbox | patch
Permalink /patch/21649/
State Accepted
Headers show

Comments

Pulkit Goyal - June 23, 2017, 7:55 p.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1498081876 -19800
#      Thu Jun 22 03:21:16 2017 +0530
# Node ID a1a4111876b69cb34fefcdf50c0ac70ea5ef704b
# Parent  98d32035dd10311980576a1007ca0ba1cf98240f
py3: use pycompat.bytestr to convert str(unicode) to bytes
Yuya Nishihara - June 24, 2017, 3:29 a.m.
On Sat, 24 Jun 2017 01:25:00 +0530, Pulkit Goyal wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit@gmail.com>
> # Date 1498081876 -19800
> #      Thu Jun 22 03:21:16 2017 +0530
> # Node ID a1a4111876b69cb34fefcdf50c0ac70ea5ef704b
> # Parent  98d32035dd10311980576a1007ca0ba1cf98240f
> py3: use pycompat.bytestr to convert str(unicode) to bytes
> 
> diff --git a/mercurial/merge.py b/mercurial/merge.py
> --- a/mercurial/merge.py
> +++ b/mercurial/merge.py
> @@ -414,7 +414,7 @@
>          if fcl.isabsent():
>              hash = nullhex
>          else:
> -            hash = hashlib.sha1(fcl.path()).hexdigest()
> +            hash = pycompat.bytestr(hashlib.sha1(fcl.path()).hexdigest())

This can be hex(sha1(...).digest()).

Patch

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -414,7 +414,7 @@ 
         if fcl.isabsent():
             hash = nullhex
         else:
-            hash = hashlib.sha1(fcl.path()).hexdigest()
+            hash = pycompat.bytestr(hashlib.sha1(fcl.path()).hexdigest())
             self._repo.vfs.write('merge/' + hash, fcl.data())
         self._state[fd] = ['u', hash, fcl.path(),
                            fca.path(), hex(fca.filenode()),