mercurial/subrepo.py
changeset 23575 a2f139d25845
parent 23574 faa3d6af154e
child 23576 70a7478c33de
equal deleted inserted replaced
23574:faa3d6af154e 23575:a2f139d25845
   467 
   467 
   468     def fileflags(self, name):
   468     def fileflags(self, name):
   469         """return file flags"""
   469         """return file flags"""
   470         return ''
   470         return ''
   471 
   471 
   472     def archive(self, ui, archiver, prefix, match=None):
   472     def archive(self, archiver, prefix, match=None):
   473         if match is not None:
   473         if match is not None:
   474             files = [f for f in self.files() if match(f)]
   474             files = [f for f in self.files() if match(f)]
   475         else:
   475         else:
   476             files = self.files()
   476             files = self.files()
   477         total = len(files)
   477         total = len(files)
   478         relpath = subrelpath(self)
   478         relpath = subrelpath(self)
   479         ui.progress(_('archiving (%s)') % relpath, 0,
   479         self.ui.progress(_('archiving (%s)') % relpath, 0,
   480                     unit=_('files'), total=total)
   480                          unit=_('files'), total=total)
   481         for i, name in enumerate(files):
   481         for i, name in enumerate(files):
   482             flags = self.fileflags(name)
   482             flags = self.fileflags(name)
   483             mode = 'x' in flags and 0755 or 0644
   483             mode = 'x' in flags and 0755 or 0644
   484             symlink = 'l' in flags
   484             symlink = 'l' in flags
   485             archiver.addfile(os.path.join(prefix, self._path, name),
   485             archiver.addfile(os.path.join(prefix, self._path, name),
   486                              mode, symlink, self.filedata(name))
   486                              mode, symlink, self.filedata(name))
   487             ui.progress(_('archiving (%s)') % relpath, i + 1,
   487             self.ui.progress(_('archiving (%s)') % relpath, i + 1,
   488                         unit=_('files'), total=total)
   488                              unit=_('files'), total=total)
   489         ui.progress(_('archiving (%s)') % relpath, None)
   489         self.ui.progress(_('archiving (%s)') % relpath, None)
   490         return total
   490         return total
   491 
   491 
   492     def walk(self, match):
   492     def walk(self, match):
   493         '''
   493         '''
   494         walk recursively through the directory tree, finding all files
   494         walk recursively through the directory tree, finding all files
   668         except error.RepoLookupError, inst:
   668         except error.RepoLookupError, inst:
   669             self.ui.warn(_('warning: error "%s" in subrepository "%s"\n')
   669             self.ui.warn(_('warning: error "%s" in subrepository "%s"\n')
   670                           % (inst, subrelpath(self)))
   670                           % (inst, subrelpath(self)))
   671 
   671 
   672     @annotatesubrepoerror
   672     @annotatesubrepoerror
   673     def archive(self, ui, archiver, prefix, match=None):
   673     def archive(self, archiver, prefix, match=None):
   674         self._get(self._state + ('hg',))
   674         self._get(self._state + ('hg',))
   675         total = abstractsubrepo.archive(self, ui, archiver, prefix, match)
   675         total = abstractsubrepo.archive(self, archiver, prefix, match)
   676         rev = self._state[1]
   676         rev = self._state[1]
   677         ctx = self._repo[rev]
   677         ctx = self._repo[rev]
   678         for subpath in ctx.substate:
   678         for subpath in ctx.substate:
   679             s = subrepo(ctx, subpath)
   679             s = subrepo(ctx, subpath)
   680             submatch = matchmod.narrowmatcher(subpath, match)
   680             submatch = matchmod.narrowmatcher(subpath, match)
   681             total += s.archive(
   681             total += s.archive(
   682                 ui, archiver, os.path.join(prefix, self._path), submatch)
   682                 archiver, os.path.join(prefix, self._path), submatch)
   683         return total
   683         return total
   684 
   684 
   685     @annotatesubrepoerror
   685     @annotatesubrepoerror
   686     def dirty(self, ignoreupdate=False):
   686     def dirty(self, ignoreupdate=False):
   687         r = self._state[1]
   687         r = self._state[1]
  1541             if os.path.isdir(path) and not os.path.islink(path):
  1541             if os.path.isdir(path) and not os.path.islink(path):
  1542                 shutil.rmtree(path)
  1542                 shutil.rmtree(path)
  1543             else:
  1543             else:
  1544                 os.remove(path)
  1544                 os.remove(path)
  1545 
  1545 
  1546     def archive(self, ui, archiver, prefix, match=None):
  1546     def archive(self, archiver, prefix, match=None):
  1547         total = 0
  1547         total = 0
  1548         source, revision = self._state
  1548         source, revision = self._state
  1549         if not revision:
  1549         if not revision:
  1550             return total
  1550             return total
  1551         self._fetch(source, revision)
  1551         self._fetch(source, revision)
  1554         # This should be much faster than manually traversing the trees
  1554         # This should be much faster than manually traversing the trees
  1555         # and objects with many subprocess calls.
  1555         # and objects with many subprocess calls.
  1556         tarstream = self._gitcommand(['archive', revision], stream=True)
  1556         tarstream = self._gitcommand(['archive', revision], stream=True)
  1557         tar = tarfile.open(fileobj=tarstream, mode='r|')
  1557         tar = tarfile.open(fileobj=tarstream, mode='r|')
  1558         relpath = subrelpath(self)
  1558         relpath = subrelpath(self)
  1559         ui.progress(_('archiving (%s)') % relpath, 0, unit=_('files'))
  1559         self.ui.progress(_('archiving (%s)') % relpath, 0, unit=_('files'))
  1560         for i, info in enumerate(tar):
  1560         for i, info in enumerate(tar):
  1561             if info.isdir():
  1561             if info.isdir():
  1562                 continue
  1562                 continue
  1563             if match and not match(info.name):
  1563             if match and not match(info.name):
  1564                 continue
  1564                 continue
  1567             else:
  1567             else:
  1568                 data = tar.extractfile(info).read()
  1568                 data = tar.extractfile(info).read()
  1569             archiver.addfile(os.path.join(prefix, self._path, info.name),
  1569             archiver.addfile(os.path.join(prefix, self._path, info.name),
  1570                              info.mode, info.issym(), data)
  1570                              info.mode, info.issym(), data)
  1571             total += 1
  1571             total += 1
  1572             ui.progress(_('archiving (%s)') % relpath, i + 1,
  1572             self.ui.progress(_('archiving (%s)') % relpath, i + 1,
  1573                         unit=_('files'))
  1573                              unit=_('files'))
  1574         ui.progress(_('archiving (%s)') % relpath, None)
  1574         self.ui.progress(_('archiving (%s)') % relpath, None)
  1575         return total
  1575         return total
  1576 
  1576 
  1577 
  1577 
  1578     @annotatesubrepoerror
  1578     @annotatesubrepoerror
  1579     def status(self, rev2, **opts):
  1579     def status(self, rev2, **opts):