[PATCH 4 of 8] progress: slightly nicer handling of nested progress topics
Martin Geisler
mg at aragost.com
Wed Dec 15 05:19:04 CST 2010
Augie Fackler <durin42 at gmail.com> writes:
> # HG changeset patch
> # User Augie Fackler <durin42 at gmail.com>
> # Date 1287459980 18000
> # Node ID 50766f487403088037b03f8d183a2bb30f03c1dd
> # Parent 81e2508690be5edc7a418472f891c125ed33907d
> progress: slightly nicer handling of nested progress topics
>
> Previously we'd declare "complete" after an inner progress topic
> completed and erase the progress bar. Now we print the state of the
> enclosing progress topic as it was last recorded.
>
> diff --git a/hgext/progress.py b/hgext/progress.py
> --- a/hgext/progress.py
> +++ b/hgext/progress.py
> @@ -62,6 +62,7 @@
>
> def resetstate(self):
> self.topics = []
> + self.topicstates = {}
> self.pendingtopics = {}
> self.printed = False
> self.lastprint = time.time() + float(self.ui.config(
> @@ -76,8 +77,12 @@
> def show(self, topic, pos, item, unit, total):
> if not shouldprint(self.ui):
> return
> + if self.printed == (topic, pos, item, unit, total):
> + # don't double-print progress information, otherwise
> + # possible in the case of unwinding the topic stack
> + return
This part was removed in changeset f139f34ba330 (progress: react more
reasonably to nested progress topics) which was pushed. But it seems to
be important -- I have a patch that adds progress output to 'hg
archive', and I see doubled output:
ERROR: /home/mg/src/mercurial-crew/tests/test-archive.t output changed
--- /home/mg/src/mercurial-crew/tests/test-archive.t
+++ /home/mg/src/mercurial-crew/tests/test-archive.t.err
@@ -230,9 +230,14 @@
$ hg archive ../with-progress 2>&1 | python 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)
My patch is simple:
# HG changeset patch
# User Martin Geisler <mg at aragost.com>
# Date 1291043825 -3600
# Node ID 7b3e4dc233114ae7f59787525562291bd86f97ff
# Parent df2769f92a9a62942fd1327d333639b1ac4655c0
archive: add support for progress extension
diff --git a/mercurial/archival.py b/mercurial/archival.py
--- a/mercurial/archival.py
+++ b/mercurial/archival.py
@@ -262,9 +262,16 @@
write('.hg_archival.txt', 0644, False, metadata)
+ total = len(ctx.manifest())
+ count = 0
+ repo.ui.progress(_('archiving'), count, unit=_('files'), total=total)
for f in ctx:
+ count += 1
ff = ctx.flags(f)
write(f, 'x' in ff and 0755 or 0644, 'l' in ff, ctx[f].data)
+ repo.ui.progress(_('archiving'), count, item=f,
+ unit=_('files'), total=total)
+ repo.ui.progress(_('archiving'), None)
if subrepos:
for subpath in ctx.substate:
diff --git a/tests/test-archive.t b/tests/test-archive.t
--- a/tests/test-archive.t
+++ b/tests/test-archive.t
@@ -206,6 +206,41 @@
abort: unknown archive type 'bogus'
[255]
+enable progress extension:
+
+ $ cat > filtercr.py <<EOF
+ > import sys, re
+ > for line in sys.stdin:
+ > line = re.sub(r'\r+[^\n]', lambda m: '\n' + m.group()[-1:], line)
+ > sys.stdout.write(line)
+ > print
+ > EOF
+
+ $ cp $HGRCPATH $HGRCPATH.no-progress
+ $ cat >> $HGRCPATH <<EOF
+ > [extensions]
+ > progress =
+ > [progress]
+ > assume-tty = 1
+ > delay = 0
+ > refresh = 0
+ > width = 60
+ > EOF
+
+ $ hg archive ../with-progress 2>&1 | python filtercr.py
+
+ archiving [ ] 0/4
+ archiving [=========> ] 1/4
+ archiving [====================> ] 2/4
+ archiving [===============================> ] 3/4
+ archiving [==========================================>] 4/4
+ \r (esc)
+
+cleanup after progress extension test:
+
+ $ cp $HGRCPATH.no-progress $HGRCPATH
+ $ rm filtercr.py
+
server errors
$ cat errors.log
--
Martin Geisler
aragost Trifork
Professional Mercurial support
http://mercurial.aragost.com/kick-start/
More information about the Mercurial-devel
mailing list