node: make bin() be a wrapper instead of just an alias
authorAugie Fackler <augie@google.com>
Wed, 14 Feb 2018 21:34:12 -0500
changeset 36238 f574cc00831a
parent 36237 b39f0fdb0338
child 36239 428de1a59f2d
node: make bin() be a wrapper instead of just an alias This includes a full backout of 59affe7e and 30d0cb27. Per the review of the former, we'd rather adapt the API to behave like it used to (at least for now), and take a second run at it if it shows up in our performance numbers. I ran perfrevlogindex with and without this change and it didn't make a measurable difference, so maybe it's fine (despite my intuition to the contrary). Differential Revision: https://phab.mercurial-scm.org/D2279
hgext/histedit.py
mercurial/node.py
mercurial/revlog.py
--- a/hgext/histedit.py	Fri Feb 16 11:30:18 2018 -0800
+++ b/hgext/histedit.py	Wed Feb 14 21:34:12 2018 -0500
@@ -183,7 +183,6 @@
 
 from __future__ import absolute_import
 
-import binascii
 import errno
 import os
 
@@ -426,7 +425,7 @@
         rulehash = rule.strip().split(' ', 1)[0]
         try:
             rev = node.bin(rulehash)
-        except (TypeError, binascii.Error):
+        except TypeError:
             raise error.ParseError("invalid changeset %s" % rulehash)
         return cls(state, rev)
 
--- a/mercurial/node.py	Fri Feb 16 11:30:18 2018 -0800
+++ b/mercurial/node.py	Wed Feb 14 21:34:12 2018 -0500
@@ -11,7 +11,14 @@
 
 # This ugly style has a noticeable effect in manifest parsing
 hex = binascii.hexlify
-bin = binascii.unhexlify
+# Adapt to Python 3 API changes. If this ends up showing up in
+# profiles, we can use this version only on Python 3, and forward
+# binascii.unhexlify like we used to on Python 2.
+def bin(s):
+    try:
+        return binascii.unhexlify(s)
+    except binascii.Error as e:
+        raise TypeError(e)
 
 nullrev = -1
 nullid = b"\0" * 20
--- a/mercurial/revlog.py	Fri Feb 16 11:30:18 2018 -0800
+++ b/mercurial/revlog.py	Wed Feb 14 21:34:12 2018 -0500
@@ -13,7 +13,6 @@
 
 from __future__ import absolute_import
 
-import binascii
 import collections
 import contextlib
 import errno
@@ -1430,7 +1429,7 @@
                 if maybewdir:
                     raise error.WdirUnsupported
                 return None
-            except (TypeError, binascii.Error):
+            except TypeError:
                 pass
 
     def lookup(self, id):