core: don't hard-code hex node lengths
authorJoerg Sonnenberger <joerg@bec.de>
Fri, 30 Apr 2021 03:09:16 +0200
changeset 47041 a407fe56d6e8
parent 47039 54589bb9604d
child 47042 c5e1cc0b4c77
core: don't hard-code hex node lengths Differential Revision: https://phab.mercurial-scm.org/D10535
mercurial/localrepo.py
mercurial/revlog.py
mercurial/revset.py
mercurial/scmutil.py
mercurial/templatefuncs.py
--- a/mercurial/localrepo.py	Mon May 03 02:33:00 2021 +0200
+++ b/mercurial/localrepo.py	Fri Apr 30 03:09:16 2021 +0200
@@ -1861,7 +1861,7 @@
                     changeid = hex(changeid)  # for the error message
                     raise
 
-            elif len(changeid) == 40:
+            elif len(changeid) == 2 * self.nodeconstants.nodelen:
                 node = bin(changeid)
                 rev = self.changelog.rev(node)
             else:
--- a/mercurial/revlog.py	Mon May 03 02:33:00 2021 +0200
+++ b/mercurial/revlog.py	Fri Apr 30 03:09:16 2021 +0200
@@ -1320,7 +1320,7 @@
             return self.node(rev)
         except (ValueError, OverflowError):
             pass
-        if len(id) == 40:
+        if len(id) == 2 * self.nodeconstants.nodelen:
             try:
                 # a full hex nodeid?
                 node = bin(id)
--- a/mercurial/revset.py	Mon May 03 02:33:00 2021 +0200
+++ b/mercurial/revset.py	Fri Apr 30 03:09:16 2021 +0200
@@ -1724,7 +1724,7 @@
 def _node(repo, n):
     """process a node input"""
     rn = None
-    if len(n) == 40:
+    if len(n) == 2 * repo.nodeconstants.nodelen:
         try:
             rn = repo.changelog.rev(bin(n))
         except error.WdirUnsupported:
--- a/mercurial/scmutil.py	Mon May 03 02:33:00 2021 +0200
+++ b/mercurial/scmutil.py	Fri Apr 30 03:09:16 2021 +0200
@@ -643,7 +643,7 @@
         except (ValueError, OverflowError, IndexError):
             pass
 
-        if len(symbol) == 40:
+        if len(symbol) == 2 * repo.nodeconstants.nodelen:
             try:
                 node = bin(symbol)
                 rev = repo.changelog.rev(node)
--- a/mercurial/templatefuncs.py	Mon May 03 02:33:00 2021 +0200
+++ b/mercurial/templatefuncs.py	Fri Apr 30 03:09:16 2021 +0200
@@ -764,9 +764,10 @@
         )
 
     repo = context.resource(mapping, b'repo')
-    if len(hexnode) > 40:
+    hexnodelen = 2 * repo.nodeconstants.nodelen
+    if len(hexnode) > hexnodelen:
         return hexnode
-    elif len(hexnode) == 40:
+    elif len(hexnode) == hexnodelen:
         try:
             node = bin(hexnode)
         except TypeError: