changeset 13144:aae2d5cbde64

subrepo: add progress bar support to archive
author Martin Geisler <mg@aragost.com>
date Mon, 29 Nov 2010 16:34:10 +0100
parents c2e55c21db27
children ce4cd176634e
files mercurial/archival.py mercurial/subrepo.py tests/test-subrepo-recursion.t
diffstat 3 files changed, 91 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/archival.py	Mon Nov 29 16:17:05 2010 +0100
+++ b/mercurial/archival.py	Mon Nov 29 16:34:10 2010 +0100
@@ -274,6 +274,6 @@
     if subrepos:
         for subpath in ctx.substate:
             sub = ctx.sub(subpath)
-            sub.archive(archiver, prefix)
+            sub.archive(repo.ui, archiver, prefix)
 
     archiver.done()
--- a/mercurial/subrepo.py	Mon Nov 29 16:17:05 2010 +0100
+++ b/mercurial/subrepo.py	Mon Nov 29 16:34:10 2010 +0100
@@ -304,13 +304,21 @@
         """return file flags"""
         return ''
 
-    def archive(self, archiver, prefix):
-        for name in self.files():
+    def archive(self, ui, archiver, prefix):
+        files = self.files()
+        total = len(files)
+        relpath = subrelpath(self)
+        ui.progress(_('archiving (%s)') % relpath, 0,
+                    unit=_('files'), total=total)
+        for i, name in enumerate(files):
             flags = self.fileflags(name)
             mode = 'x' in flags and 0755 or 0644
             symlink = 'l' in flags
             archiver.addfile(os.path.join(prefix, self._path, name),
                              mode, symlink, self.filedata(name))
+            ui.progress(_('archiving (%s)') % relpath, i + 1,
+                        unit=_('files'), total=total)
+        ui.progress(_('archiving (%s)') % relpath, None)
 
 
 class hgsubrepo(abstractsubrepo):
@@ -373,14 +381,14 @@
             self._repo.ui.warn(_('warning: error "%s" in subrepository "%s"\n')
                                % (inst, subrelpath(self)))
 
-    def archive(self, archiver, prefix):
-        abstractsubrepo.archive(self, archiver, prefix)
+    def archive(self, ui, archiver, prefix):
+        abstractsubrepo.archive(self, ui, archiver, prefix)
 
         rev = self._state[1]
         ctx = self._repo[rev]
         for subpath in ctx.substate:
             s = subrepo(ctx, subpath)
-            s.archive(archiver, os.path.join(prefix, self._path))
+            s.archive(ui, archiver, os.path.join(prefix, self._path))
 
     def dirty(self):
         r = self._state[1]
@@ -860,7 +868,7 @@
             else:
                 os.remove(path)
 
-    def archive(self, archiver, prefix):
+    def archive(self, ui, archiver, prefix):
         source, revision = self._state
         self._fetch(source, revision)
 
@@ -869,10 +877,16 @@
         # and objects with many subprocess calls.
         tarstream = self._gitcommand(['archive', revision], stream=True)
         tar = tarfile.open(fileobj=tarstream, mode='r|')
-        for info in tar:
+        relpath = subrelpath(self)
+        ui.progress(_('archiving (%s)') % relpath, 0, unit=_('files'))
+        for i, info in enumerate(tar):
             archiver.addfile(os.path.join(prefix, self._relpath, info.name),
                              info.mode, info.issym(),
                              tar.extractfile(info).read())
+            ui.progress(_('archiving (%s)') % relpath, i + 1,
+                        unit=_('files'))
+        ui.progress(_('archiving (%s)') % relpath, None)
+
 
 types = {
     'hg': hgsubrepo,
--- a/tests/test-subrepo-recursion.t	Mon Nov 29 16:17:05 2010 +0100
+++ b/tests/test-subrepo-recursion.t	Mon Nov 29 16:34:10 2010 +0100
@@ -221,9 +221,47 @@
    z1
   +z2
 
-Test archiving to a directory tree:
+Enable progress extension for archive tests:
+
+  $ cp $HGRCPATH $HGRCPATH.no-progress
+  $ cat >> $HGRCPATH <<EOF
+  > [extensions]
+  > progress =
+  > [progress]
+  > assume-tty = 1
+  > delay = 0
+  > refresh = 0
+  > 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):
 
-  $ hg archive --subrepos ../archive
+  $ 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
+  archiving (foo/bar) [                                 ] 0/1
+  archiving (foo/bar) [================================>] 1/1
+  archiving (foo/bar) [================================>] 1/1
+                                                              \r (esc)
   $ find ../archive | sort
   ../archive
   ../archive/.hg_archival.txt
@@ -239,7 +277,35 @@
 
 Test archiving to zip file (unzip output is unstable):
 
-  $ hg archive --subrepos ../archive.zip
+  $ 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
+  archiving (foo/bar) [                                 ] 0/1
+  archiving (foo/bar) [================================>] 1/1
+  archiving (foo/bar) [================================>] 1/1
+                                                              \r (esc)
+
+Disable progress extension and cleanup:
+
+  $ mv $HGRCPATH.no-progress $HGRCPATH
 
 Clone and test outgoing: