I just thought this was clearer, but it turned out to also simplify
the next patch.
This seems to have sped up hg perfprogress from 1.85 s to 1.78 s.
( )
hg-reviewers |
I just thought this was clearer, but it turned out to also simplify
the next patch.
This seems to have sped up hg perfprogress from 1.85 s to 1.78 s.
Lint Skipped |
Unit Tests Skipped |
Path | Packages | |||
---|---|---|---|---|
M | mercurial/scmutil.py (12 lines) |
Commit | Parents | Author | Summary | Date |
---|---|---|---|---|
Martin von Zweigbergk | Jan 8 2019, 3:17 AM |
Status | Author | Revision | |
---|---|---|---|
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz |
def __exit__(self, exc_type, exc_value, exc_tb): | def __exit__(self, exc_type, exc_value, exc_tb): | ||||
self.complete() | self.complete() | ||||
def update(self, pos, item="", total=None): | def update(self, pos, item="", total=None): | ||||
assert pos is not None | assert pos is not None | ||||
if total: | if total: | ||||
self.total = total | self.total = total | ||||
self.pos = pos | self.pos = pos | ||||
self._print(item) | self._updatebar(item) | ||||
if self.debug: | |||||
self._printdebug(item) | |||||
def increment(self, step=1, item="", total=None): | def increment(self, step=1, item="", total=None): | ||||
self.update(self.pos + step, item, total) | self.update(self.pos + step, item, total) | ||||
def complete(self): | def complete(self): | ||||
self.pos = None | self.pos = None | ||||
self.unit = "" | self.unit = "" | ||||
self.total = None | self.total = None | ||||
self._print("") | self._updatebar("") | ||||
def _print(self, item): | def _updatebar(self, item): | ||||
if getattr(self.ui._fmsgerr, 'structured', False): | if getattr(self.ui._fmsgerr, 'structured', False): | ||||
# channel for machine-readable output with metadata, just send | # channel for machine-readable output with metadata, just send | ||||
# raw information | # raw information | ||||
# TODO: consider porting some useful information (e.g. estimated | # TODO: consider porting some useful information (e.g. estimated | ||||
# time) from progbar. we might want to support update delay to | # time) from progbar. we might want to support update delay to | ||||
# reduce the cost of transferring progress messages. | # reduce the cost of transferring progress messages. | ||||
self.ui._fmsgerr.write(None, type=b'progress', topic=self.topic, | self.ui._fmsgerr.write(None, type=b'progress', topic=self.topic, | ||||
pos=self.pos, item=item, unit=self.unit, | pos=self.pos, item=item, unit=self.unit, | ||||
total=self.total) | total=self.total) | ||||
elif self.ui._progbar is not None: | elif self.ui._progbar is not None: | ||||
self.ui._progbar.progress(self.topic, self.pos, item=item, | self.ui._progbar.progress(self.topic, self.pos, item=item, | ||||
unit=self.unit, total=self.total) | unit=self.unit, total=self.total) | ||||
if self.pos is None or not self.debug: | def _printdebug(self, item): | ||||
return | |||||
if self.unit: | if self.unit: | ||||
unit = ' ' + self.unit | unit = ' ' + self.unit | ||||
if item: | if item: | ||||
item = ' ' + item | item = ' ' + item | ||||
if self.total: | if self.total: | ||||
pct = 100.0 * self.pos / self.total | pct = 100.0 * self.pos / self.total | ||||
self.ui.debug('%s:%s %d/%d%s (%4.2f%%)\n' | self.ui.debug('%s:%s %d/%d%s (%4.2f%%)\n' |