Merge with crew
authorMatt Mackall <mpm@selenic.com>
Mon, 25 Sep 2006 22:26:54 -0500
changeset 3158 ca00ce41a2e8
parent 3155 56c59ba7aa76 (current diff)
parent 3157 4fe41a9e4591 (diff)
child 3159 e43fd1623fe1
Merge with crew
--- a/mercurial/revlog.py	Mon Sep 25 20:31:05 2006 -0500
+++ b/mercurial/revlog.py	Mon Sep 25 22:26:54 2006 -0500
@@ -747,25 +747,42 @@
         return c
 
     def lookup(self, id):
-        """locate a node based on revision number or subset of hex nodeid"""
+        """locate a node based on:
+            - revision number or str(revision number)
+            - nodeid or subset of hex nodeid
+        """
         if type(id) == type(0):
+            # rev
             return self.node(id)
         try:
+            # str(rev)
             rev = int(id)
             if str(rev) != id: raise ValueError
             if rev < 0: rev = self.count() + rev
             if rev < 0 or rev >= self.count(): raise ValueError
             return self.node(rev)
         except (ValueError, OverflowError):
-            c = []
+            pass
+        try:
+            # hex(node)[:...]
+            if len(id) % 2 == 0:
+                bin_id = bin(id)
+            else:
+                bin_id = bin(id[:-1])
+            node = None
             for n in self.nodemap:
-                if hex(n).startswith(id):
-                    c.append(n)
-            if len(c) > 1: raise RevlogError(_("Ambiguous identifier"))
-            if len(c) == 1: return c[0]
+                if n.startswith(bin_id) and hex(n).startswith(id):
+                    if node is not None:
+                        raise RevlogError(_("Ambiguous identifier"))
+                    node = n
+            if node is not None:
+                return node
+        except TypeError:
+            pass
 
         # might need fixing if we change hash lengths
         if len(id) == 20 and id in self.nodemap:
+            # node
             return id
 
         raise RevlogError(_("No match found"))