comparison mercurial/scmutil.py @ 38345:bec1212eceaa

progress: create helper class for incrementing progress When using ui.progress(), there's a clear pattern that is followed: * Pass the same topic and unit * Usually pass the same total * Call with pos=None to close the progress bar * Often keep track of the current position and increment it This patch creates a simple helper class for this. I'll probably make it implement the context manager protocol later (calling update(None) on __exit__). Progress is used in low-level modules like changegroup, so I also exposed it via a method on the ui object. Perhaps the class itself should also live in ui.py? This patch also makes merge.oy use it to show that it works. Differential Revision: https://phab.mercurial-scm.org/D3765
author Martin von Zweigbergk <martinvonz@google.com>
date Fri, 15 Jun 2018 22:37:01 -0700
parents cf59de802883
children ef692614e601
comparison
equal deleted inserted replaced
38344:c6f82a18a63d 38345:bec1212eceaa
1283 arguments that ui.system does, and returns the exit code of the 1283 arguments that ui.system does, and returns the exit code of the
1284 subprocess.""" 1284 subprocess."""
1285 return _locksub(repo, repo.currentwlock(), 'HG_WLOCK_LOCKER', cmd, *args, 1285 return _locksub(repo, repo.currentwlock(), 'HG_WLOCK_LOCKER', cmd, *args,
1286 **kwargs) 1286 **kwargs)
1287 1287
1288 class progress(object):
1289 def __init__(self, ui, topic, unit="", total=None):
1290 self.ui = ui
1291 self.pos = 0
1292 self.topic = topic
1293 self.unit = unit
1294 self.total = total
1295
1296 def update(self, pos, item="", total=None):
1297 if total:
1298 self.total = total
1299 self.pos = pos
1300 self._print(item)
1301
1302 def increment(self, step=1, item="", total=None):
1303 self.update(self.pos + step, item, total)
1304
1305 def _print(self, item):
1306 self.ui.progress(self.topic, self.pos, item, self.unit,
1307 self.total)
1308
1288 def gdinitconfig(ui): 1309 def gdinitconfig(ui):
1289 """helper function to know if a repo should be created as general delta 1310 """helper function to know if a repo should be created as general delta
1290 """ 1311 """
1291 # experimental config: format.generaldelta 1312 # experimental config: format.generaldelta
1292 return (ui.configbool('format', 'generaldelta') 1313 return (ui.configbool('format', 'generaldelta')