Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/ui.py @ 41143:8cf92ca92bfe
progress: write ui.progress() in terms of ui.makeprogress()
I think ui.makeprogress() should be the preferred interface and we
should deprecate ui.progress(). All in-core callers already use
ui.makeprogress(). Moving the logic to the scmutil.progress() will let
us make further improvements.
This seems to have sped up `hg perfprogress` from 1.92 s to 1.85 s,
perhaps because we now skip the indirection of updating the progress
bar via ui.progress().
Differential Revision: https://phab.mercurial-scm.org/D5527
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Mon, 07 Jan 2019 23:55:26 -0800 |
parents | 8ecb17b7f432 |
children | 929999d963b8 |
comparison
equal
deleted
inserted
replaced
41142:89d103fc9c19 | 41143:8cf92ca92bfe |
---|---|
1689 Multiple nested topics may be active at a time. | 1689 Multiple nested topics may be active at a time. |
1690 | 1690 |
1691 All topics should be marked closed by setting pos to None at | 1691 All topics should be marked closed by setting pos to None at |
1692 termination. | 1692 termination. |
1693 ''' | 1693 ''' |
1694 if getattr(self._fmsgerr, 'structured', False): | 1694 progress = self.makeprogress(topic, unit, total) |
1695 # channel for machine-readable output with metadata, just send | 1695 if pos is not None: |
1696 # raw information | 1696 progress.update(pos, item=item) |
1697 # TODO: consider porting some useful information (e.g. estimated | |
1698 # time) from progbar. we might want to support update delay to | |
1699 # reduce the cost of transferring progress messages. | |
1700 self._fmsgerr.write(None, type=b'progress', topic=topic, pos=pos, | |
1701 item=item, unit=unit, total=total) | |
1702 elif self._progbar is not None: | |
1703 self._progbar.progress(topic, pos, item=item, unit=unit, | |
1704 total=total) | |
1705 | |
1706 # Looking up progress.debug in tight loops is expensive. The value | |
1707 # is cached on the progbar object and we can avoid the lookup in | |
1708 # the common case where a progbar is active. | |
1709 if pos is None or not self._progbar.debug: | |
1710 return | |
1711 | |
1712 # Keep this logic in sync with above. | |
1713 if pos is None or not self.configbool('progress', 'debug'): | |
1714 return | |
1715 | |
1716 if unit: | |
1717 unit = ' ' + unit | |
1718 if item: | |
1719 item = ' ' + item | |
1720 | |
1721 if total: | |
1722 pct = 100.0 * pos / total | |
1723 self.debug('%s:%s %d/%d%s (%4.2f%%)\n' | |
1724 % (topic, item, pos, total, unit, pct)) | |
1725 else: | 1697 else: |
1726 self.debug('%s:%s %d%s\n' % (topic, item, pos, unit)) | 1698 progress.complete() |
1727 | 1699 |
1728 def makeprogress(self, topic, unit="", total=None): | 1700 def makeprogress(self, topic, unit="", total=None): |
1729 '''exists only so low-level modules won't need to import scmutil''' | 1701 '''exists only so low-level modules won't need to import scmutil''' |
1730 return scmutil.progress(self, topic, unit, total) | 1702 return scmutil.progress(self, topic, unit, total) |
1731 | 1703 |