[PATCH 1 of 8] httpsendfile: record progress information during read()
Augie Fackler
durin42 at gmail.com
Thu Dec 9 17:41:01 CST 2010
# HG changeset patch
# User Augie Fackler <durin42 at gmail.com>
# Date 1291005558 21600
# Node ID a6a1d02d1d1ad2d936a8a8324b5bb814d6bab480
# Parent 5dac0d04b838d599acdc5db9ee0b7de51de15537
httpsendfile: record progress information during read()
diff --git a/mercurial/httprepo.py b/mercurial/httprepo.py
--- a/mercurial/httprepo.py
+++ b/mercurial/httprepo.py
@@ -160,7 +160,7 @@
break
tempname = changegroup.writebundle(cg, None, type)
- fp = url.httpsendfile(tempname, "rb")
+ fp = url.httpsendfile(self.ui, tempname, "rb")
headers = {'Content-Type': 'application/mercurial-0.1'}
try:
diff --git a/mercurial/url.py b/mercurial/url.py
--- a/mercurial/url.py
+++ b/mercurial/url.py
@@ -258,18 +258,35 @@
defines a __len__ attribute to feed the Content-Length header.
"""
- def __init__(self, *args, **kwargs):
+ def __init__(self, ui, *args, **kwargs):
# We can't just "self._data = open(*args, **kwargs)" here because there
# is an "open" function defined in this module that shadows the global
# one
+ self.ui = ui
self._data = __builtin__.open(*args, **kwargs)
- self.read = self._data.read
self.seek = self._data.seek
self.close = self._data.close
self.write = self._data.write
+ self._len = os.fstat(self._data.fileno()).st_size
+ self._pos = 0
+
+ def read(self, *args, **kwargs):
+ try:
+ ret = self._data.read(*args, **kwargs)
+ except EOFError:
+ self.ui.progress(_('sending'), None)
+ self._pos += len(ret)
+ # We pass double the max for total because we currently have
+ # to send the bundle twice in the case of a server that
+ # requires authentication. Since we can't know until we try
+ # once whether authentication will be required, just lie to
+ # the user and maybe the push succeeds suddenly at 50%.
+ self.ui.progress(_('sending'), self._pos/1024,
+ unit=_('kb'), total=(len(self)/1024)*2)
+ return ret
def __len__(self):
- return os.fstat(self._data.fileno()).st_size
+ return self._len
def _gen_sendfile(connection):
def _sendfile(self, data):
More information about the Mercurial-devel
mailing list