Patchwork [4,of,8,py3] repair: reliably obtain bytestr of node ids

login
register
mail settings
Submitter Augie Fackler
Date Sept. 15, 2017, 11:14 p.m.
Message ID <050dd624a9a887c3efde.1505517247@augie-macbookpro2.roam.corp.google.com>
Download mbox | patch
Permalink /patch/23922/
State Accepted
Headers show

Comments

Augie Fackler - Sept. 15, 2017, 11:14 p.m.
# HG changeset patch
# User Augie Fackler <raf@durin42.com>
# Date 1503451354 14400
#      Tue Aug 22 21:22:34 2017 -0400
# Node ID 050dd624a9a887c3efde65b7750311d3d3bd716c
# Parent  e6d61e2a38873be057c9ecd0432750935423d745
repair: reliably obtain bytestr of node ids
Yuya Nishihara - Sept. 16, 2017, 11:57 a.m.
On Fri, 15 Sep 2017 19:14:07 -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 050dd624a9a887c3efde65b7750311d3d3bd716c
> # Parent  e6d61e2a38873be057c9ecd0432750935423d745
> repair: reliably obtain bytestr of node ids
> 
> diff --git a/mercurial/repair.py b/mercurial/repair.py
> --- a/mercurial/repair.py
> +++ b/mercurial/repair.py
> @@ -12,7 +12,10 @@ import errno
>  import hashlib
>  
>  from .i18n import _
> -from .node import short
> +from .node import (
> +    hex,
> +    short,
> +)
>  from . import (
>      bundle2,
>      changegroup,
> @@ -21,6 +24,7 @@ from . import (
>      exchange,
>      obsolete,
>      obsutil,
> +    pycompat,
>      util,
>  )
>  
> @@ -35,8 +39,9 @@ def _bundle(repo, bases, heads, node, su
>      # Include a hash of all the nodes in the filename for uniqueness
>      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)
> +    totalhash = hashlib.sha1(''.join(allhashes)).digest()
> +    name = "%s/%s-%s-%s.hg" % (backupdir, pycompat.bytestr(short(node)),
> +                               hex(totalhash[:4]), suffix)

Perhaps pycompat.bytestr() isn't needed. node.short() returns a bytes.

Patch

diff --git a/mercurial/repair.py b/mercurial/repair.py
--- a/mercurial/repair.py
+++ b/mercurial/repair.py
@@ -12,7 +12,10 @@  import errno
 import hashlib
 
 from .i18n import _
-from .node import short
+from .node import (
+    hex,
+    short,
+)
 from . import (
     bundle2,
     changegroup,
@@ -21,6 +24,7 @@  from . import (
     exchange,
     obsolete,
     obsutil,
+    pycompat,
     util,
 )
 
@@ -35,8 +39,9 @@  def _bundle(repo, bases, heads, node, su
     # Include a hash of all the nodes in the filename for uniqueness
     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)
+    totalhash = hashlib.sha1(''.join(allhashes)).digest()
+    name = "%s/%s-%s-%s.hg" % (backupdir, pycompat.bytestr(short(node)),
+                               hex(totalhash[:4]), suffix)
 
     cgversion = changegroup.safeversion(repo)
     comp = None