Mercurial > hg > mercurial-source
changeset 33366:7bfa1b199972
cat: use with statement to close output file
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 27 May 2017 17:58:36 +0900 |
parents | 7f4435078a8f |
children | 746e12a767b3 |
files | mercurial/cmdutil.py |
diffstat | 1 files changed, 5 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -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.