Patchwork [5,of,5] util: drop local aliases for md5, sha1, sha256, and sha512

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

Comments

Augie Fackler - June 10, 2016, 4:41 a.m.
# HG changeset patch
# User Augie Fackler <raf@durin42.com>
# Date 1465532003 14400
#      Fri Jun 10 00:13:23 2016 -0400
# Node ID fad6ce69483b3b25c6bd9fb2bd9e2e31467f207f
# Parent  c53644cf3126d5fe51a32b464ecf77c3ea2ca549
util: drop local aliases for md5, sha1, sha256, and sha512

This used to be needed to paper over hashlib not being in all Pythons
we support, but that's not a problem anymore, so we can simplify
things a little bit.
timeless - July 8, 2016, 4:06 p.m.
This was bad.

  File "/home/timeless/hg/topic/hgext3rd/topic/topicmap.py", line 37,
in _phaseshash
    s = util.sha1()
AttributeError: 'module' object has no attribute 'sha1'

  File "/home/timeless/hg/evolve-main/hgext/evolve.py", line 3929, in
_obsrelsethashtree
    sha = util.sha1()
AttributeError: 'module' object has no attribute 'sha1'

It meant that I ended up w/ a broken hg and thus couldn't easily back
myself out of it.

Can we please leave sha1 in w/ a deprecation warning for at least 1 revision?

Also, the error handling is pretty poor. For this case (AttributeError
/ module missing thing), we should crawl the stack looking for
extensions and suggest disabling them...

On Fri, Jun 10, 2016 at 12:41 AM, Augie Fackler <raf@durin42.com> wrote:
> # HG changeset patch
> # User Augie Fackler <raf@durin42.com>
> # Date 1465532003 14400
> #      Fri Jun 10 00:13:23 2016 -0400
> # Node ID fad6ce69483b3b25c6bd9fb2bd9e2e31467f207f
> # Parent  c53644cf3126d5fe51a32b464ecf77c3ea2ca549
> util: drop local aliases for md5, sha1, sha256, and sha512
>
> This used to be needed to paper over hashlib not being in all Pythons
> we support, but that's not a problem anymore, so we can simplify
> things a little bit.
>
> diff --git a/mercurial/util.py b/mercurial/util.py
> --- a/mercurial/util.py
> +++ b/mercurial/util.py
> @@ -64,10 +64,6 @@ if os.name == 'nt':
>  else:
>      from . import posix as platform
>
> -md5 = hashlib.md5
> -sha1 = hashlib.sha1
> -sha256 = hashlib.sha256
> -sha512 = hashlib.sha512
>  _ = i18n._
>
>  cachestat = platform.cachestat
> @@ -138,9 +134,9 @@ def safehasattr(thing, attr):
>      return getattr(thing, attr, _notset) is not _notset
>
>  DIGESTS = {
> -    'md5': md5,
> -    'sha1': sha1,
> -    'sha512': sha512,
> +    'md5': hashlib.md5,
> +    'sha1': hashlib.sha1,
> +    'sha512': hashlib.sha512,
>  }
>  # List of digest types from strongest to weakest
>  DIGESTS_BY_STRENGTH = ['sha512', 'sha1', 'md5']
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
timeless - July 17, 2016, 7:53 p.m.
And... we really need some mechanism to recognize when our .so/.dll
files are out of sync w/ our .py files...

I was still getting errors about util.sha1 even after I fixed all of
my python consumers because I hadn't rebuilt patchencode.c. -- And
because of various things (demandimport, python2's totally unhelpful
error reporting), it's really hard to figure out what's going wrong.

  File "/home/timeless/hg/crew/mercurial/localrepo.py", line 105, in wrapper
    return orig(repo.unfiltered(), *args, **kwargs)
  File "/home/timeless/hg/crew/mercurial/localrepo.py", line 1700, in commitctx
    trp, changed)
  File "/home/timeless/hg/crew/mercurial/localrepo.py", line 1404, in _filecommt
    flog = self.file(fname)
  File "/home/timeless/hg/crew/mercurial/localrepo.py", line 889, in file
    return filelog.filelog(self.svfs, f)
  File "/home/timeless/hg/crew/mercurial/filelog.py", line 45, in __init__
    "/".join(("data", path + ".i")))
  File "/home/timeless/hg/crew/mercurial/revlog.py", line 270, in __init__
    f = self.opener(self.indexfile)
  File "/home/timeless/hg/crew/mercurial/store.py", line 480, in __call__
    return self.vfs(self.encode(path), mode, *args, **kw)
AttributeError: module 'mercurial.util' has no attribute 'sha1'
-> return self.vfs(self.encode(path), mode, *args, **kw)
(Pdb) p self.encode(path)
*** AttributeError: AttributeError("module 'mercurial.util' has no
attribute 'sa1'",)
(Pdb) p self
<mercurial.store._fncachevfs object at 0x3fff83d25450>
(Pdb) p self.encode
<built-in function pathencode>

indygreg has recently added some versioning to our .py files for py3...

It'd be somewhat handy if we had some way to recognize when our .so
files were out of sync w/ our .py files ... a constant that was pulled
from a .py file as part of the build process and checked at load time
would probably work...

On Fri, Jul 8, 2016 at 12:06 PM, timeless <timeless@gmail.com> wrote:
> This was bad.
>
>   File "/home/timeless/hg/topic/hgext3rd/topic/topicmap.py", line 37,
> in _phaseshash
>     s = util.sha1()
> AttributeError: 'module' object has no attribute 'sha1'
>
>   File "/home/timeless/hg/evolve-main/hgext/evolve.py", line 3929, in
> _obsrelsethashtree
>     sha = util.sha1()
> AttributeError: 'module' object has no attribute 'sha1'
>
> It meant that I ended up w/ a broken hg and thus couldn't easily back
> myself out of it.
>
> Can we please leave sha1 in w/ a deprecation warning for at least 1 revision?
>
> Also, the error handling is pretty poor. For this case (AttributeError
> / module missing thing), we should crawl the stack looking for
> extensions and suggest disabling them...
>
> On Fri, Jun 10, 2016 at 12:41 AM, Augie Fackler <raf@durin42.com> wrote:
>> # HG changeset patch
>> # User Augie Fackler <raf@durin42.com>
>> # Date 1465532003 14400
>> #      Fri Jun 10 00:13:23 2016 -0400
>> # Node ID fad6ce69483b3b25c6bd9fb2bd9e2e31467f207f
>> # Parent  c53644cf3126d5fe51a32b464ecf77c3ea2ca549
>> util: drop local aliases for md5, sha1, sha256, and sha512
>>
>> This used to be needed to paper over hashlib not being in all Pythons
>> we support, but that's not a problem anymore, so we can simplify
>> things a little bit.
>>
>> diff --git a/mercurial/util.py b/mercurial/util.py
>> --- a/mercurial/util.py
>> +++ b/mercurial/util.py
>> @@ -64,10 +64,6 @@ if os.name == 'nt':
>>  else:
>>      from . import posix as platform
>>
>> -md5 = hashlib.md5
>> -sha1 = hashlib.sha1
>> -sha256 = hashlib.sha256
>> -sha512 = hashlib.sha512
>>  _ = i18n._
>>
>>  cachestat = platform.cachestat
>> @@ -138,9 +134,9 @@ def safehasattr(thing, attr):
>>      return getattr(thing, attr, _notset) is not _notset
>>
>>  DIGESTS = {
>> -    'md5': md5,
>> -    'sha1': sha1,
>> -    'sha512': sha512,
>> +    'md5': hashlib.md5,
>> +    'sha1': hashlib.sha1,
>> +    'sha512': hashlib.sha512,
>>  }
>>  # List of digest types from strongest to weakest
>>  DIGESTS_BY_STRENGTH = ['sha512', 'sha1', 'md5']
>> _______________________________________________
>> Mercurial-devel mailing list
>> Mercurial-devel@mercurial-scm.org
>> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -64,10 +64,6 @@  if os.name == 'nt':
 else:
     from . import posix as platform
 
-md5 = hashlib.md5
-sha1 = hashlib.sha1
-sha256 = hashlib.sha256
-sha512 = hashlib.sha512
 _ = i18n._
 
 cachestat = platform.cachestat
@@ -138,9 +134,9 @@  def safehasattr(thing, attr):
     return getattr(thing, attr, _notset) is not _notset
 
 DIGESTS = {
-    'md5': md5,
-    'sha1': sha1,
-    'sha512': sha512,
+    'md5': hashlib.md5,
+    'sha1': hashlib.sha1,
+    'sha512': hashlib.sha512,
 }
 # List of digest types from strongest to weakest
 DIGESTS_BY_STRENGTH = ['sha512', 'sha1', 'md5']