changeset 40641:234c2d8c9e48

commandserver: send raw progress information to message channel This is pretty basic implementation to support GUI progress bar.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 04 Nov 2018 12:51:14 +0900
parents 6f0941f4a184
children 419d703115b0
files mercurial/commandserver.py mercurial/ui.py tests/test-commandserver.t
diffstat 3 files changed, 15 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commandserver.py	Sun Nov 04 12:38:49 2018 +0900
+++ b/mercurial/commandserver.py	Sun Nov 04 12:51:14 2018 +0900
@@ -93,7 +93,8 @@
 
     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):
--- a/mercurial/ui.py	Sun Nov 04 12:38:49 2018 +0900
+++ b/mercurial/ui.py	Sun Nov 04 12:51:14 2018 +0900
@@ -1675,7 +1675,15 @@
         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'):
--- a/tests/test-commandserver.t	Sun Nov 04 12:38:49 2018 +0900
+++ b/tests/test-commandserver.t	Sun Nov 04 12:51:14 2018 +0900
@@ -750,9 +750,13 @@
   pgid: * (glob)
   *** runcommand -R repo2 verify
   message: '\xa2DdataTchecking changesets\nDtypeFstatus'
+  message: '\xa6Ditem@Cpos\xf6EtopicHcheckingEtotal\xf6DtypeHprogressDunit@'
   message: '\xa2DdataSchecking manifests\nDtypeFstatus'
+  message: '\xa6Ditem@Cpos\xf6EtopicHcheckingEtotal\xf6DtypeHprogressDunit@'
   message: '\xa2DdataX0crosschecking files in changesets and manifests\nDtypeFstatus'
+  message: '\xa6Ditem@Cpos\xf6EtopicMcrosscheckingEtotal\xf6DtypeHprogressDunit@'
   message: '\xa2DdataOchecking files\nDtypeFstatus'
+  message: '\xa6Ditem@Cpos\xf6EtopicHcheckingEtotal\xf6DtypeHprogressDunit@'
   message: '\xa2DdataX/checked 0 changesets with 0 changes to 0 files\nDtypeFstatus'
 
   >>> from hgclient import checkwith, readchannel, runcommand, stringio