Patchwork [1,of,5] store: use hashlib.sha1 directly instead of through util

login
register
mail settings
Submitter Augie Fackler
Date June 10, 2016, 4:41 a.m.
Message ID <16f5b31b1228212dc175.1465533674@imladris.local>
Download mbox | patch
Permalink /patch/15451/
State Accepted
Headers show

Comments

Augie Fackler - June 10, 2016, 4:41 a.m.
# HG changeset patch
# User Augie Fackler <raf@durin42.com>
# Date 1465531806 14400
#      Fri Jun 10 00:10:06 2016 -0400
# Node ID 16f5b31b1228212dc175b5a0baf3601cca48330d
# Parent  0c6dbf7019d084d0a775dc716532b5b7f24ee7ea
store: use hashlib.sha1 directly instead of through util

Also remove module-local alias to _sha, since it's not used that much.
Gregory Szorc - June 10, 2016, 4:44 a.m.
Series LGTM.

> On Jun 9, 2016, at 21:41, Augie Fackler <raf@durin42.com> wrote:
> 
> # HG changeset patch
> # User Augie Fackler <raf@durin42.com>
> # Date 1465531806 14400
> #      Fri Jun 10 00:10:06 2016 -0400
> # Node ID 16f5b31b1228212dc175b5a0baf3601cca48330d
> # Parent  0c6dbf7019d084d0a775dc716532b5b7f24ee7ea
> store: use hashlib.sha1 directly instead of through util
> 
> Also remove module-local alias to _sha, since it's not used that much.
> 
> diff --git a/mercurial/store.py b/mercurial/store.py
> --- a/mercurial/store.py
> +++ b/mercurial/store.py
> @@ -8,6 +8,7 @@
> from __future__ import absolute_import
> 
> import errno
> +import hashlib
> import os
> import stat
> 
> @@ -19,8 +20,6 @@ from . import (
>     util,
> )
> 
> -_sha = util.sha1
> -
> # This avoids a collision between a file named foo and a dir named
> # foo.i or foo.d
> def _encodedir(path):
> @@ -211,7 +210,7 @@ def _auxencode(path, dotencode):
> _maxshortdirslen = 8 * (_dirprefixlen + 1) - 4
> 
> def _hashencode(path, dotencode):
> -    digest = _sha(path).hexdigest()
> +    digest = hashlib.sha1(path).hexdigest()
>     le = lowerencode(path[5:]).split('/') # skips prefix 'data/' or 'meta/'
>     parts = _auxencode(le, dotencode)
>     basename = parts[-1]
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/store.py b/mercurial/store.py
--- a/mercurial/store.py
+++ b/mercurial/store.py
@@ -8,6 +8,7 @@ 
 from __future__ import absolute_import
 
 import errno
+import hashlib
 import os
 import stat
 
@@ -19,8 +20,6 @@  from . import (
     util,
 )
 
-_sha = util.sha1
-
 # This avoids a collision between a file named foo and a dir named
 # foo.i or foo.d
 def _encodedir(path):
@@ -211,7 +210,7 @@  def _auxencode(path, dotencode):
 _maxshortdirslen = 8 * (_dirprefixlen + 1) - 4
 
 def _hashencode(path, dotencode):
-    digest = _sha(path).hexdigest()
+    digest = hashlib.sha1(path).hexdigest()
     le = lowerencode(path[5:]).split('/') # skips prefix 'data/' or 'meta/'
     parts = _auxencode(le, dotencode)
     basename = parts[-1]