Mercurial > public > mercurial-scm > hg-stable
diff hgext/mq.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 | 900a92862a7b |
children | 9e5df8719ad4 |
line wrap: on
line diff
--- a/hgext/mq.py Fri Feb 11 22:24:10 2011 +0800 +++ b/hgext/mq.py Fri Dec 24 15:23:01 2010 +0100 @@ -251,6 +251,7 @@ try: fh = open(os.path.join(path, 'patches.queue')) cur = fh.read().rstrip() + fh.close() if not cur: curpath = os.path.join(path, 'patches') else: @@ -1781,7 +1782,9 @@ _('need --name to import a patch from -')) text = sys.stdin.read() else: - text = url.open(self.ui, filename).read() + fp = url.open(self.ui, filename) + text = fp.read() + fp.close() except (OSError, IOError): raise util.Abort(_("unable to read file %s") % filename) if not patchname: @@ -1790,6 +1793,7 @@ checkfile(patchname) patchf = self.opener(patchname, "w") patchf.write(text) + patchf.close() if not force: checkseries(patchname) if patchname not in self.series: @@ -2787,6 +2791,7 @@ try: fh = repo.opener(_allqueues, 'r') queues = [queue.strip() for queue in fh if queue.strip()] + fh.close() if current not in queues: queues.append(current) except IOError: