--- 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"))