diff hgext/convert/monotone.py @ 51683:1eab9e40c0c8

convert: fix various leaked file descriptors Some of these only leaked if an exception occurred between the open and close, but a lot of these leaked unconditionally. A type hint is added to `parsesplicemap` because otherwise this change caused pytype to change the return type from this to `Dict[nothing, nothing]`.
author Matt Harbison <matt_harbison@yahoo.com>
date Thu, 11 Jul 2024 21:54:02 -0400
parents e63ab79b2fa1
children f1ef512e14ab
line wrap: on
line diff
--- a/hgext/convert/monotone.py	Thu Jul 11 21:16:45 2024 -0400
+++ b/hgext/convert/monotone.py	Thu Jul 11 21:54:02 2024 -0400
@@ -43,9 +43,8 @@
         if not os.path.exists(os.path.join(path, b'_MTN')):
             # Could be a monotone repository (SQLite db file)
             try:
-                f = open(path, b'rb')
-                header = f.read(16)
-                f.close()
+                with open(path, b'rb') as f:
+                    header = f.read(16)
             except IOError:
                 header = b''
             if header != b'SQLite format 3\x00':