Mercurial > hg
comparison mercurial/httpconnection.py @ 38393:5f9d436cd3b7
httpconnection: use progress helper
Differential Revision: https://phab.mercurial-scm.org/D3794
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Sun, 17 Jun 2018 23:11:06 -0700 |
parents | 6b1eb4c610b4 |
children | c53f0ead5781 |
comparison
equal
deleted
inserted
replaced
38392:81a4be7099fa | 38393:5f9d436cd3b7 |
---|---|
36 self.seek = self._data.seek | 36 self.seek = self._data.seek |
37 self.close = self._data.close | 37 self.close = self._data.close |
38 self.write = self._data.write | 38 self.write = self._data.write |
39 self.length = os.fstat(self._data.fileno()).st_size | 39 self.length = os.fstat(self._data.fileno()).st_size |
40 self._pos = 0 | 40 self._pos = 0 |
41 self._total = self.length // 1024 * 2 | |
42 | |
43 def read(self, *args, **kwargs): | |
44 ret = self._data.read(*args, **kwargs) | |
45 if not ret: | |
46 self.ui.progress(_('sending'), None) | |
47 return ret | |
48 self._pos += len(ret) | |
49 # We pass double the max for total because we currently have | 41 # We pass double the max for total because we currently have |
50 # to send the bundle twice in the case of a server that | 42 # to send the bundle twice in the case of a server that |
51 # requires authentication. Since we can't know until we try | 43 # requires authentication. Since we can't know until we try |
52 # once whether authentication will be required, just lie to | 44 # once whether authentication will be required, just lie to |
53 # the user and maybe the push succeeds suddenly at 50%. | 45 # the user and maybe the push succeeds suddenly at 50%. |
54 self.ui.progress(_('sending'), self._pos // 1024, | 46 self._progress = ui.makeprogress(_('sending'), unit=_('kb'), |
55 unit=_('kb'), total=self._total) | 47 total=(self.length // 1024 * 2)) |
48 | |
49 def read(self, *args, **kwargs): | |
50 ret = self._data.read(*args, **kwargs) | |
51 if not ret: | |
52 self._progress.complete() | |
53 return ret | |
54 self._pos += len(ret) | |
55 self._progress.update(self._pos // 1024) | |
56 return ret | 56 return ret |
57 | 57 |
58 def __enter__(self): | 58 def __enter__(self): |
59 return self | 59 return self |
60 | 60 |