Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/subrepo.py @ 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 | 7397a53219c9 |
children | 8617b8b74fae |
comparison
equal
deleted
inserted
replaced
13143:c2e55c21db27 | 13144:aae2d5cbde64 |
---|---|
302 | 302 |
303 def fileflags(self, name): | 303 def fileflags(self, name): |
304 """return file flags""" | 304 """return file flags""" |
305 return '' | 305 return '' |
306 | 306 |
307 def archive(self, archiver, prefix): | 307 def archive(self, ui, archiver, prefix): |
308 for name in self.files(): | 308 files = self.files() |
309 total = len(files) | |
310 relpath = subrelpath(self) | |
311 ui.progress(_('archiving (%s)') % relpath, 0, | |
312 unit=_('files'), total=total) | |
313 for i, name in enumerate(files): | |
309 flags = self.fileflags(name) | 314 flags = self.fileflags(name) |
310 mode = 'x' in flags and 0755 or 0644 | 315 mode = 'x' in flags and 0755 or 0644 |
311 symlink = 'l' in flags | 316 symlink = 'l' in flags |
312 archiver.addfile(os.path.join(prefix, self._path, name), | 317 archiver.addfile(os.path.join(prefix, self._path, name), |
313 mode, symlink, self.filedata(name)) | 318 mode, symlink, self.filedata(name)) |
319 ui.progress(_('archiving (%s)') % relpath, i + 1, | |
320 unit=_('files'), total=total) | |
321 ui.progress(_('archiving (%s)') % relpath, None) | |
314 | 322 |
315 | 323 |
316 class hgsubrepo(abstractsubrepo): | 324 class hgsubrepo(abstractsubrepo): |
317 def __init__(self, ctx, path, state): | 325 def __init__(self, ctx, path, state): |
318 self._path = path | 326 self._path = path |
371 listsubrepos=True, **opts) | 379 listsubrepos=True, **opts) |
372 except error.RepoLookupError, inst: | 380 except error.RepoLookupError, inst: |
373 self._repo.ui.warn(_('warning: error "%s" in subrepository "%s"\n') | 381 self._repo.ui.warn(_('warning: error "%s" in subrepository "%s"\n') |
374 % (inst, subrelpath(self))) | 382 % (inst, subrelpath(self))) |
375 | 383 |
376 def archive(self, archiver, prefix): | 384 def archive(self, ui, archiver, prefix): |
377 abstractsubrepo.archive(self, archiver, prefix) | 385 abstractsubrepo.archive(self, ui, archiver, prefix) |
378 | 386 |
379 rev = self._state[1] | 387 rev = self._state[1] |
380 ctx = self._repo[rev] | 388 ctx = self._repo[rev] |
381 for subpath in ctx.substate: | 389 for subpath in ctx.substate: |
382 s = subrepo(ctx, subpath) | 390 s = subrepo(ctx, subpath) |
383 s.archive(archiver, os.path.join(prefix, self._path)) | 391 s.archive(ui, archiver, os.path.join(prefix, self._path)) |
384 | 392 |
385 def dirty(self): | 393 def dirty(self): |
386 r = self._state[1] | 394 r = self._state[1] |
387 if r == '': | 395 if r == '': |
388 return True | 396 return True |
858 if os.path.isdir(path) and not os.path.islink(path): | 866 if os.path.isdir(path) and not os.path.islink(path): |
859 shutil.rmtree(path) | 867 shutil.rmtree(path) |
860 else: | 868 else: |
861 os.remove(path) | 869 os.remove(path) |
862 | 870 |
863 def archive(self, archiver, prefix): | 871 def archive(self, ui, archiver, prefix): |
864 source, revision = self._state | 872 source, revision = self._state |
865 self._fetch(source, revision) | 873 self._fetch(source, revision) |
866 | 874 |
867 # Parse git's native archive command. | 875 # Parse git's native archive command. |
868 # This should be much faster than manually traversing the trees | 876 # This should be much faster than manually traversing the trees |
869 # and objects with many subprocess calls. | 877 # and objects with many subprocess calls. |
870 tarstream = self._gitcommand(['archive', revision], stream=True) | 878 tarstream = self._gitcommand(['archive', revision], stream=True) |
871 tar = tarfile.open(fileobj=tarstream, mode='r|') | 879 tar = tarfile.open(fileobj=tarstream, mode='r|') |
872 for info in tar: | 880 relpath = subrelpath(self) |
881 ui.progress(_('archiving (%s)') % relpath, 0, unit=_('files')) | |
882 for i, info in enumerate(tar): | |
873 archiver.addfile(os.path.join(prefix, self._relpath, info.name), | 883 archiver.addfile(os.path.join(prefix, self._relpath, info.name), |
874 info.mode, info.issym(), | 884 info.mode, info.issym(), |
875 tar.extractfile(info).read()) | 885 tar.extractfile(info).read()) |
886 ui.progress(_('archiving (%s)') % relpath, i + 1, | |
887 unit=_('files')) | |
888 ui.progress(_('archiving (%s)') % relpath, None) | |
889 | |
876 | 890 |
877 types = { | 891 types = { |
878 'hg': hgsubrepo, | 892 'hg': hgsubrepo, |
879 'svn': svnsubrepo, | 893 'svn': svnsubrepo, |
880 'git': gitsubrepo, | 894 'git': gitsubrepo, |