changeset 469:e205194ca7ef

Various node id lookup tweaks -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Various node id lookup tweaks - - lookup of nullid with lazymap fixed - - do the Pythonic thing with negative rev numbers (-1 == tip) - - bound ranges on rev numbers - - catch exceptions more correctly - - restrict node id matching to beginning of string on manifest hash: 15918cb74f41ac4bbf8bf02bc3bb599f24f0b5b8 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCvQzDywK+sNU5EO8RAnKfAJ4vzXnrGmRwOlPqNQFxxrUKchzAzQCcDkbi g3T3KiiVUckrWpziGq67YUE= =vrSU -----END PGP SIGNATURE-----
author mpm@selenic.com
date Fri, 24 Jun 2005 23:50:27 -0800
parents 157675add351
children 0ab093b473c5
files mercurial/revlog.py
diffstat 1 files changed, 6 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revlog.py	Fri Jun 24 23:22:46 2005 -0800
+++ b/mercurial/revlog.py	Fri Jun 24 23:50:27 2005 -0800
@@ -98,6 +98,7 @@
         self.p.load()
         return key in self.p.map
     def __iter__(self):
+        yield nullid
         for i in xrange(self.p.l):
             try:
                 yield self.p.index[i][6]
@@ -192,12 +193,14 @@
     def lookup(self, id):
         try:
             rev = int(id)
-            if str(rev) != id: raise "mismatch"
+            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:
+        except (ValueError, OverflowError):
             c = []
             for n in self.nodemap:
-                if id in hex(n):
+                if hex(n).startswith(id):
                     c.append(n)
             if len(c) > 1: raise KeyError("Ambiguous identifier")
             if len(c) < 1: raise KeyError("No match found")