perfrevlogwrite: use progress helper on modern hg
authorMartin von Zweigbergk <martinvonz@google.com>
Tue, 04 Dec 2018 11:22:31 -0800
changeset 41156 f36fd52dae8f
parent 41155 8c222bec97da
child 41157 c4639fdae1b9
perfrevlogwrite: use progress helper on modern hg Differential Revision: https://phab.mercurial-scm.org/D5372
contrib/perf.py
--- a/contrib/perf.py	Tue Jan 08 14:19:51 2019 -0800
+++ b/contrib/perf.py	Tue Dec 04 11:22:31 2018 -0800
@@ -1838,8 +1838,21 @@
         topic = 'adding'
         if runidx is not None:
             topic += ' (run #%d)' % runidx
+         # Support both old and new progress API
+        if util.safehasattr(ui, 'makeprogress'):
+            progress = ui.makeprogress(topic, unit='revs', total=total)
+            def updateprogress(pos):
+                progress.update(pos)
+            def completeprogress():
+                progress.complete()
+        else:
+            def updateprogress(pos):
+                ui.progress(topic, pos, unit='revs', total=total)
+            def completeprogress():
+                ui.progress(topic, None, unit='revs', total=total)
+
         for idx, rev in enumerate(revs):
-            ui.progress(topic, idx, unit='revs', total=total)
+            updateprogress(idx)
             addargs, addkwargs = _getrevisionseed(orig, rev, tr, source)
             if clearcaches:
                 dest.index.clearcaches()
@@ -1847,8 +1860,8 @@
             with timeone() as r:
                 dest.addrawrevision(*addargs, **addkwargs)
             timings.append((rev, r[0]))
-        ui.progress(topic, total, unit='revs', total=total)
-        ui.progress(topic, None, unit='revs', total=total)
+        updateprogress(total)
+        completeprogress()
     return timings
 
 def _getrevisionseed(orig, rev, tr, source):