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

login
register
mail settings
Submitter Yuya Nishihara
Date Nov. 8, 2018, 2:24 p.m.
Message ID <c116648678800a03858b.1541687086@mimosa>
Download mbox | patch
Permalink /patch/36477/
State Accepted
Headers show

Comments

Yuya Nishihara - Nov. 8, 2018, 2:24 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@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.
Augie Fackler - Nov. 12, 2018, 7:18 p.m.
On Thu, Nov 08, 2018 at 11:24:46PM +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@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

queued, thanks

Patch

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@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