progress: clear progress bar when locking to suspend

Summary:
The recent changes to the progress engine to work around locking bugs removed
the `clear` step of `progress.suspend`.  This leads to garbled output when
a progress bar is ongoing.  Restore it by adding a new lock method to the
engine.

Also add a `--with-output` option to `hg debugprogress` to test this.

Reviewed By: mitrandir77

Differential Revision: D12838415

fbshipit-source-id: 83ed516b528d0b0bbe37945141d50b50da00ac8e
This commit is contained in:
Mark Thomas 2018-10-30 07:38:02 -07:00 committed by Facebook Github Bot
parent 2deae85b42
commit 92674884fd
3 changed files with 27 additions and 4 deletions

View File

@ -3053,11 +3053,14 @@ def debugdrawdag(ui, repo, **opts):
("s", "spinner", False, _("use a progress spinner")),
("n", "nototal", False, _("don't include the total")),
("b", "bytes", False, _("use a bytes format function")),
("", "with-output", False, _("also print output every 10%")),
],
_("NUMBER"),
norepo=True,
)
def debugprogress(ui, number, spinner=False, nototal=False, bytes=False):
def debugprogress(
ui, number, spinner=False, nototal=False, bytes=False, with_output=False
):
"""
Initiate a progress bar and increment the progress NUMBER times.
@ -3069,18 +3072,30 @@ def debugprogress(ui, number, spinner=False, nototal=False, bytes=False):
formatfunc = util.bytecount if bytes else None
if with_output:
outputfreq = num // 10
if outputfreq == 0:
outputfreq = 1
else:
outputfreq = None
if spinner:
with progress.spinner(ui, _spinning):
for i in xrange(num):
pass
if outputfreq and i % outputfreq == 0:
ui.write(("processed %d items") % i)
elif nototal:
with progress.bar(ui, _spinning, formatfunc=formatfunc) as p:
for i in xrange(num):
p.value = (i, "item %s" % i)
if outputfreq and i % outputfreq == 0:
ui.write(("processed %d items") % i)
else:
with progress.bar(ui, _spinning, total=num, formatfunc=formatfunc) as p:
for i in xrange(num):
p.value = (i, "item %s" % i)
if outputfreq and i % outputfreq == 0:
ui.write(("processed %d items\n") % i)
def _findtreemanifest(ctx):

View File

@ -432,6 +432,14 @@ class engine(object):
with b, b, b, b, b, b:
yield
@contextlib.contextmanager
def _lockclear(self):
with self.lock():
bar = self._currentbar()
if bar is not None:
bar._enginerenderer.clear()
yield
def resetstate(self):
with self.lock():
self._clear()
@ -449,7 +457,7 @@ class engine(object):
self._bars.append(bar)
self._recalculatedisplay(now)
global suspend
suspend = self.lock
suspend = self._lockclear
self._cond.notify_all()
def unregister(self, bar):

View File

@ -306,7 +306,7 @@ Show all commands + options
debugpathcomplete: full, normal, added, removed
debugpickmergetool: rev, changedelete, include, exclude, tool
debugprocesstree:
debugprogress: spinner, nototal, bytes
debugprogress: spinner, nototal, bytes, with-output
debugpushkey:
debugpvec:
debugrebuilddirstate: rev, minimal