Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/cmdutil.py @ 13400:14f3795a5ed7
explicitly close files
Add missing calls to close() to many places where files are
opened. Relying on reference counting to catch them soon-ish is not
portable and fails in environments with a proper GC, such as PyPy.
author | Dan Villiom Podlaski Christiansen <danchr@gmail.com> |
---|---|
date | Fri, 24 Dec 2010 15:23:01 +0100 |
parents | f78bc5ddbe4f |
children | 31aa2e5b0750 |
comparison
equal
deleted
inserted
replaced
13399:eff102facb15 | 13400:14f3795a5ed7 |
---|---|
677 branch = ctx.branch() | 677 branch = ctx.branch() |
678 if switch_parent: | 678 if switch_parent: |
679 parents.reverse() | 679 parents.reverse() |
680 prev = (parents and parents[0]) or nullid | 680 prev = (parents and parents[0]) or nullid |
681 | 681 |
682 shouldclose = False | |
682 if not fp: | 683 if not fp: |
684 shouldclose = True | |
683 fp = make_file(repo, template, node, total=total, seqno=seqno, | 685 fp = make_file(repo, template, node, total=total, seqno=seqno, |
684 revwidth=revwidth, mode='ab') | 686 revwidth=revwidth, mode='ab') |
685 if fp != sys.stdout and hasattr(fp, 'name'): | 687 if fp != sys.stdout and hasattr(fp, 'name'): |
686 repo.ui.note("%s\n" % fp.name) | 688 repo.ui.note("%s\n" % fp.name) |
687 | 689 |
698 fp.write("\n\n") | 700 fp.write("\n\n") |
699 | 701 |
700 for chunk in patch.diff(repo, prev, node, opts=opts): | 702 for chunk in patch.diff(repo, prev, node, opts=opts): |
701 fp.write(chunk) | 703 fp.write(chunk) |
702 | 704 |
703 fp.flush() | 705 if shouldclose: |
706 fp.close() | |
704 | 707 |
705 for seqno, rev in enumerate(revs): | 708 for seqno, rev in enumerate(revs): |
706 single(rev, seqno + 1, fp) | 709 single(rev, seqno + 1, fp) |
707 | 710 |
708 def diffordiffstat(ui, repo, diffopts, node1, node2, match, | 711 def diffordiffstat(ui, repo, diffopts, node1, node2, match, |