changeset 51898:159854151f0f

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.
author Matt Harbison <matt_harbison@yahoo.com>
date Wed, 25 Sep 2024 00:52:44 -0400
parents 499b19683c1b
children e26a08563223
files mercurial/statichttprepo.py
diffstat 1 files changed, 2 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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