cat: use with statement to close output file
authorYuya Nishihara <yuya@tcha.org>
Sat, 27 May 2017 17:58:36 +0900
changeset 32609 7bfa1b199972
parent 32608 7f4435078a8f
child 32610 746e12a767b3
cat: use with statement to close output file
mercurial/cmdutil.py
--- a/mercurial/cmdutil.py	Thu May 25 21:43:09 2017 +0900
+++ b/mercurial/cmdutil.py	Sat May 27 17:58:36 2017 +0900
@@ -2642,11 +2642,11 @@
             fp = open(filename, 'wb')
         else:
             fp = _unclosablefile(ui.fout)
-        data = ctx[path].data()
-        if opts.get('decode'):
-            data = repo.wwritedata(path, data)
-        fp.write(data)
-        fp.close()
+        with fp:
+            data = ctx[path].data()
+            if opts.get('decode'):
+                data = repo.wwritedata(path, data)
+            fp.write(data)
 
     # Automation often uses hg cat on single files, so special case it
     # for performance to avoid the cost of parsing the manifest.