reduce memory used by util.opener when making a temp copy of a file.
authorVadim Gelfer <vadim.gelfer@gmail.com>
Tue, 09 May 2006 11:12:45 -0700
changeset 2237 4a069064a39b
parent 2236 d7f866789d7e
child 2238 25af3f17ce95
reduce memory used by util.opener when making a temp copy of a file.
mercurial/util.py
--- a/mercurial/util.py	Tue May 09 11:08:06 2006 -0700
+++ b/mercurial/util.py	Tue May 09 11:12:45 2006 -0700
@@ -685,20 +685,22 @@
         d, fn = os.path.split(name)
         fd, temp = tempfile.mkstemp(prefix='.%s-' % fn, dir=d)
         os.close(fd)
-        fp = posixfile(temp, "wb")
+        ofp = posixfile(temp, "wb")
         try:
             try:
-                s = posixfile(name, "rb").read()
+                ifp = posixfile(name, "rb")
             except IOError, inst:
                 if not getattr(inst, 'filename', None):
                     inst.filename = name
                 raise
-            fp.write(s)
+            for chunk in filechunkiter(ifp):
+                ofp.write(chunk)
+            ifp.close()
+            ofp.close()
         except:
             try: os.unlink(temp)
             except: pass
             raise
-        fp.close()
         st = os.lstat(name)
         os.chmod(temp, st.st_mode)
         return temp