Much of isvalid() was about testing if a prefix is a valid revnum. I
want to reuse that soon, so let's move it out.
There is no significant slowdown from the function call overhead.
| indygreg |
| hg-reviewers |
Much of isvalid() was about testing if a prefix is a valid revnum. I
want to reuse that soon, so let's move it out.
There is no significant slowdown from the function call overhead.
| Lint Skipped |
| Unit Tests Skipped |
| Path | Packages | |||
|---|---|---|---|---|
| M | mercurial/revlog.py (23 lines) |
| Commit | Parents | Author | Summary | Date |
|---|---|---|---|---|
| Martin von Zweigbergk | May 3 2018, 1:56 AM |
| Status | Author | Revision | |
|---|---|---|---|
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz |
| n = self._partialmatch(id) | n = self._partialmatch(id) | ||||
| if n: | if n: | ||||
| return n | return n | ||||
| raise LookupError(id, self.indexfile, _('no match found')) | raise LookupError(id, self.indexfile, _('no match found')) | ||||
| def shortest(self, node, minlength=1): | def shortest(self, node, minlength=1): | ||||
| """Find the shortest unambiguous prefix that matches node.""" | """Find the shortest unambiguous prefix that matches node.""" | ||||
| def isvalid(prefix): | def isrev(prefix): | ||||
| try: | |||||
| if self._partialmatch(prefix) is None: | |||||
| return False | |||||
| except error.RevlogError: | |||||
| return False | |||||
| except error.WdirUnsupported: | |||||
| # single 'ff...' match | |||||
| return True | |||||
| try: | try: | ||||
| i = int(prefix) | i = int(prefix) | ||||
| # if we are a pure int, then starting with zero will not be | # if we are a pure int, then starting with zero will not be | ||||
| # confused as a rev; or, obviously, if the int is larger | # confused as a rev; or, obviously, if the int is larger | ||||
| # than the value of the tip rev | # than the value of the tip rev | ||||
| if prefix[0] == '0' or i > len(self): | if prefix[0] == '0' or i > len(self): | ||||
| return True | |||||
| return False | return False | ||||
| return True | |||||
| except ValueError: | except ValueError: | ||||
| return False | |||||
| def isvalid(prefix): | |||||
| try: | |||||
| if self._partialmatch(prefix) is None: | |||||
| return False | |||||
| except error.RevlogError: | |||||
| return False | |||||
| except error.WdirUnsupported: | |||||
| # single 'ff...' match | |||||
| return True | return True | ||||
| return not isrev(prefix) | |||||
| hexnode = hex(node) | hexnode = hex(node) | ||||
| shortest = hexnode | shortest = hexnode | ||||
| startlength = max(6, minlength) | startlength = max(6, minlength) | ||||
| length = startlength | length = startlength | ||||
| while True: | while True: | ||||
| prefix = hexnode[:length] | prefix = hexnode[:length] | ||||
| if isvalid(prefix): | if isvalid(prefix): | ||||