Patchwork D3461: shortest: don't keep checking for longer prefix if node doesn't exist (API)

login
register
mail settings
Submitter phabricator
Date May 8, 2018, 12:47 p.m.
Message ID <99d450b1964c3dc852fa751823b06cb2@localhost.localdomain>
Download mbox | patch
Permalink /patch/31344/
State Not Applicable
Headers show

Comments

phabricator - May 8, 2018, 12:47 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHGda083d9fafab: shortest: don&#039;t keep checking for longer prefix if node doesn&#039;t exist (API) (authored by martinvonz, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D3461?vs=8486&id=8515

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

AFFECTED FILES
  mercurial/revlog.py
  mercurial/scmutil.py
  mercurial/templatefuncs.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/templatefuncs.py b/mercurial/templatefuncs.py
--- a/mercurial/templatefuncs.py
+++ b/mercurial/templatefuncs.py
@@ -608,7 +608,10 @@ 
             return hexnode
         if not node:
             return hexnode
-    return scmutil.shortesthexnodeidprefix(repo, node, minlength)
+    try:
+        return scmutil.shortesthexnodeidprefix(repo, node, minlength)
+    except error.RepoLookupError:
+        return hexnode
 
 @templatefunc('strip(text[, chars])')
 def strip(context, mapping, args):
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -448,7 +448,10 @@ 
     # _partialmatch() of filtered changelog could take O(len(repo)) time,
     # which would be unacceptably slow. so we look for hash collision in
     # unfiltered space, which means some hashes may be slightly longer.
-    return repo.unfiltered().changelog.shortest(node, minlength)
+    try:
+        return repo.unfiltered().changelog.shortest(node, minlength)
+    except error.LookupError:
+        raise error.RepoLookupError()
 
 def isrevsymbol(repo, symbol):
     """Checks if a symbol exists in the repo.
diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -1516,13 +1516,14 @@ 
 
         def isvalid(prefix):
             try:
-                if self._partialmatch(prefix) is None:
-                    return False
+                node = self._partialmatch(prefix)
             except error.RevlogError:
                 return False
             except error.WdirUnsupported:
                 # single 'ff...' match
                 return True
+            if node is None:
+                raise LookupError(node, self.indexfile, _('no node'))
             return not isrev(prefix)
 
         hexnode = hex(node)