diff mercurial/ui.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 aac4be30e250
children 313a940d49a3
line wrap: on
line diff
--- a/mercurial/ui.py	Sun Jun 17 18:01:49 2018 +0900
+++ b/mercurial/ui.py	Fri Jun 15 22:37:01 2018 -0700
@@ -1596,6 +1596,10 @@
         else:
             self.debug('%s:%s %d%s\n' % (topic, item, pos, unit))
 
+    def makeprogress(self, topic, unit="", total=None):
+        '''exists only so low-level modules won't need to import scmutil'''
+        return scmutil.progress(self, topic, unit, total)
+
     def log(self, service, *msg, **opts):
         '''hook for logging facility extensions