# HG changeset patch # User Martin Geisler # Date 2010-11-29 15:34:10 # Node ID aae2d5cbde647da49fb1927d02faabfc37975c63 # Parent c2e55c21db27bb1b69206aac2c7c53d06ee13128 subrepo: add progress bar support to archive diff --git a/mercurial/archival.py b/mercurial/archival.py --- a/mercurial/archival.py +++ b/mercurial/archival.py @@ -274,6 +274,6 @@ def archive(repo, dest, node, kind, deco if subrepos: for subpath in ctx.substate: sub = ctx.sub(subpath) - sub.archive(archiver, prefix) + sub.archive(repo.ui, archiver, prefix) archiver.done() diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py --- a/mercurial/subrepo.py +++ b/mercurial/subrepo.py @@ -304,13 +304,21 @@ class abstractsubrepo(object): """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 @@ class hgsubrepo(abstractsubrepo): 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 @@ class gitsubrepo(abstractsubrepo): 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 @@ class gitsubrepo(abstractsubrepo): # 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, 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 @@ -221,9 +221,47 @@ Status between revisions: z1 +z2 -Test archiving to a directory tree: +Enable progress extension for archive tests: + + $ cp $HGRCPATH $HGRCPATH.no-progress + $ cat >> $HGRCPATH < [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 a directory tree: 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: