changeset 3158:ca00ce41a2e8

Merge with crew
author Matt Mackall <mpm@selenic.com>
date Mon, 25 Sep 2006 22:26:54 -0500
parents 56c59ba7aa76 (current diff) 4fe41a9e4591 (diff)
children e43fd1623fe1
files
diffstat 1 files changed, 23 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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"))