comparison mercurial/scmutil.py @ 41209:b223fc1c6b4c

progress: change _updatebar() to take parameters as arguments I want to move updatebar() back to ui. See the next patch for why.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 13 Jan 2019 14:21:35 +0900
parents 963462786f6e
children 929999d963b8
comparison
equal deleted inserted replaced
41208:d9eda1c6dfca 41209:b223fc1c6b4c
1426 # channel for machine-readable output with metadata, just send 1426 # channel for machine-readable output with metadata, just send
1427 # raw information 1427 # raw information
1428 # TODO: consider porting some useful information (e.g. estimated 1428 # TODO: consider porting some useful information (e.g. estimated
1429 # time) from progbar. we might want to support update delay to 1429 # time) from progbar. we might want to support update delay to
1430 # reduce the cost of transferring progress messages. 1430 # reduce the cost of transferring progress messages.
1431 def updatebar(item): 1431 def updatebar(topic, pos, item, unit, total):
1432 ui._fmsgerr.write(None, type=b'progress', topic=self.topic, 1432 ui._fmsgerr.write(None, type=b'progress', topic=topic,
1433 pos=self.pos, item=item, unit=self.unit, 1433 pos=pos, item=item, unit=unit,
1434 total=self.total) 1434 total=total)
1435 elif ui._progbar is not None: 1435 elif ui._progbar is not None:
1436 def updatebar(item): 1436 updatebar = ui._progbar.progress
1437 ui._progbar.progress(self.topic, self.pos, item=item,
1438 unit=self.unit, total=self.total)
1439 else: 1437 else:
1440 def updatebar(item): 1438 def updatebar(topic, pos, item, unit, total):
1441 pass 1439 pass
1442 self._updatebar = updatebar 1440 self._updatebar = updatebar
1443 1441
1444 def __enter__(self): 1442 def __enter__(self):
1445 return self 1443 return self
1450 def update(self, pos, item="", total=None): 1448 def update(self, pos, item="", total=None):
1451 assert pos is not None 1449 assert pos is not None
1452 if total: 1450 if total:
1453 self.total = total 1451 self.total = total
1454 self.pos = pos 1452 self.pos = pos
1455 self._updatebar(item) 1453 self._updatebar(self.topic, self.pos, item, self.unit, self.total)
1456 if self.debug: 1454 if self.debug:
1457 self._printdebug(item) 1455 self._printdebug(item)
1458 1456
1459 def increment(self, step=1, item="", total=None): 1457 def increment(self, step=1, item="", total=None):
1460 self.update(self.pos + step, item, total) 1458 self.update(self.pos + step, item, total)
1461 1459
1462 def complete(self): 1460 def complete(self):
1463 self.pos = None 1461 self.pos = None
1464 self.unit = "" 1462 self.unit = ""
1465 self.total = None 1463 self.total = None
1466 self._updatebar("") 1464 self._updatebar(self.topic, self.pos, "", self.unit, self.total)
1467 1465
1468 def _printdebug(self, item): 1466 def _printdebug(self, item):
1469 if self.unit: 1467 if self.unit:
1470 unit = ' ' + self.unit 1468 unit = ' ' + self.unit
1471 if item: 1469 if item: