[PATCH] revlog: add explicit type check to _match()

Dan Villiom Podlaski Christiansen danchr at gmail.com
Wed Aug 12 05:13:31 CDT 2009


# HG changeset patch
# User Dan Villiom Podlaski Christiansen <danchr at gmail.com>
# Date 1250071313 -7200
# Node ID 503f9a6eacfa9afd12493d5cbf1707c3d2046504
# Parent  a4a996cce137e1a328f6cd384d46b97e62fd26fe
revlog: add explicit type check to _match().

The _match method called len() on its parameter without checking the
type, raising a TypeError if 'None' was given. This change adds a type
check, and in case of failure raises the usual 'LookupError'.

I ran into this when loading the 'pathrevspec' extension before
'share'. For some reason, this caused the 'None' value of 'checkout'
in hg.share() to be propagated down the call chain.

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -845,7 +845,12 @@ class revlog(object):
         if isinstance(id, (long, int)):
             # rev
             return self.node(id)
-        if len(id) == 20:
+        elif not isinstance(id, basestring):
+            # invalid identifier: len() or int() may not allow this,
+            # so raise an explicit LookupError.
+            raise LookupError(id, self.indexfile,
+                              _('invalid identifier'))
+        elif len(id) == 20:
             # possibly a binary node
             # odds of a binary node being all hex in ASCII are 1 in 10**25
             try:


More information about the Mercurial-devel mailing list