revlog: make try block smaller
authorManuel Jacob <me@manueljacob.de>
Mon, 30 May 2022 00:45:00 +0200
changeset 49247 3e5f1fb2aec7
parent 49246 31602d471b60
child 49248 63fd0282ad40
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.
mercurial/revlog.py
--- 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: