diff --git a/hgext3rd/progressfile.py b/hgext3rd/progressfile.py --- a/hgext3rd/progressfile.py +++ b/hgext3rd/progressfile.py @@ -1,9 +1,3 @@ -from __future__ import absolute_import -import json -import time - -from mercurial import progress, util - """allows users to have JSON progress bar information written to a path Controlled by the `ui.progressfile` config. Mercurial will overwrite this file @@ -33,8 +27,25 @@ # Where to write progress information statefile = /some/path/to/file """ + +from __future__ import absolute_import + +import json +import time + +from mercurial import ( + progress, + registrar, + util, +) + testedwith = 'ships-with-fb-hgext' +configtable = {} +configitem = registrar.configitem(configtable) + +configitem('progress', 'statefile', default='') + class progbarwithfile(progress.progbar): def progress(self, topic, pos, item='', unit='', total=None): super(progbarwithfile, self).progress(topic, pos, item, unit, total) @@ -101,13 +112,14 @@ return int(delta / elapsed) def uisetup(ui): - progbar = progbarwithfile(ui) class progressfileui(ui.__class__): """Redirects _progbar to our version, which always outputs if the config is set, and calls the default progbar if plain mode is off. """ @util.propertycache def _progbar(self): - if self.config('progress', 'statefile', None): - return progbar + if self.config('progress', 'statefile'): + return progbarwithfile(self) + else: + return super(progressfileui, self)._progbar ui.__class__ = progressfileui diff --git a/tests/test-progressfile.t b/tests/test-progressfile.t --- a/tests/test-progressfile.t +++ b/tests/test-progressfile.t @@ -14,7 +14,7 @@ > def uisetup(ui): > def progress(orig, *args, **kwargs): > orig(*args, **kwargs) - > if ui.config("progress", "statefile") is not None: + > if ui.config("progress", "statefile"): > try: > with open(ui.config("progress", "statefile"), 'r') as f: > print(f.read()) @@ -102,3 +102,15 @@ {"state": {"loop": {"active": false, "estimate_sec": null, "estimate_str": null, "item": "item #0", "pos": 0, "speed_str": null, "topic": "loop", "total": 2, "unit": "loopnum", "units_per_sec": null}}, "topics": ["loop"]} {"state": {"loop": {"active": true, "estimate_sec": 12, "estimate_str": "12s", "item": "item #1", "pos": 1, "speed_str": "0 loopnum/sec", "topic": "loop", "total": 2, "unit": "loopnum", "units_per_sec": null}}, "topics": ["loop"]} {"state": {}, "topics": []} + +Do not hide the progress if statefile is not set + + $ hg -y loop 5 --config progress.statefile= + \r (no-eol) (esc) + loop [ ] 0/5\r (no-eol) (esc) + loop [=======> ] 1/5 05s\r (no-eol) (esc) + loop [================> ] 2/5 04s\r (no-eol) (esc) + loop [=========================> ] 3/5 03s\r (no-eol) (esc) + loop [==================================> ] 4/5 02s\r (no-eol) (esc) + \r (no-eol) (esc) +