changeset 52585:5502109ac769

churn: don't leak the file descriptor when reading the email alias file This was noticed when migrating away from `pycompat.open()` this cycle.
author Matt Harbison <matt_harbison@yahoo.com>
date Mon, 16 Dec 2024 20:04:44 -0500
parents 2d52ae3c5f76
children 058b051bc44f
files hgext/churn.py
diffstat 1 files changed, 10 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/churn.py	Mon Dec 30 12:15:52 2024 +0000
+++ b/hgext/churn.py	Mon Dec 16 20:04:44 2024 -0500
@@ -206,15 +206,16 @@
     if not aliases and os.path.exists(repo.wjoin(b'.hgchurn')):
         aliases = repo.wjoin(b'.hgchurn')
     if aliases:
-        for l in open(aliases, "rb"):
-            try:
-                alias, actual = l.rsplit(b'=' in l and b'=' or None, 1)
-                amap[alias.strip()] = actual.strip()
-            except ValueError:
-                l = l.strip()
-                if l:
-                    ui.warn(_(b"skipping malformed alias: %s\n") % l)
-                continue
+        with open(aliases, "rb") as fp:
+            for l in fp:
+                try:
+                    alias, actual = l.rsplit(b'=' in l and b'=' or None, 1)
+                    amap[alias.strip()] = actual.strip()
+                except ValueError:
+                    l = l.strip()
+                    if l:
+                        ui.warn(_(b"skipping malformed alias: %s\n") % l)
+                    continue
 
     rate = list(countrate(ui, repo, amap, *pats, **opts).items())
     if not rate: