[PATCH 04 of 13] largefiles: drop lfutil.blockstream - use filechunkiter like everybody else
Mads Kiilerich
mads at kiilerich.com
Mon Apr 15 21:43:21 CDT 2013
# HG changeset patch
# User Mads Kiilerich <madski at unity3d.com>
# Date 1366062224 -7200
# Mon Apr 15 23:43:44 2013 +0200
# Node ID 2b554516b0868563d22f3907ca3498ce970725b0
# Parent 889ccb073d7e346d761c6487f00003cf825edad9
largefiles: drop lfutil.blockstream - use filechunkiter like everybody else
The old chunk size is kept - just to avoid changing it.
diff --git a/hgext/largefiles/lfutil.py b/hgext/largefiles/lfutil.py
--- a/hgext/largefiles/lfutil.py
+++ b/hgext/largefiles/lfutil.py
@@ -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')
diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py
--- a/hgext/largefiles/overrides.py
+++ b/hgext/largefiles/overrides.py
@@ -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()
diff --git a/hgext/largefiles/remotestore.py b/hgext/largefiles/remotestore.py
--- a/hgext/largefiles/remotestore.py
+++ b/hgext/largefiles/remotestore.py
@@ -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)
More information about the Mercurial-devel
mailing list