[PATCH 8 of 8] commandserver: send raw progress information to message channel

Yuya Nishihara yuya at tcha.org
Thu Nov 8 09:24:46 EST 2018


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1541303474 -32400
#      Sun Nov 04 12:51:14 2018 +0900
# Node ID c116648678800a03858bfd3f5c2798335392034b
# Parent  b7781ccecdcdf9021ea3e6cadf6039be2f8c613e
commandserver: send raw progress information to message channel

This is pretty basic implementation to support GUI progress bar.

diff --git a/mercurial/commandserver.py b/mercurial/commandserver.py
--- a/mercurial/commandserver.py
+++ b/mercurial/commandserver.py
@@ -93,7 +93,8 @@ class channeledmessage(object):
 
     def write(self, data, **opts):
         opts = pycompat.byteskwargs(opts)
-        opts[b'data'] = data
+        if data is not None:
+            opts[b'data'] = data
         self._cout.write(self._encodefn(opts))
 
     def __getattr__(self, attr):
diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -1678,7 +1678,15 @@ class ui(object):
         All topics should be marked closed by setting pos to None at
         termination.
         '''
-        if self._progbar is not None:
+        if getattr(self._fmsgerr, 'structured', False):
+            # channel for machine-readable output with metadata, just send
+            # raw information
+            # TODO: consider porting some useful information (e.g. estimated
+            # time) from progbar. we might want to support update delay to
+            # reduce the cost of transferring progress messages.
+            self._fmsgerr.write(None, type=b'progress', topic=topic, pos=pos,
+                                item=item, unit=unit, total=total)
+        elif self._progbar is not None:
             self._progbar.progress(topic, pos, item=item, unit=unit,
                                    total=total)
         if pos is None or not self.configbool('progress', 'debug'):
diff --git a/tests/test-commandserver.t b/tests/test-commandserver.t
--- a/tests/test-commandserver.t
+++ b/tests/test-commandserver.t
@@ -750,9 +750,13 @@ structured message channel:
   pgid: * (glob)
   *** runcommand -R repo2 verify
   message: '\xa2DdataTchecking changesets\nDtypeFstatus'
+  message: '\xa6Ditem at Cpos\xf6EtopicHcheckingEtotal\xf6DtypeHprogressDunit@'
   message: '\xa2DdataSchecking manifests\nDtypeFstatus'
+  message: '\xa6Ditem at Cpos\xf6EtopicHcheckingEtotal\xf6DtypeHprogressDunit@'
   message: '\xa2DdataX0crosschecking files in changesets and manifests\nDtypeFstatus'
+  message: '\xa6Ditem at Cpos\xf6EtopicMcrosscheckingEtotal\xf6DtypeHprogressDunit@'
   message: '\xa2DdataOchecking files\nDtypeFstatus'
+  message: '\xa6Ditem at Cpos\xf6EtopicHcheckingEtotal\xf6DtypeHprogressDunit@'
   message: '\xa2DdataX/checked 0 changesets with 0 changes to 0 files\nDtypeFstatus'
 
   >>> from hgclient import checkwith, readchannel, runcommand, stringio


More information about the Mercurial-devel mailing list