[PATCH 1 of 2] progress: stop double wrapping of ui class

Augie Fackler raf at durin42.com
Mon Jun 8 09:36:19 CDT 2015


On Sun, Jun 07, 2015 at 08:08:06PM -0700, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david at fb.com>
> # Date 1433725883 25200
> #      Sun Jun 07 18:11:23 2015 -0700
> # Node ID 567035f46c6e91ef9420739bb7f21b7e3b9a6d10
> # Parent  6fabde6ef4453ee6c2aa964184f6cf2c54483621
> progress: stop double wrapping of ui class

Woohoo! I've been meaning to hunt this down forever, but never got
bothered enough by the test output. Thanks!

Queued with enthusiasm.

>
> We were wrapping the ui class again and again (uisetup, reposetup, subrepo
> setup, remote repo setup, etc). We now avoid that.  This has impact on test that were double printing data because of this.
>
> diff --git a/hgext/progress.py b/hgext/progress.py
> --- a/hgext/progress.py
> +++ b/hgext/progress.py
> @@ -310,15 +310,17 @@ def uisetup(ui):
>      # 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 shouldprint(ui) and not ui.debugflag and not ui.quiet:
> -        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:
> -            if _singleton is None:
> -                _singleton = progbar(ui)
> -            progressui._progbar = _singleton
> +        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:
> +                if _singleton is None:
> +                    _singleton = progbar(ui)
> +                progressui._progbar = _singleton
>
>  def reposetup(ui, repo):
>      uisetup(repo.ui)
> diff --git a/tests/test-archive.t b/tests/test-archive.t
> --- a/tests/test-archive.t
> +++ b/tests/test-archive.t
> @@ -280,22 +280,15 @@ enable progress extension:
>    > EOF
>
>    $ hg archive ../with-progress
>    \r (no-eol) (esc)
>    archiving [                                           ] 0/6\r (no-eol) (esc)
> -  archiving [                                           ] 0/6\r (no-eol) (esc)
> -  archiving [======>                                    ] 1/6\r (no-eol) (esc)
>    archiving [======>                                    ] 1/6\r (no-eol) (esc)
>    archiving [=============>                             ] 2/6\r (no-eol) (esc)
> -  archiving [=============>                             ] 2/6\r (no-eol) (esc)
> -  archiving [====================>                      ] 3/6\r (no-eol) (esc)
>    archiving [====================>                      ] 3/6\r (no-eol) (esc)
>    archiving [===========================>               ] 4/6\r (no-eol) (esc)
> -  archiving [===========================>               ] 4/6\r (no-eol) (esc)
>    archiving [==================================>        ] 5/6\r (no-eol) (esc)
> -  archiving [==================================>        ] 5/6\r (no-eol) (esc)
> -  archiving [==========================================>] 6/6\r (no-eol) (esc)
>    archiving [==========================================>] 6/6\r (no-eol) (esc)
>                                                                \r (no-eol) (esc)
>
>  cleanup after progress extension test:
>
> diff --git a/tests/test-debugbuilddag.t b/tests/test-debugbuilddag.t
> --- a/tests/test-debugbuilddag.t
> +++ b/tests/test-debugbuilddag.t
> @@ -8,41 +8,24 @@ plain
>    > --config progress.format=topic,bar,number \
>    > --config progress.width=60
>    \r (no-eol) (esc)
>    building [                                          ]  0/12\r (no-eol) (esc)
>    building [                                          ]  0/12\r (no-eol) (esc)
> -  building [                                          ]  0/12\r (no-eol) (esc)
> -  building [                                          ]  0/12\r (no-eol) (esc)
> -  building [==>                                       ]  1/12\r (no-eol) (esc)
> -  building [==>                                       ]  1/12\r (no-eol) (esc)
>    building [==>                                       ]  1/12\r (no-eol) (esc)
>    building [==>                                       ]  1/12\r (no-eol) (esc)
>    building [======>                                   ]  2/12\r (no-eol) (esc)
> -  building [======>                                   ]  2/12\r (no-eol) (esc)
> -  building [=========>                                ]  3/12\r (no-eol) (esc)
>    building [=========>                                ]  3/12\r (no-eol) (esc)
>    building [=============>                            ]  4/12\r (no-eol) (esc)
>    building [=============>                            ]  4/12\r (no-eol) (esc)
>    building [=============>                            ]  4/12\r (no-eol) (esc)
> -  building [=============>                            ]  4/12\r (no-eol) (esc)
> -  building [=============>                            ]  4/12\r (no-eol) (esc)
> -  building [=============>                            ]  4/12\r (no-eol) (esc)
> -  building [================>                         ]  5/12\r (no-eol) (esc)
>    building [================>                         ]  5/12\r (no-eol) (esc)
>    building [====================>                     ]  6/12\r (no-eol) (esc)
> -  building [====================>                     ]  6/12\r (no-eol) (esc)
> -  building [=======================>                  ]  7/12\r (no-eol) (esc)
>    building [=======================>                  ]  7/12\r (no-eol) (esc)
>    building [===========================>              ]  8/12\r (no-eol) (esc)
>    building [===========================>              ]  8/12\r (no-eol) (esc)
> -  building [===========================>              ]  8/12\r (no-eol) (esc)
> -  building [===========================>              ]  8/12\r (no-eol) (esc)
> -  building [==============================>           ]  9/12\r (no-eol) (esc)
>    building [==============================>           ]  9/12\r (no-eol) (esc)
>    building [==================================>       ] 10/12\r (no-eol) (esc)
> -  building [==================================>       ] 10/12\r (no-eol) (esc)
> -  building [=====================================>    ] 11/12\r (no-eol) (esc)
>    building [=====================================>    ] 11/12\r (no-eol) (esc)
>                                                                \r (no-eol) (esc)
>
>  tags
>    $ cat .hg/localtags
> diff --git a/tests/test-patchbomb.t b/tests/test-patchbomb.t
> --- a/tests/test-patchbomb.t
> +++ b/tests/test-patchbomb.t
> @@ -287,22 +287,15 @@ Test breaking format changes aren't
>
>    Write the introductory message for the patch series.
>
>    \r (no-eol) (esc)
>    sending [                                             ] 0/3\r (no-eol) (esc)
> -  sending [                                             ] 0/3\r (no-eol) (esc)
> -                                                              \r (no-eol) (esc)
> -  \r (no-eol) (esc)
>                                                                \r (no-eol) (esc)
>    \r (no-eol) (esc)
>    sending [==============>                              ] 1/3\r (no-eol) (esc)
> -  sending [==============>                              ] 1/3\r (no-eol) (esc)
>                                                                \r (no-eol) (esc)
>    \r (no-eol) (esc)
> -                                                              \r (no-eol) (esc)
> -  \r (no-eol) (esc)
> -  sending [=============================>               ] 2/3\r (no-eol) (esc)
>    sending [=============================>               ] 2/3\r (no-eol) (esc)
>                                                                \r (esc)
>    sending [PATCH 0 of 2] test ...
>    sending [PATCH 1 of 2] a ...
>    sending [PATCH 2 of 2] b ...
> 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
> @@ -271,33 +271,23 @@ Test archiving to a directory tree (the
>  only show up in the test output, not in real usage):
>
>    $ hg archive --subrepos ../archive
>    \r (no-eol) (esc)
>    archiving [                                           ] 0/3\r (no-eol) (esc)
> -  archiving [                                           ] 0/3\r (no-eol) (esc)
> -  archiving [=============>                             ] 1/3\r (no-eol) (esc)
>    archiving [=============>                             ] 1/3\r (no-eol) (esc)
>    archiving [===========================>               ] 2/3\r (no-eol) (esc)
> -  archiving [===========================>               ] 2/3\r (no-eol) (esc)
> -  archiving [==========================================>] 3/3\r (no-eol) (esc)
>    archiving [==========================================>] 3/3\r (no-eol) (esc)
>                                                                \r (no-eol) (esc)
>    \r (no-eol) (esc)
>    archiving (foo) [                                     ] 0/3\r (no-eol) (esc)
> -  archiving (foo) [                                     ] 0/3\r (no-eol) (esc)
> -  archiving (foo) [===========>                         ] 1/3\r (no-eol) (esc)
>    archiving (foo) [===========>                         ] 1/3\r (no-eol) (esc)
>    archiving (foo) [=======================>             ] 2/3\r (no-eol) (esc)
> -  archiving (foo) [=======================>             ] 2/3\r (no-eol) (esc)
> -  archiving (foo) [====================================>] 3/3\r (no-eol) (esc)
>    archiving (foo) [====================================>] 3/3\r (no-eol) (esc)
>                                                                \r (no-eol) (esc)
>    \r (no-eol) (esc)
> -  archiving (foo/bar) [                                 ] 0/1\r (no-eol) (glob) (esc)
> -  archiving (foo/bar) [                                 ] 0/1\r (no-eol) (glob) (esc)
> -  archiving (foo/bar) [================================>] 1/1\r (no-eol) (glob) (esc)
> -  archiving (foo/bar) [================================>] 1/1\r (no-eol) (glob) (esc)
> +  archiving (foo/bar) [                                 ] 0/1\r (no-eol) (esc)
> +  archiving (foo/bar) [================================>] 1/1\r (no-eol) (esc)
>                                                                \r (no-eol) (esc)
>    $ find ../archive | sort
>    ../archive
>    ../archive/.hg_archival.txt
>    ../archive/.hgsub
> @@ -313,33 +303,23 @@ only show up in the test output, not in
>  Test archiving to zip file (unzip output is unstable):
>
>    $ hg archive --subrepos --prefix '.' ../archive.zip
>    \r (no-eol) (esc)
>    archiving [                                           ] 0/3\r (no-eol) (esc)
> -  archiving [                                           ] 0/3\r (no-eol) (esc)
> -  archiving [=============>                             ] 1/3\r (no-eol) (esc)
>    archiving [=============>                             ] 1/3\r (no-eol) (esc)
>    archiving [===========================>               ] 2/3\r (no-eol) (esc)
> -  archiving [===========================>               ] 2/3\r (no-eol) (esc)
> -  archiving [==========================================>] 3/3\r (no-eol) (esc)
>    archiving [==========================================>] 3/3\r (no-eol) (esc)
>                                                                \r (no-eol) (esc)
>    \r (no-eol) (esc)
>    archiving (foo) [                                     ] 0/3\r (no-eol) (esc)
> -  archiving (foo) [                                     ] 0/3\r (no-eol) (esc)
> -  archiving (foo) [===========>                         ] 1/3\r (no-eol) (esc)
>    archiving (foo) [===========>                         ] 1/3\r (no-eol) (esc)
>    archiving (foo) [=======================>             ] 2/3\r (no-eol) (esc)
> -  archiving (foo) [=======================>             ] 2/3\r (no-eol) (esc)
> -  archiving (foo) [====================================>] 3/3\r (no-eol) (esc)
>    archiving (foo) [====================================>] 3/3\r (no-eol) (esc)
>                                                                \r (no-eol) (esc)
>    \r (no-eol) (esc)
> -  archiving (foo/bar) [                                 ] 0/1\r (no-eol) (glob) (esc)
> -  archiving (foo/bar) [                                 ] 0/1\r (no-eol) (glob) (esc)
> -  archiving (foo/bar) [================================>] 1/1\r (no-eol) (glob) (esc)
> -  archiving (foo/bar) [================================>] 1/1\r (no-eol) (glob) (esc)
> +  archiving (foo/bar) [                                 ] 0/1\r (no-eol) (esc)
> +  archiving (foo/bar) [================================>] 1/1\r (no-eol) (esc)
>                                                                \r (no-eol) (esc)
>
>  (unzip date formating is unstable, we do not care about it and glob it out)
>
>    $ unzip -l ../archive.zip
> @@ -381,16 +361,12 @@ cloned:
>    $ cd ../empty
>  #if hardlink
>    $ hg archive --subrepos -r tip --prefix './' ../archive.tar.gz
>    \r (no-eol) (esc)
>    archiving [                                           ] 0/3\r (no-eol) (esc)
> -  archiving [                                           ] 0/3\r (no-eol) (esc)
> -  archiving [=============>                             ] 1/3\r (no-eol) (esc)
>    archiving [=============>                             ] 1/3\r (no-eol) (esc)
>    archiving [===========================>               ] 2/3\r (no-eol) (esc)
> -  archiving [===========================>               ] 2/3\r (no-eol) (esc)
> -  archiving [==========================================>] 3/3\r (no-eol) (esc)
>    archiving [==========================================>] 3/3\r (no-eol) (esc)
>                                                                \r (no-eol) (esc)
>    \r (no-eol) (esc)
>    linking [ <=>                                           ] 1\r (no-eol) (esc)
>    linking [  <=>                                          ] 2\r (no-eol) (esc)
> @@ -401,16 +377,12 @@ cloned:
>    linking [       <=>                                     ] 7\r (no-eol) (esc)
>    linking [        <=>                                    ] 8\r (no-eol) (esc)
>                                                                \r (no-eol) (esc)
>    \r (no-eol) (esc)
>    archiving (foo) [                                     ] 0/3\r (no-eol) (esc)
> -  archiving (foo) [                                     ] 0/3\r (no-eol) (esc)
> -  archiving (foo) [===========>                         ] 1/3\r (no-eol) (esc)
>    archiving (foo) [===========>                         ] 1/3\r (no-eol) (esc)
>    archiving (foo) [=======================>             ] 2/3\r (no-eol) (esc)
> -  archiving (foo) [=======================>             ] 2/3\r (no-eol) (esc)
> -  archiving (foo) [====================================>] 3/3\r (no-eol) (esc)
>    archiving (foo) [====================================>] 3/3\r (no-eol) (esc)
>                                                                \r (no-eol) (esc)
>    \r (no-eol) (esc)
>    linking [ <=>                                           ] 1\r (no-eol) (esc)
>    linking [  <=>                                          ] 2\r (no-eol) (esc)
> @@ -418,14 +390,12 @@ cloned:
>    linking [    <=>                                        ] 4\r (no-eol) (esc)
>    linking [     <=>                                       ] 5\r (no-eol) (esc)
>    linking [      <=>                                      ] 6\r (no-eol) (esc)
>                                                                \r (no-eol) (esc)
>    \r (no-eol) (esc)
> -  archiving (foo/bar) [                                 ] 0/1\r (no-eol) (glob) (esc)
> -  archiving (foo/bar) [                                 ] 0/1\r (no-eol) (glob) (esc)
> -  archiving (foo/bar) [================================>] 1/1\r (no-eol) (glob) (esc)
> -  archiving (foo/bar) [================================>] 1/1\r (no-eol) (glob) (esc)
> +  archiving (foo/bar) [                                 ] 0/1\r (no-eol) (esc)
> +  archiving (foo/bar) [================================>] 1/1\r (no-eol) (esc)
>                                                                \r (no-eol) (esc)
>    cloning subrepo foo from $TESTTMP/repo/foo
>    cloning subrepo foo/bar from $TESTTMP/repo/foo/bar (glob)
>  #else
>  Note there's a slight output glitch on non-hardlink systems: the last
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel


More information about the Mercurial-devel mailing list