evolve: install progress support for the bundle2 pull path
authorPierre-Yves David <pierre-yves.david@fb.com>
Tue, 20 May 2014 22:36:47 -0700
changeset 962 d04a52f40f41
parent 961 8de88b323fb6
child 963 f80e8e3c3726
evolve: install progress support for the bundle2 pull path The custom wireprotocol command had a trick to display progress while pulling. We reinstall such logic for the new path using bundle2. Its notable that we are using the bundle2 advisory parameter for this purpose.
hgext/evolve.py
--- a/hgext/evolve.py	Tue May 20 17:21:36 2014 -0700
+++ b/hgext/evolve.py	Tue May 20 22:36:47 2014 -0700
@@ -2382,7 +2382,22 @@
 def handleobsmarkerv1(op, inpart):
     """add a stream of obsmarker to the repo"""
     tr = op.gettransaction()
-    obsdata = inpart.read()
+    advparams = dict(inpart.advisoryparams)
+    length = advparams.get('totalbytes')
+    if length is None:
+        obsdata = inpart.read()
+    else:
+        length = int(length)
+        data = StringIO()
+        current = 0
+        op.ui.progress('OBSEXC', current, unit="bytes", total=length)
+        while current < length:
+            readsize = min(length-current, 4096)
+            data.write(inpart.read(readsize))
+            current += readsize
+            op.ui.progress('OBSEXC', current, unit="bytes", total=length)
+        op.ui.progress('OBSEXC', None)
+        obsdata = data.getvalue()
     totalsize = len(obsdata)
     old = len(op.repo.obsstore._all)
     op.repo.obsstore.mergemarkers(tr, obsdata)
@@ -2429,7 +2444,10 @@
         heads = wireproto.decodelist(heads)
         obsdata = _getobsmarkersstream(repo, common=common, heads=heads)
         if len(obsdata.getvalue()) > 5:
-            obspart = bundle2.bundlepart('EVOLVE:B2X:OBSMARKERV1', data=obsdata)
+            advparams = [('totalbytes', str(len(obsdata.getvalue())))]
+            obspart = bundle2.bundlepart('EVOLVE:B2X:OBSMARKERV1',
+                                         advisoryparams=advparams,
+                                         data=obsdata)
             bundler.addpart(obspart)
     orig(bundler, repo, source)