statichttprepo: use a context manager to handle a file descriptor
authorMatt Harbison <matt_harbison@yahoo.com>
Wed, 25 Sep 2024 00:52:44 -0400
changeset 51935 159854151f0f
parent 51934 499b19683c1b
child 51936 e26a08563223
statichttprepo: use a context manager to handle a file descriptor I'm not sure if this should be reduced to `vfs.exists()`. That would seem to be equivalent code (since the result of the read is ignored, so we can't tell if the file actually has content, which has been the state of things going back to 98b6c3dde237), but this is at least safer file descriptor handling.
mercurial/statichttprepo.py
--- a/mercurial/statichttprepo.py	Thu Sep 26 02:58:50 2024 +0200
+++ b/mercurial/statichttprepo.py	Wed Sep 25 00:52:44 2024 -0400
@@ -192,9 +192,8 @@
 
             # check if it is a non-empty old-style repository
             try:
-                fp = self.vfs(b"00changelog.i")
-                fp.read(1)
-                fp.close()
+                with self.vfs(b"00changelog.i") as fp:
+                    fp.read(1)
             except FileNotFoundError:
                 # we do not care about empty old-style repositories here
                 msg = _(b"'%s' does not appear to be an hg repository") % path