Mercurial > public > mercurial-scm > hg-stable
diff 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 |
line wrap: on
line diff
--- a/mercurial/cmdutil.py Fri Feb 11 22:24:10 2011 +0800 +++ b/mercurial/cmdutil.py Fri Dec 24 15:23:01 2010 +0100 @@ -679,7 +679,9 @@ parents.reverse() prev = (parents and parents[0]) or nullid + shouldclose = False if not fp: + shouldclose = True fp = make_file(repo, template, node, total=total, seqno=seqno, revwidth=revwidth, mode='ab') if fp != sys.stdout and hasattr(fp, 'name'): @@ -700,7 +702,8 @@ for chunk in patch.diff(repo, prev, node, opts=opts): fp.write(chunk) - fp.flush() + if shouldclose: + fp.close() for seqno, rev in enumerate(revs): single(rev, seqno + 1, fp)