changeset 3453:dba3cadef789

Only look up tags and branches as a last resort
author Matt Mackall <mpm@selenic.com>
date Wed, 18 Oct 2006 11:44:56 -0500
parents fcf14d87e0a4
children 23ede9e7ad4d
files mercurial/localrepo.py mercurial/revlog.py
diffstat 2 files changed, 31 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/localrepo.py	Wed Oct 18 10:46:51 2006 -0500
+++ b/mercurial/localrepo.py	Wed Oct 18 11:44:56 2006 -0500
@@ -336,14 +336,17 @@
             key = self.dirstate.parents()[0]
             if key == nullid:
                 raise repo.RepoError(_("no revision checked out"))
+        n = self.changelog._match(key)
+        if n:
+            return n
         if key in self.tags():
             return self.tags()[key]
         if key in self.branchtags():
             return self.branchtags()[key]
-        try:
-            return self.changelog.lookup(key)
-        except:
-            raise repo.RepoError(_("unknown revision '%s'") % key)
+        n = self.changelog._partialmatch(key)
+        if n:
+            return n
+        raise repo.RepoError(_("unknown revision '%s'") % key)
 
     def dev(self):
         return os.lstat(self.path).st_dev
--- a/mercurial/revlog.py	Wed Oct 18 10:46:51 2006 -0500
+++ b/mercurial/revlog.py	Wed Oct 18 11:44:56 2006 -0500
@@ -746,11 +746,7 @@
                     continue
         return c
 
-    def lookup(self, id):
-        """locate a node based on:
-            - revision number or str(revision number)
-            - nodeid or subset of hex nodeid
-        """
+    def _match(self, id):
         if isinstance(id, (long, int)):
             # rev
             return self.node(id)
@@ -772,13 +768,18 @@
             return self.node(rev)
         except (ValueError, OverflowError):
             pass
-        try:
-            if len(id) == 40:
+        if len(id) == 40:
+            try:
                 # a full hex nodeid?
                 node = bin(id)
                 r = self.rev(node)
                 return node
-            elif len(id) < 40:
+            except TypeError:
+                pass
+
+    def _partialmatch(self, id):
+        if len(id) < 40:
+            try:
                 # hex(node)[:...]
                 bin_id = bin(id[:len(id) & ~1]) # grab an even number of digits
                 node = None
@@ -789,8 +790,21 @@
                         node = n
                 if node is not None:
                     return node
-        except TypeError:
-            pass
+            except TypeError:
+                pass
+
+    def lookup(self, id):
+        """locate a node based on:
+            - revision number or str(revision number)
+            - nodeid or subset of hex nodeid
+        """
+
+        n = self._match(id)
+        if n is not None:
+            return n
+        n = self._partialmatch(id)
+        if n:
+            return n
 
         raise RevlogError(_("No match found"))