crecord: don't leak a file descriptor when I/O fails
Also put a comment here, because I initially thought opening in non-binary mode
was a mistake, but 7cc913396f8c did it purposely.
--- a/mercurial/crecord.py Mon Dec 16 21:30:02 2024 -0500
+++ b/mercurial/crecord.py Tue Dec 17 00:47:42 2024 -0500
@@ -622,10 +622,10 @@
chunkselector.stdscr = dummystdscr()
if testfn and os.path.exists(testfn):
- testf = open(testfn, 'r')
- # TODO: open in binary mode?
- testcommands = [x.rstrip('\n') for x in testf.readlines()]
- testf.close()
+ # This file is purposely NOT opened in binary mode
+ with open(testfn, 'r') as testf:
+ testcommands = [x.rstrip('\n') for x in testf.readlines()]
+
while True:
if chunkselector.handlekeypressed(testcommands.pop(0), test=True):
break