Patchwork [7,of,7] repair: use bytestr() to turn hashes into bytes

login
register
mail settings
Submitter Augie Fackler
Date Aug. 29, 2017, 3:22 p.m.
Message ID <67e8c38e7efb154b63c2.1504020124@augie-macbookpro2.roam.corp.google.com>
Download mbox | patch
Permalink /patch/23476/
State Accepted
Headers show

Comments

Augie Fackler - Aug. 29, 2017, 3:22 p.m.
# HG changeset patch
# User Augie Fackler <raf@durin42.com>
# Date 1503451354 14400
#      Tue Aug 22 21:22:34 2017 -0400
# Node ID 67e8c38e7efb154b63c23426d402e0ffdf0831aa
# Parent  ae30c980ec329715171d142644a6bda68114df57
repair: use bytestr() to turn hashes into bytes
Yuya Nishihara - Aug. 31, 2017, 1:59 p.m.
On Tue, 29 Aug 2017 11:22:04 -0400, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <raf@durin42.com>
> # Date 1503451354 14400
> #      Tue Aug 22 21:22:34 2017 -0400
> # Node ID 67e8c38e7efb154b63c23426d402e0ffdf0831aa
> # Parent  ae30c980ec329715171d142644a6bda68114df57
> repair: use bytestr() to turn hashes into bytes
> 
> diff --git a/mercurial/repair.py b/mercurial/repair.py
> --- a/mercurial/repair.py
> +++ b/mercurial/repair.py
> @@ -21,6 +21,7 @@ from . import (
>      exchange,
>      obsolete,
>      obsutil,
> +    pycompat,
>      util,
>  )
>  
> @@ -36,7 +37,8 @@ def _bundle(repo, bases, heads, node, su
>      allcommits = repo.set('%ln::%ln', bases, heads)
>      allhashes = sorted(c.hex() for c in allcommits)
>      totalhash = hashlib.sha1(''.join(allhashes)).hexdigest()
> -    name = "%s/%s-%s-%s.hg" % (backupdir, short(node), totalhash[:8], suffix)
> +    name = "%s/%s-%s-%s.hg" % (backupdir, pycompat.bytestr(short(node)),
> +                               pycompat.bytestr(totalhash[:8]), suffix)

I slightly prefer .digest() and hex(totalhash[:4]).

Patch

diff --git a/mercurial/repair.py b/mercurial/repair.py
--- a/mercurial/repair.py
+++ b/mercurial/repair.py
@@ -21,6 +21,7 @@  from . import (
     exchange,
     obsolete,
     obsutil,
+    pycompat,
     util,
 )
 
@@ -36,7 +37,8 @@  def _bundle(repo, bases, heads, node, su
     allcommits = repo.set('%ln::%ln', bases, heads)
     allhashes = sorted(c.hex() for c in allcommits)
     totalhash = hashlib.sha1(''.join(allhashes)).hexdigest()
-    name = "%s/%s-%s-%s.hg" % (backupdir, short(node), totalhash[:8], suffix)
+    name = "%s/%s-%s-%s.hg" % (backupdir, pycompat.bytestr(short(node)),
+                               pycompat.bytestr(totalhash[:8]), suffix)
 
     cgversion = changegroup.safeversion(repo)
     comp = None