diff hgext3rd/pullbundle.py @ 5044:b9179a034005

pullbundle: compatibility for progress in hg <= 4.6
author Anton Shestakov <av6@dwimlabs.net>
date Thu, 19 Dec 2019 18:02:31 +0700
parents 1015a1dbaf7c
children ebd0f5c6098f
line wrap: on
line diff
--- a/hgext3rd/pullbundle.py	Thu Dec 19 18:01:15 2019 +0700
+++ b/hgext3rd/pullbundle.py	Thu Dec 19 18:02:31 2019 +0700
@@ -87,6 +87,7 @@
     node as nodemod,
     registrar,
     scmutil,
+    ui as uimod,
     util,
 )
 
@@ -508,7 +509,7 @@
     if 1 < min_cache:
         repo.ui.write(b"  not caching ranges smaller than %d changesets\n" % min_cache)
     for i in range(count):
-        repo.ui.progress(b'gathering data', i, total=count)
+        progress(repo.ui, b'gathering data', i, total=count)
         outgoing = takeonesample(repo, actionrevs)
         ranges = sliceoutgoing(repo, outgoing)
         hitranges = 0
@@ -532,7 +533,7 @@
                  hitranges,
                  )
         pullstats.append(stats)
-    repo.ui.progress(b'gathering data', None)
+    progress(repo.ui, b'gathering data', None)
 
     sizes = []
     changesmissing = []
@@ -624,6 +625,18 @@
 def fmtdist(name, data):
     return STATSFORMAT.format(name=name, **data)
 
+# hg <= 4.6 (bec1212eceaa)
+if util.safehasattr(uimod.ui, 'makeprogress'):
+    def progress(ui, topic, pos, item=b"", unit=b"", total=None):
+        progress = ui.makeprogress(topic, unit, total)
+        if pos is not None:
+            progress.update(pos, item=item)
+        else:
+            progress.complete()
+else:
+    def progress(ui, topic, pos, item=b"", unit=b"", total=None):
+        ui.progress(topic, pos, item, unit, total)
+
 # nodemap.get and index.[has_node|rev|get_rev]
 # hg <= 5.3 (02802fa87b74)
 def getgetrev(cl):