changeset 3156:d01e4cb2f5f2

cleanups in revlog.lookup - add comments - do a clean separation of the different cases - don't use a list of each possible node when doing the lookup, just keep the previous entry
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
date Sun, 24 Sep 2006 13:52:25 +0200
parents 6719b3dd7d50
children 4fe41a9e4591
files mercurial/revlog.py
diffstat 1 files changed, 17 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revlog.py	Fri Sep 22 16:12:39 2006 -0500
+++ b/mercurial/revlog.py	Sun Sep 24 13:52:25 2006 +0200
@@ -747,25 +747,35 @@
         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 = []
-            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]
+            pass
+        # hex(node)[:...]
+        node = None
+        for n in self.nodemap:
+            if hex(n).startswith(id):
+                if node is not None:
+                    raise RevlogError(_("Ambiguous identifier"))
+                node = n
+        if node is not None:
+            return node
 
         # 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"))