# HG changeset patch # User Yuya Nishihara # Date 2018-11-04 03:51:14 # Node ID 234c2d8c9e4839c1f4f0e744cf08c6b3cc7416da # Parent 6f0941f4a184aca9c4f5149b96ed1697a10d6ea7 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 @@ -1675,7 +1675,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