# HG changeset patch # User Martin von Zweigbergk # Date 2019-01-08 08:30:30 # Node ID 963462786f6e028563bcedc9008622e0f3b59c86 # Parent 3025fd3c2e71a64125affe558c24181ec1305281 progress: check what type of progress bar to use only once per topic This seems to have sped up `hg perfprogress` from 1.78 s to 1.41 s. Differential Revision: https://phab.mercurial-scm.org/D5530 diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py --- a/mercurial/scmutil.py +++ b/mercurial/scmutil.py @@ -1422,6 +1422,24 @@ class progress(object): self.unit = unit self.total = total self.debug = ui.configbool('progress', 'debug') + if getattr(ui._fmsgerr, 'structured', False): + # channel for machine-readable output with metadata, just send + # raw information + # TODO: consider porting some useful information (e.g. estimated + # time) from progbar. we might want to support update delay to + # reduce the cost of transferring progress messages. + def updatebar(item): + ui._fmsgerr.write(None, type=b'progress', topic=self.topic, + pos=self.pos, item=item, unit=self.unit, + total=self.total) + elif ui._progbar is not None: + def updatebar(item): + ui._progbar.progress(self.topic, self.pos, item=item, + unit=self.unit, total=self.total) + else: + def updatebar(item): + pass + self._updatebar = updatebar def __enter__(self): return self @@ -1447,20 +1465,6 @@ class progress(object): self.total = None self._updatebar("") - def _updatebar(self, item): - if getattr(self.ui._fmsgerr, 'structured', False): - # channel for machine-readable output with metadata, just send - # raw information - # TODO: consider porting some useful information (e.g. estimated - # time) from progbar. we might want to support update delay to - # reduce the cost of transferring progress messages. - self.ui._fmsgerr.write(None, type=b'progress', topic=self.topic, - pos=self.pos, item=item, unit=self.unit, - total=self.total) - elif self.ui._progbar is not None: - self.ui._progbar.progress(self.topic, self.pos, item=item, - unit=self.unit, total=self.total) - def _printdebug(self, item): if self.unit: unit = ' ' + self.unit