Patchwork [08,of,13] largefiles: drop limitreader, use filechunkiter limit

login
register
mail settings
Submitter Mads Kiilerich
Date April 16, 2013, 2:43 a.m.
Message ID <0aaf7db2201975bcf9f5.1366080205@mk-desktop>
Download mbox | patch
Permalink /patch/1337/
State Accepted
Commit 1b84047e7d16dd1dd3695524ec55049a395a0131
Headers show

Comments

Mads Kiilerich - April 16, 2013, 2:43 a.m.
# HG changeset patch
# User Mads Kiilerich <madski@unity3d.com>
# Date 1366070157 -7200
#      Tue Apr 16 01:55:57 2013 +0200
# Node ID 0aaf7db2201975bcf9f5d82da481167b4c4c2ad6
# Parent  9e00da40bd5995bf07c7cb3df2b152ab34fb2603
largefiles: drop limitreader, use filechunkiter limit

filechunkiter.close was a noop.

Patch

diff --git a/hgext/largefiles/lfutil.py b/hgext/largefiles/lfutil.py
--- a/hgext/largefiles/lfutil.py
+++ b/hgext/largefiles/lfutil.py
@@ -309,21 +309,6 @@ 
     fd.close()
     return hasher.hexdigest()
 
-class limitreader(object):
-    def __init__(self, f, limit):
-        self.f = f
-        self.limit = limit
-
-    def read(self, length):
-        if self.limit == 0:
-            return ''
-        length = length > self.limit and self.limit or length
-        self.limit -= length
-        return self.f.read(length)
-
-    def close(self):
-        pass
-
 def writehash(hash, filename, executable):
     util.makedirs(os.path.dirname(filename))
     util.writefile(filename, hash + '\n')
diff --git a/hgext/largefiles/proto.py b/hgext/largefiles/proto.py
--- a/hgext/largefiles/proto.py
+++ b/hgext/largefiles/proto.py
@@ -123,11 +123,9 @@ 
                 self._abort(error.ResponseError(_("unexpected response:"),
                                                 length))
 
-            # Mercurial does not close its SSH connections after writing a stream
-            infile = lfutil.limitreader(stream, length)
-            for chunk in util.filechunkiter(infile, 128 * 1024):
+            # SSH streams will block if reading more than length
+            for chunk in util.filechunkiter(stream, 128 * 1024, length):
                 yield chunk
-            infile.close()
 
         @batchable
         def statlfile(self, sha):