commands: use a context manager for file I/O in debugdiscovery
authorBryan O'Sullivan <bryano@fb.com>
Tue, 12 Jan 2016 14:28:43 -0800
changeset 27771 338c9d227a9e
parent 27770 1b8c7d59be43
child 27772 00bd72629a45
commands: use a context manager for file I/O in debugdiscovery
mercurial/commands.py
--- a/mercurial/commands.py	Tue Jan 12 14:28:16 2016 -0800
+++ b/mercurial/commands.py	Tue Jan 12 14:28:43 2016 -0800
@@ -2311,8 +2311,7 @@
     serverlogs = opts.get('serverlog')
     if serverlogs:
         for filename in serverlogs:
-            logfile = open(filename, 'r')
-            try:
+            with open(filename, 'r') as logfile:
                 line = logfile.readline()
                 while line:
                     parts = line.strip().split(';')
@@ -2324,9 +2323,6 @@
                     elif op == 'unb':
                         doit(parts[3].split(' '), parts[2].split(' '))
                     line = logfile.readline()
-            finally:
-                logfile.close()
-
     else:
         remoterevs, _checkout = hg.addbranchrevs(repo, remote, branches,
                                                  opts.get('remote_head'))