Patchwork D3500: shortest: make pure code also disambigute against revnums at end

login
register
mail settings
Submitter phabricator
Date May 11, 2018, 7:32 p.m.
Message ID <8cc0b11f19c176077c07361f77974cda@localhost.localdomain>
Download mbox | patch
Permalink /patch/31516/
State Not Applicable
Headers show

Comments

phabricator - May 11, 2018, 7:32 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG0db7fe7c34d3: shortest: make pure code also disambigute against revnums at end (authored by martinvonz, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D3500?vs=8553&id=8640

REVISION DETAIL
  https://phab.mercurial-scm.org/D3500

AFFECTED FILES
  mercurial/revlog.py

CHANGE DETAILS




To: martinvonz, indygreg, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -1542,31 +1542,22 @@ 
                 length = max(self.index.shortest(node), minlength)
                 return disambiguate(hexnode, length)
             except RevlogError:
-                if node == wdirid:
-                    for length in range(minlength, 41):
-                        prefix = hexnode[:length]
-                        if isvalid(prefix):
-                            return prefix
-                else:
+                if node != wdirid:
                     raise LookupError(node, self.indexfile, _('no node'))
             except AttributeError:
                 # Fall through to pure code
                 pass
 
-        shortest = hexnode
-        startlength = max(6, minlength)
-        length = startlength
-        while True:
+        if node == wdirid:
+            for length in range(minlength, 41):
+                prefix = hexnode[:length]
+                if isvalid(prefix):
+                    return prefix
+
+        for length in range(minlength, 41):
             prefix = hexnode[:length]
             if isvalid(prefix):
-                shortest = prefix
-                if length == minlength or length > startlength:
-                    return shortest
-                length -= 1
-            else:
-                length += 1
-                if len(shortest) <= length:
-                    return shortest
+                return disambiguate(hexnode, length)
 
     def cmp(self, node, text):
         """compare text with a given file revision