D10535: core: don't hard-code hex node lengths
joerg.sonnenberger (Joerg Sonnenberger)
phabricator at mercurial-scm.org
Fri Apr 30 01:11:44 UTC 2021
joerg.sonnenberger created this revision.
Herald added a reviewer: indygreg.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.
REPOSITORY
rHG Mercurial
BRANCH
default
REVISION DETAIL
https://phab.mercurial-scm.org/D10535
AFFECTED FILES
mercurial/localrepo.py
mercurial/revlog.py
mercurial/revset.py
mercurial/scmutil.py
mercurial/templatefuncs.py
CHANGE DETAILS
diff --git a/mercurial/templatefuncs.py b/mercurial/templatefuncs.py
--- a/mercurial/templatefuncs.py
+++ b/mercurial/templatefuncs.py
@@ -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:
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -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)
diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -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:
diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -1454,7 +1454,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)
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -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:
To: joerg.sonnenberger, indygreg, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
More information about the Mercurial-devel
mailing list