Patchwork [1,of,3,STABLE] node: add a `isnode` function

login
register
mail settings
Submitter Boris Feld
Date July 26, 2018, 12:21 p.m.
Message ID <fd0db472d69ac41a0540.1532607678@FB-lair>
Download mbox | patch
Permalink /patch/32944/
State New
Headers show

Comments

Boris Feld - July 26, 2018, 12:21 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@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.

Patch

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)
+