archive: add support for progress extension
authorMartin Geisler <mg@aragost.com>
Mon, 29 Nov 2010 16:17:05 +0100
changeset 13143 c2e55c21db27
parent 13142 e9827c85c50b
child 13144 aae2d5cbde64
archive: add support for progress extension
mercurial/archival.py
tests/test-archive.t
--- a/mercurial/archival.py	Wed Dec 15 16:35:09 2010 +0100
+++ b/mercurial/archival.py	Mon Nov 29 16:17:05 2010 +0100
@@ -262,9 +262,14 @@
 
         write('.hg_archival.txt', 0644, False, metadata)
 
-    for f in ctx:
+    total = len(ctx.manifest())
+    repo.ui.progress(_('archiving'), 0, unit=_('files'), total=total)
+    for i, f in enumerate(ctx):
         ff = ctx.flags(f)
         write(f, 'x' in ff and 0755 or 0644, 'l' in ff, ctx[f].data)
+        repo.ui.progress(_('archiving'), i + 1, item=f,
+                         unit=_('files'), total=total)
+    repo.ui.progress(_('archiving'), None)
 
     if subrepos:
         for subpath in ctx.substate:
--- a/tests/test-archive.t	Wed Dec 15 16:35:09 2010 +0100
+++ b/tests/test-archive.t	Mon Nov 29 16:17:05 2010 +0100
@@ -206,6 +206,37 @@
   abort: unknown archive type 'bogus'
   [255]
 
+enable progress extension:
+
+  $ 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 | $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)
+
+cleanup after progress extension test:
+
+  $ cp $HGRCPATH.no-progress $HGRCPATH
+
 server errors
 
   $ cat errors.log