changeset 27771:338c9d227a9e

commands: use a context manager for file I/O in debugdiscovery
author Bryan O'Sullivan <bryano@fb.com>
date Tue, 12 Jan 2016 14:28:43 -0800
parents 1b8c7d59be43
children 00bd72629a45
files mercurial/commands.py
diffstat 1 files changed, 1 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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'))