Mercurial > public > mercurial-scm > hg
comparison mercurial/cmdutil.py @ 32583: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 |
comparison
equal
deleted
inserted
replaced
32582:7f4435078a8f | 32583:7bfa1b199972 |
---|---|
2640 filename = makefilename(repo, fntemplate, ctx.node(), | 2640 filename = makefilename(repo, fntemplate, ctx.node(), |
2641 pathname=os.path.join(prefix, path)) | 2641 pathname=os.path.join(prefix, path)) |
2642 fp = open(filename, 'wb') | 2642 fp = open(filename, 'wb') |
2643 else: | 2643 else: |
2644 fp = _unclosablefile(ui.fout) | 2644 fp = _unclosablefile(ui.fout) |
2645 data = ctx[path].data() | 2645 with fp: |
2646 if opts.get('decode'): | 2646 data = ctx[path].data() |
2647 data = repo.wwritedata(path, data) | 2647 if opts.get('decode'): |
2648 fp.write(data) | 2648 data = repo.wwritedata(path, data) |
2649 fp.close() | 2649 fp.write(data) |
2650 | 2650 |
2651 # Automation often uses hg cat on single files, so special case it | 2651 # Automation often uses hg cat on single files, so special case it |
2652 # for performance to avoid the cost of parsing the manifest. | 2652 # for performance to avoid the cost of parsing the manifest. |
2653 if len(matcher.files()) == 1 and not matcher.anypats(): | 2653 if len(matcher.files()) == 1 and not matcher.anypats(): |
2654 file = matcher.files()[0] | 2654 file = matcher.files()[0] |