# HG changeset patch # User Yuya Nishihara # Date 2017-05-27 08:58:36 # Node ID 7bfa1b199972a347f8c58095c9263fd34297775e # Parent 7f4435078a8f182b05b4f9450dd15255f2fdaa3f cat: use with statement to close output file diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -2642,11 +2642,11 @@ def cat(ui, repo, ctx, matcher, fntempla 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.