Details
Details
- Reviewers
pulkit - Group Reviewers
hg-reviewers - Commits
- rHG5f9d436cd3b7: httpconnection: use progress helper
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
( )
| pulkit |
| hg-reviewers |
| Lint Skipped |
| Unit Tests Skipped |
| Path | Packages | |||
|---|---|---|---|---|
| M | mercurial/httpconnection.py (20 lines) |
| Commit | Parents | Author | Summary | Date |
|---|---|---|---|---|
| Martin von Zweigbergk | Jun 18 2018, 2:11 AM |
| Status | Author | Revision | |
|---|---|---|---|
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz |
| def __init__(self, ui, *args, **kwargs): | def __init__(self, ui, *args, **kwargs): | ||||
| self.ui = ui | self.ui = ui | ||||
| self._data = open(*args, **kwargs) | self._data = open(*args, **kwargs) | ||||
| self.seek = self._data.seek | self.seek = self._data.seek | ||||
| self.close = self._data.close | self.close = self._data.close | ||||
| self.write = self._data.write | self.write = self._data.write | ||||
| self.length = os.fstat(self._data.fileno()).st_size | self.length = os.fstat(self._data.fileno()).st_size | ||||
| self._pos = 0 | self._pos = 0 | ||||
| self._total = self.length // 1024 * 2 | # 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._progress = ui.makeprogress(_('sending'), unit=_('kb'), | |||||
| total=(self.length // 1024 * 2)) | |||||
| def read(self, *args, **kwargs): | def read(self, *args, **kwargs): | ||||
| ret = self._data.read(*args, **kwargs) | ret = self._data.read(*args, **kwargs) | ||||
| if not ret: | if not ret: | ||||
| self.ui.progress(_('sending'), None) | self._progress.complete() | ||||
| return ret | return ret | ||||
| self._pos += len(ret) | self._pos += len(ret) | ||||
| # We pass double the max for total because we currently have | self._progress.update(self._pos // 1024) | ||||
| # 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=self._total) | |||||
| return ret | return ret | ||||
| def __enter__(self): | def __enter__(self): | ||||
| return self | return self | ||||
| def __exit__(self, exc_type, exc_val, exc_tb): | def __exit__(self, exc_type, exc_val, exc_tb): | ||||
| self.close() | self.close() | ||||