[PATCH 1 of 3] progress: move from extension to core
Augie Fackler
raf at durin42.com
Sat May 12 10:33:13 CDT 2012
On May 12, 2012, at 4:39 PM, Martin Geisler wrote:
> # HG changeset patch
> # User Martin Geisler <martin at geisler.net>
> # Date 1336829943 -7200
> # Node ID bd17c94b246bb7b4b8cfec24e491310bd54e3f8b
> # Parent 654b9e1966f76d38b11fbd1d518efce5d58caa88
> progress: move from extension to core
>
> The old progress extension is now ignored, so people can keep loading
> it in their existing config.
>
> This also somehow fixed a problem with doubled progress bars: two
> progress bars would be printed, though they had the same information.
> This was therefore not visible in normal usage, it only showed up in
> the test suite.
(repeating for list viewers)
We'll need to disable this in hgweb, as touching sys.{stderr,stdout} can cause WSGI servers to be grumpy and throw exceptions.
>
> diff --git a/mercurial/extensions.py b/mercurial/extensions.py
> --- a/mercurial/extensions.py
> +++ b/mercurial/extensions.py
> @@ -11,7 +11,7 @@
>
> _extensions = {}
> _order = []
> -_ignore = ['hbisect', 'bookmarks', 'parentrevspec']
> +_ignore = ['hbisect', 'bookmarks', 'parentrevspec', 'progress']
>
> def extensions():
> for name in _order:
> diff --git a/hgext/progress.py b/mercurial/progress.py
> rename from hgext/progress.py
> rename to mercurial/progress.py
> --- a/hgext/progress.py
> +++ b/mercurial/progress.py
> @@ -38,14 +38,16 @@
> import sys
> import time
>
> -from mercurial import util
> -from mercurial.i18n import _
> +import util
> +from i18n import _
>
> def spacejoin(*args):
> return ' '.join(s for s in args if s)
>
> def shouldprint(ui):
> - return util.isatty(sys.stderr) or ui.configbool('progress', 'assume-tty')
> + return (not ui.configbool('progress', 'disabled')
> + and (util.isatty(sys.stderr)
> + or ui.configbool('progress', 'assume-tty')))
>
> def fmtremaining(seconds):
> if seconds < 60:
> @@ -255,41 +257,9 @@
>
> _singleton = None
>
> -def uisetup(ui):
> +def progressbar(ui):
> + """return the singleton progressbar"""
> global _singleton
> - 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 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
> -
> -def reposetup(ui, repo):
> - uisetup(repo.ui)
> + if _singleton is None:
> + _singleton = progbar(ui)
> + return _singleton
> diff --git a/mercurial/ui.py b/mercurial/ui.py
> --- a/mercurial/ui.py
> +++ b/mercurial/ui.py
> @@ -7,7 +7,7 @@
>
> from i18n import _
> import errno, getpass, os, socket, sys, tempfile, traceback
> -import config, scmutil, util, error, formatter
> +import config, scmutil, util, error, formatter, progress
>
> class ui(object):
> def __init__(self, src=None):
> @@ -19,6 +19,7 @@
> self._ucfg = config.config() # untrusted
> self._trustusers = set()
> self._trustgroups = set()
> + self._progbar = progress.progressbar(self)
>
> if src:
> self.fout = src.fout
> @@ -145,6 +146,9 @@
> self._trustusers.update(self.configlist('trusted', 'users'))
> self._trustgroups.update(self.configlist('trusted', 'groups'))
>
> + if section in (None, 'progress'):
> + self._progbar.resetstate()
> +
> def backupconfig(self, section, item):
> return (self._ocfg.backup(section, item),
> self._tcfg.backup(section, item),
> @@ -466,6 +470,8 @@
> "cmdname.type" is recommended. For example, status issues
> a label of "status.modified" for modified files.
> '''
> + if not self._quiet() and self._progbar.printed:
> + self._progbar.clear()
> if self._buffers:
> self._buffers[-1].extend([str(a) for a in args])
> else:
> @@ -473,6 +479,8 @@
> self.fout.write(str(a))
>
> def write_err(self, *args, **opts):
> + if not self._quiet() and self._progbar.printed:
> + self._progbar.clear()
> try:
> if not getattr(self.fout, 'closed', False):
> self.fout.flush()
> @@ -699,6 +707,9 @@
> os.environ.get("VISUAL") or
> os.environ.get("EDITOR", editor))
>
> + def _quiet(self):
> + return self.debugflag or self.quiet
> +
> def progress(self, topic, pos, item="", unit="", total=None):
> '''show a progress message
>
> @@ -715,6 +726,8 @@
> All topics should be marked closed by setting pos to None at
> termination.
> '''
> + if not self._quiet():
> + self._progbar.progress(topic, pos, item, unit, total)
>
> if pos is None or not self.debugflag:
> return
> diff --git a/tests/test-archive.t b/tests/test-archive.t
> --- a/tests/test-archive.t
> +++ b/tests/test-archive.t
> @@ -224,14 +224,9 @@
> $ hg archive ../with-progress 2>&1 | "$TESTDIR/filtercr.py"
>
> archiving [ ] 0/4
> - archiving [ ] 0/4
> - archiving [=========> ] 1/4
> archiving [=========> ] 1/4
> archiving [====================> ] 2/4
> - archiving [====================> ] 2/4
> archiving [===============================> ] 3/4
> - archiving [===============================> ] 3/4
> - archiving [==========================================>] 4/4
> archiving [==========================================>] 4/4
> \r (esc)
>
> diff --git a/tests/test-debugbuilddag.t b/tests/test-debugbuilddag.t
> --- a/tests/test-debugbuilddag.t
> +++ b/tests/test-debugbuilddag.t
> @@ -13,37 +13,20 @@
>
> building [ ] 0/12
> building [ ] 0/12
> - building [ ] 0/12
> - building [ ] 0/12
> - building [==> ] 1/12
> - building [==> ] 1/12
> building [==> ] 1/12
> building [==> ] 1/12
> building [======> ] 2/12
> - building [======> ] 2/12
> - building [=========> ] 3/12
> building [=========> ] 3/12
> building [=============> ] 4/12
> building [=============> ] 4/12
> building [=============> ] 4/12
> - building [=============> ] 4/12
> - building [=============> ] 4/12
> - building [=============> ] 4/12
> - building [================> ] 5/12
> building [================> ] 5/12
> building [====================> ] 6/12
> - building [====================> ] 6/12
> - building [=======================> ] 7/12
> building [=======================> ] 7/12
> building [===========================> ] 8/12
> building [===========================> ] 8/12
> - building [===========================> ] 8/12
> - building [===========================> ] 8/12
> - building [==============================> ] 9/12
> building [==============================> ] 9/12
> building [==================================> ] 10/12
> - building [==================================> ] 10/12
> - building [=====================================> ] 11/12
> building [=====================================> ] 11/12
> \r (esc)
>
> diff --git a/tests/test-patchbomb.t b/tests/test-patchbomb.t
> --- a/tests/test-patchbomb.t
> +++ b/tests/test-patchbomb.t
> @@ -162,14 +162,9 @@
>
>
> sending [ ] 0/3
> - sending [ ] 0/3
> -
>
> sending [==============> ] 1/3
> - sending [==============> ] 1/3
>
> -
> - sending [=============================> ] 2/3
> sending [=============================> ] 2/3
> \r (esc)
> Sending [PATCH 0 of 2] test ...
> diff --git a/tests/test-progress.t b/tests/test-progress.t
> --- a/tests/test-progress.t
> +++ b/tests/test-progress.t
> @@ -37,7 +37,6 @@
>
> $ cp $HGRCPATH $HGRCPATH.orig
> $ echo "[extensions]" >> $HGRCPATH
> - $ echo "progress=" >> $HGRCPATH
> $ echo "loop=`pwd`/loop.py" >> $HGRCPATH
> $ echo "[progress]" >> $HGRCPATH
> $ echo "format = topic bar number" >> $HGRCPATH
> @@ -161,12 +160,14 @@
>>
>> def uisetup(ui):
>> time.time = mocktime(int(os.environ.get('MOCKTIME', '11')))
> + > # The extension is loaded after time.time() is called by the
> + > # progessbar, so we need to reset it again.
> + > ui._progbar.resetstate()
>> EOF
>
> $ cp $HGRCPATH.orig $HGRCPATH
> $ echo "[extensions]" >> $HGRCPATH
> $ echo "mocktime=`pwd`/mocktime.py" >> $HGRCPATH
> - $ echo "progress=" >> $HGRCPATH
> $ echo "loop=`pwd`/loop.py" >> $HGRCPATH
> $ echo "[progress]" >> $HGRCPATH
> $ echo "assume-tty=1" >> $HGRCPATH
> 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
> @@ -257,32 +257,21 @@
>> width = 60
>> EOF
>
> -Test archiving to a directory tree (the doubled lines in the output
> -only show up in the test output, not in real usage):
> +Test archiving to a directory tree:
>
> $ hg archive --subrepos ../archive 2>&1 | "$TESTDIR/filtercr.py"
>
> archiving [ ] 0/3
> - archiving [ ] 0/3
> - archiving [=============> ] 1/3
> archiving [=============> ] 1/3
> archiving [===========================> ] 2/3
> - archiving [===========================> ] 2/3
> - archiving [==========================================>] 3/3
> archiving [==========================================>] 3/3
>
> archiving (foo) [ ] 0/3
> - archiving (foo) [ ] 0/3
> - archiving (foo) [===========> ] 1/3
> archiving (foo) [===========> ] 1/3
> archiving (foo) [=======================> ] 2/3
> - archiving (foo) [=======================> ] 2/3
> - archiving (foo) [====================================>] 3/3
> archiving (foo) [====================================>] 3/3
>
> archiving (foo/bar) [ ] 0/1 (glob)
> - archiving (foo/bar) [ ] 0/1 (glob)
> - archiving (foo/bar) [================================>] 1/1 (glob)
> archiving (foo/bar) [================================>] 1/1 (glob)
> \r (esc)
> $ find ../archive | sort
> @@ -303,26 +292,16 @@
> $ hg archive --subrepos ../archive.zip 2>&1 | "$TESTDIR/filtercr.py"
>
> archiving [ ] 0/3
> - archiving [ ] 0/3
> - archiving [=============> ] 1/3
> archiving [=============> ] 1/3
> archiving [===========================> ] 2/3
> - archiving [===========================> ] 2/3
> - archiving [==========================================>] 3/3
> archiving [==========================================>] 3/3
>
> archiving (foo) [ ] 0/3
> - archiving (foo) [ ] 0/3
> - archiving (foo) [===========> ] 1/3
> archiving (foo) [===========> ] 1/3
> archiving (foo) [=======================> ] 2/3
> - archiving (foo) [=======================> ] 2/3
> - archiving (foo) [====================================>] 3/3
> archiving (foo) [====================================>] 3/3
>
> archiving (foo/bar) [ ] 0/1 (glob)
> - archiving (foo/bar) [ ] 0/1 (glob)
> - archiving (foo/bar) [================================>] 1/1 (glob)
> archiving (foo/bar) [================================>] 1/1 (glob)
> \r (esc)
>
> @@ -334,26 +313,16 @@
> $ hg archive --subrepos -r tip ../archive.tar.gz 2>&1 | "$TESTDIR/filtercr.py"
>
> archiving [ ] 0/3
> - archiving [ ] 0/3
> - archiving [=============> ] 1/3
> archiving [=============> ] 1/3
> archiving [===========================> ] 2/3
> - archiving [===========================> ] 2/3
> - archiving [==========================================>] 3/3
> archiving [==========================================>] 3/3
>
> archiving (foo) [ ] 0/3
> - archiving (foo) [ ] 0/3
> - archiving (foo) [===========> ] 1/3
> archiving (foo) [===========> ] 1/3
> archiving (foo) [=======================> ] 2/3
> - archiving (foo) [=======================> ] 2/3
> - archiving (foo) [====================================>] 3/3
> archiving (foo) [====================================>] 3/3
>
> archiving (foo/bar) [ ] 0/1 (glob)
> - archiving (foo/bar) [ ] 0/1 (glob)
> - archiving (foo/bar) [================================>] 1/1 (glob)
> archiving (foo/bar) [================================>] 1/1 (glob)
>
> cloning subrepo foo from $TESTTMP/repo/foo
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
More information about the Mercurial-devel
mailing list