[PATCH 1 of 3 STABLE] node: add a `isnode` function
Boris Feld
boris.feld at octobus.net
Thu Jul 26 12:21:18 UTC 2018
# HG changeset patch
# User Boris Feld <boris.feld at octobus.net>
# Date 1532598676 -7200
# Thu Jul 26 11:51:16 2018 +0200
# Branch stable
# Node ID fd0db472d69ac41a0540a15a3019707a368727b3
# Parent 10d40c83205b69e000016f6d2b83c9d4be453f6b
# EXP-Topic compat-hggit
# Available At https://bitbucket.org/octobus/mercurial-devel/
# hg pull https://bitbucket.org/octobus/mercurial-devel/ -r fd0db472d69a
node: add a `isnode` function
This function centralize basic check to understand if an identifier looks like a
node or not.
diff --git a/mercurial/node.py b/mercurial/node.py
--- a/mercurial/node.py
+++ b/mercurial/node.py
@@ -40,3 +40,12 @@ wdirhex = hex(wdirid)
def short(node):
return hex(node[:6])
+
+def isnode(symbol):
+ """True if the symbol is a valid internal binary node
+
+ note: symbol of length 20 will considered a node too"""
+ return (symbol is not None
+ and isinstance(symbol, bytes)
+ and len(symbol) == 20)
+
More information about the Mercurial-devel
mailing list