changeset 49247:3e5f1fb2aec7

revlog: make try block smaller Making try blocks as small as possible is generally a good idea, especially when catching very general errors like TypeError.
author Manuel Jacob <me@manueljacob.de>
date Mon, 30 May 2022 00:45:00 +0200
parents 31602d471b60
children 63fd0282ad40
files mercurial/revlog.py
diffstat 1 files changed, 5 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revlog.py	Mon May 30 00:39:53 2022 +0200
+++ b/mercurial/revlog.py	Mon May 30 00:45:00 2022 +0200
@@ -1525,10 +1525,13 @@
             return self._pcache[id]
 
         if len(id) <= 40:
+            # hex(node)[:...]
+            l = len(id) // 2 * 2  # grab an even number of digits
             try:
-                # hex(node)[:...]
-                l = len(id) // 2 * 2  # grab an even number of digits
                 prefix = bin(id[:l])
+            except TypeError:
+                pass
+            else:
                 nl = [e[7] for e in self.index if e[7].startswith(prefix)]
                 nl = [
                     n for n in nl if hex(n).startswith(id) and self.hasnode(n)
@@ -1545,8 +1548,6 @@
                 if maybewdir:
                     raise error.WdirUnsupported
                 return None
-            except TypeError:
-                pass
 
     def lookup(self, id):
         """locate a node based on: