pullbundle: compatibility for progress in hg <= 4.6
authorAnton Shestakov <av6@dwimlabs.net>
Thu, 19 Dec 2019 18:02:31 +0700
changeset 5044 b9179a034005
parent 5043 db341dafdccb
child 5045 c9b25b1d6a61
pullbundle: compatibility for progress in hg <= 4.6
hgext3rd/pullbundle.py
--- 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):