##// END OF EJS Templates
Only look up tags and branches as a last resort
Matt Mackall -
r3453:dba3cade default
parent child Browse files
Show More
@@ -336,14 +336,17 b' class localrepository(repo.repository):'
336 key = self.dirstate.parents()[0]
336 key = self.dirstate.parents()[0]
337 if key == nullid:
337 if key == nullid:
338 raise repo.RepoError(_("no revision checked out"))
338 raise repo.RepoError(_("no revision checked out"))
339 n = self.changelog._match(key)
340 if n:
341 return n
339 if key in self.tags():
342 if key in self.tags():
340 return self.tags()[key]
343 return self.tags()[key]
341 if key in self.branchtags():
344 if key in self.branchtags():
342 return self.branchtags()[key]
345 return self.branchtags()[key]
343 try:
346 n = self.changelog._partialmatch(key)
344 return self.changelog.lookup(key)
347 if n:
345 except:
348 return n
346 raise repo.RepoError(_("unknown revision '%s'") % key)
349 raise repo.RepoError(_("unknown revision '%s'") % key)
347
350
348 def dev(self):
351 def dev(self):
349 return os.lstat(self.path).st_dev
352 return os.lstat(self.path).st_dev
@@ -746,11 +746,7 b' class revlog(object):'
746 continue
746 continue
747 return c
747 return c
748
748
749 def lookup(self, id):
749 def _match(self, id):
750 """locate a node based on:
751 - revision number or str(revision number)
752 - nodeid or subset of hex nodeid
753 """
754 if isinstance(id, (long, int)):
750 if isinstance(id, (long, int)):
755 # rev
751 # rev
756 return self.node(id)
752 return self.node(id)
@@ -772,13 +768,18 b' class revlog(object):'
772 return self.node(rev)
768 return self.node(rev)
773 except (ValueError, OverflowError):
769 except (ValueError, OverflowError):
774 pass
770 pass
775 try:
771 if len(id) == 40:
776 if len(id) == 40:
772 try:
777 # a full hex nodeid?
773 # a full hex nodeid?
778 node = bin(id)
774 node = bin(id)
779 r = self.rev(node)
775 r = self.rev(node)
780 return node
776 return node
781 elif len(id) < 40:
777 except TypeError:
778 pass
779
780 def _partialmatch(self, id):
781 if len(id) < 40:
782 try:
782 # hex(node)[:...]
783 # hex(node)[:...]
783 bin_id = bin(id[:len(id) & ~1]) # grab an even number of digits
784 bin_id = bin(id[:len(id) & ~1]) # grab an even number of digits
784 node = None
785 node = None
@@ -789,8 +790,21 b' class revlog(object):'
789 node = n
790 node = n
790 if node is not None:
791 if node is not None:
791 return node
792 return node
792 except TypeError:
793 except TypeError:
793 pass
794 pass
795
796 def lookup(self, id):
797 """locate a node based on:
798 - revision number or str(revision number)
799 - nodeid or subset of hex nodeid
800 """
801
802 n = self._match(id)
803 if n is not None:
804 return n
805 n = self._partialmatch(id)
806 if n:
807 return n
794
808
795 raise RevlogError(_("No match found"))
809 raise RevlogError(_("No match found"))
796
810
General Comments 0
You need to be logged in to leave comments. Login now