[PATCH 3 of 3] progress: move all logic altering the ui object logic in mercurial.ui

Augie Fackler raf at durin42.com
Wed Jun 10 09:33:49 CDT 2015


On Tue, Jun 09, 2015 at 10:58:29AM -0700, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david at fb.com>
> # Date 1433724656 25200
> #      Sun Jun 07 17:50:56 2015 -0700
> # Node ID f60301e56e0301a0c1b406a88810f6914dff74d6
> # Parent  083b0e44c3cd57e342cd1799de05ec7387952835
> progress: move all logic altering the ui object logic in mercurial.ui

Queued, but someone touched progress in the interim, so there was a
rebase required. I recommend you look at the patches in the
clowncopter carefully.

>
> The ui object can take care of its project object logic by itself.
>
> test-subrepo-recursion is modified because it is a bit sensible to the "no
> progress bar" default. It will become  unnecessary in the next step when
> progress will be on by default in core.
>
> diff --git a/hgext/progress.py b/hgext/progress.py
> --- a/hgext/progress.py
> +++ b/hgext/progress.py
> @@ -33,45 +33,11 @@ estimate, speed, and item. item defaults
>  the item, but this can be changed by adding either ``-<num>`` which
>  would take the last num characters, or ``+<num>`` for the first num
>  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
> @@ -582,17 +582,19 @@ class ui(object):
>
>          When labeling output for a specific command, a label of
>          "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:
>              for a in args:
>                  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)
>              if not getattr(self.fout, 'closed', False):
>                  self.fout.flush()
> @@ -884,10 +886,26 @@ class ui(object):
>          return (os.environ.get("HGEDITOR") or
>                  self.config("ui", "editor") or
>                  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
>
>          With stock hg, this is simply a debug message that is hidden
>          by default, but with extensions or GUI tools it may be
> @@ -900,11 +918,13 @@ class ui(object):
>          Multiple nested topics may be active at a time.
>
>          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
>
>          if unit:
>              unit = ' ' + unit
> 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
> @@ -256,10 +256,11 @@ Enable progress extension for archive te
>    $ cp $HGRCPATH $HGRCPATH.no-progress
>    $ cat >> $HGRCPATH <<EOF
>    > [extensions]
>    > progress =
>    > [progress]
> +  > disable=False
>    > assume-tty = 1
>    > delay = 0
>    > # set changedelay really large so we don't see nested topics
>    > changedelay = 30000
>    > format = topic bar number
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel


More information about the Mercurial-devel mailing list