##// END OF EJS Templates
progress: write ui.progress() in terms of ui.makeprogress()...
Martin von Zweigbergk -
r41178:8cf92ca9 default
parent child Browse files
Show More
@@ -1439,11 +1439,46 b' class progress(object):'
1439 self.update(self.pos + step, item, total)
1439 self.update(self.pos + step, item, total)
1440
1440
1441 def complete(self):
1441 def complete(self):
1442 self.ui.progress(self.topic, None)
1442 self.pos = None
1443 self.unit = ""
1444 self.total = None
1445 self._print("")
1443
1446
1444 def _print(self, item):
1447 def _print(self, item):
1445 self.ui.progress(self.topic, self.pos, item, self.unit,
1448 if getattr(self.ui._fmsgerr, 'structured', False):
1446 self.total)
1449 # channel for machine-readable output with metadata, just send
1450 # raw information
1451 # TODO: consider porting some useful information (e.g. estimated
1452 # time) from progbar. we might want to support update delay to
1453 # reduce the cost of transferring progress messages.
1454 self.ui._fmsgerr.write(None, type=b'progress', topic=self.topic,
1455 pos=self.pos, item=item, unit=self.unit,
1456 total=self.total)
1457 elif self.ui._progbar is not None:
1458 self.ui._progbar.progress(self.topic, self.pos, item=item,
1459 unit=self.unit, total=self.total)
1460
1461 # Looking up progress.debug in tight loops is expensive. The value
1462 # is cached on the progbar object and we can avoid the lookup in
1463 # the common case where a progbar is active.
1464 if self.pos is None or not self.ui._progbar.debug:
1465 return
1466
1467 # Keep this logic in sync with above.
1468 if self.pos is None or not self.ui.configbool('progress', 'debug'):
1469 return
1470
1471 if self.unit:
1472 unit = ' ' + self.unit
1473 if item:
1474 item = ' ' + item
1475
1476 if self.total:
1477 pct = 100.0 * self.pos / self.total
1478 self.ui.debug('%s:%s %d/%d%s (%4.2f%%)\n'
1479 % (self.topic, item, self.pos, self.total, unit, pct))
1480 else:
1481 self.ui.debug('%s:%s %d%s\n' % (self.topic, item, self.pos, unit))
1447
1482
1448 def gdinitconfig(ui):
1483 def gdinitconfig(ui):
1449 """helper function to know if a repo should be created as general delta
1484 """helper function to know if a repo should be created as general delta
@@ -1691,39 +1691,11 b' class ui(object):'
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'''
General Comments 0
You need to be logged in to leave comments. Login now