changeset 19001:2a35296a6304

largefiles: drop lfutil.blockstream - use filechunkiter like everybody else The old chunk size is kept - just to avoid changing it.
author Mads Kiilerich <madski@unity3d.com>
date Mon, 15 Apr 2013 23:43:44 +0200
parents eaf146e811a4
children 5083baa6cbf8
files hgext/largefiles/lfutil.py hgext/largefiles/overrides.py hgext/largefiles/remotestore.py
diffstat 3 files changed, 7 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/largefiles/lfutil.py	Mon Apr 15 23:35:43 2013 +0200
+++ b/hgext/largefiles/lfutil.py	Mon Apr 15 23:43:44 2013 +0200
@@ -311,7 +311,7 @@
         return ''
     hasher = util.sha1('')
     fd = open(file, 'rb')
-    for data in blockstream(fd):
+    for data in util.filechunkiter(fd, 128 * 1024):
         hasher.update(data)
     fd.close()
     return hasher.hexdigest()
@@ -331,16 +331,6 @@
     def close(self):
         pass
 
-def blockstream(infile, blocksize=128 * 1024):
-    """Generator that yields blocks of data from infile and closes infile."""
-    while True:
-        data = infile.read(blocksize)
-        if not data:
-            break
-        yield data
-    # same blecch as copyandhash() above
-    infile.close()
-
 def writehash(hash, filename, executable):
     util.makedirs(os.path.dirname(filename))
     util.writefile(filename, hash + '\n')
--- a/hgext/largefiles/overrides.py	Mon Apr 15 23:35:43 2013 +0200
+++ b/hgext/largefiles/overrides.py	Mon Apr 15 23:43:44 2013 +0200
@@ -1198,7 +1198,7 @@
                           'downloaded')  % lf)
             path = lfutil.usercachepath(repo.ui, hash)
             fpin = open(path, "rb")
-            for chunk in lfutil.blockstream(fpin):
+            for chunk in util.filechunkiter(fpin, 128 * 1024):
                 fp.write(chunk)
             fpin.close()
         fp.close()
--- a/hgext/largefiles/remotestore.py	Mon Apr 15 23:35:43 2013 +0200
+++ b/hgext/largefiles/remotestore.py	Mon Apr 15 23:43:44 2013 +0200
@@ -74,7 +74,11 @@
         # Mercurial does not close its SSH connections after writing a stream
         if length is not None:
             infile = lfutil.limitreader(infile, length)
-        return lfutil.copyandhash(lfutil.blockstream(infile), tmpfile)
+        try:
+            return lfutil.copyandhash(util.filechunkiter(infile, 128 * 1024),
+                                      tmpfile)
+        finally:
+            infile.close()
 
     def _verifyfile(self, cctx, cset, contents, standin, verified):
         filename = lfutil.splitstandin(standin)