diff --git a/hgext/progress.py b/hgext/progress.py --- a/hgext/progress.py +++ b/hgext/progress.py @@ -35,43 +35,9 @@ would take the last num characters, or ` characters. """ -from mercurial import progress -from mercurial import ui as uimod - def uisetup(ui): - class progressui(ui.__class__): - _progbar = None - - def _quiet(self): - return self.debugflag or self.quiet - - def progress(self, *args, **opts): - if not self._quiet(): - self._progbar.progress(*args, **opts) - return super(progressui, self).progress(*args, **opts) - - def write(self, *args, **opts): - if not self._quiet() and self._progbar.printed: - self._progbar.clear() - return super(progressui, self).write(*args, **opts) - - def write_err(self, *args, **opts): - if not self._quiet() and self._progbar.printed: - self._progbar.clear() - return super(progressui, self).write_err(*args, **opts) - - # Apps that derive a class from ui.ui() can use - # setconfig('progress', 'disable', 'True') to disable this extension - if ui.configbool('progress', 'disable'): - return - if progress.shouldprint(ui) and not ui.debugflag and not ui.quiet: - dval = object() - if getattr(ui, '_progbar', dval) is dval: - ui.__class__ = progressui - # we instantiate one globally-shared progress bar to avoid - # competing progress bars when multiple UI objects get created - if not progressui._progbar: - progressui._progbar = uimod.getprogbar(ui) + if ui.config('progress', 'disable', None) is None: + ui.setconfig('progress', 'disable', 'False', 'hgext-progress') def reposetup(ui, repo): uisetup(repo.ui) diff --git a/mercurial/ui.py b/mercurial/ui.py --- a/mercurial/ui.py +++ b/mercurial/ui.py @@ -584,6 +584,7 @@ class ui(object): "cmdname.type" is recommended. For example, status issues a label of "status.modified" for modified files. ''' + self._progclear() if self._buffers: self._buffers[-1].extend([str(a) for a in args]) else: @@ -591,6 +592,7 @@ class ui(object): self.fout.write(str(a)) def write_err(self, *args, **opts): + self._progclear() try: if self._bufferstates and self._bufferstates[-1][0]: return self.write(*args, **opts) @@ -886,6 +888,22 @@ class ui(object): os.environ.get("VISUAL") or os.environ.get("EDITOR", editor)) + @util.propertycache + def _progbar(self): + """setup the progbar singleton to the ui object""" + if (self.quiet or self.debugflag + or self.configbool('progress', 'disable', True) + or not progress.shouldprint(self)): + return None + return getprogbar(self) + + def _progclear(self): + """clear progress bar output if any. use it before any output""" + if '_progbar' not in vars(self): # nothing loadef yet + return + if self._progbar is not None and self._progbar.printed: + self._progbar.clear() + def progress(self, topic, pos, item="", unit="", total=None): '''show a progress message @@ -902,7 +920,9 @@ class ui(object): All topics should be marked closed by setting pos to None at termination. ''' - + if 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'): return diff --git a/tests/test-subrepo-recursion.t b/tests/test-subrepo-recursion.t --- a/tests/test-subrepo-recursion.t +++ b/tests/test-subrepo-recursion.t @@ -258,6 +258,7 @@ Enable progress extension for archive te > [extensions] > progress = > [progress] + > disable=False > assume-tty = 1 > delay = 0 > # set changedelay really large so we don't see nested topics