Mercurial > public > mercurial-scm > hg
comparison mercurial/subrepo.py @ 17108:1894dac619de
subrepo: propagate matcher to subrepos when archiving
Add a match object to subrepo.archive(). This will allow the -X and -I
options to be honored inside subrepos when archiving. They formerly
only affect the top level repo.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Sat, 16 Jun 2012 22:34:06 -0400 |
parents | ab4644c3064f |
children | f7152a0d90df |
comparison
equal
deleted
inserted
replaced
17107:dcac72c9efb2 | 17108:1894dac619de |
---|---|
6 # GNU General Public License version 2 or any later version. | 6 # GNU General Public License version 2 or any later version. |
7 | 7 |
8 import errno, os, re, xml.dom.minidom, shutil, posixpath | 8 import errno, os, re, xml.dom.minidom, shutil, posixpath |
9 import stat, subprocess, tarfile | 9 import stat, subprocess, tarfile |
10 from i18n import _ | 10 from i18n import _ |
11 import config, scmutil, util, node, error, cmdutil, bookmarks | 11 import config, scmutil, util, node, error, cmdutil, bookmarks, match as matchmod |
12 hg = None | 12 hg = None |
13 propertycache = util.propertycache | 13 propertycache = util.propertycache |
14 | 14 |
15 nullstate = ('', '', 'empty') | 15 nullstate = ('', '', 'empty') |
16 | 16 |
349 | 349 |
350 def fileflags(self, name): | 350 def fileflags(self, name): |
351 """return file flags""" | 351 """return file flags""" |
352 return '' | 352 return '' |
353 | 353 |
354 def archive(self, ui, archiver, prefix): | 354 def archive(self, ui, archiver, prefix, match=None): |
355 files = self.files() | 355 if match is not None: |
356 files = [f for f in self.files() if match(f)] | |
357 else: | |
358 files = self.files() | |
356 total = len(files) | 359 total = len(files) |
357 relpath = subrelpath(self) | 360 relpath = subrelpath(self) |
358 ui.progress(_('archiving (%s)') % relpath, 0, | 361 ui.progress(_('archiving (%s)') % relpath, 0, |
359 unit=_('files'), total=total) | 362 unit=_('files'), total=total) |
360 for i, name in enumerate(files): | 363 for i, name in enumerate(files): |
443 listsubrepos=True, **opts) | 446 listsubrepos=True, **opts) |
444 except error.RepoLookupError, inst: | 447 except error.RepoLookupError, inst: |
445 self._repo.ui.warn(_('warning: error "%s" in subrepository "%s"\n') | 448 self._repo.ui.warn(_('warning: error "%s" in subrepository "%s"\n') |
446 % (inst, subrelpath(self))) | 449 % (inst, subrelpath(self))) |
447 | 450 |
448 def archive(self, ui, archiver, prefix): | 451 def archive(self, ui, archiver, prefix, match=None): |
449 self._get(self._state + ('hg',)) | 452 self._get(self._state + ('hg',)) |
450 abstractsubrepo.archive(self, ui, archiver, prefix) | 453 abstractsubrepo.archive(self, ui, archiver, prefix, match) |
451 | 454 |
452 rev = self._state[1] | 455 rev = self._state[1] |
453 ctx = self._repo[rev] | 456 ctx = self._repo[rev] |
454 for subpath in ctx.substate: | 457 for subpath in ctx.substate: |
455 s = subrepo(ctx, subpath) | 458 s = subrepo(ctx, subpath) |
456 s.archive(ui, archiver, os.path.join(prefix, self._path)) | 459 submatch = matchmod.narrowmatcher(subpath, match) |
460 s.archive(ui, archiver, os.path.join(prefix, self._path), submatch) | |
457 | 461 |
458 def dirty(self, ignoreupdate=False): | 462 def dirty(self, ignoreupdate=False): |
459 r = self._state[1] | 463 r = self._state[1] |
460 if r == '' and not ignoreupdate: # no state recorded | 464 if r == '' and not ignoreupdate: # no state recorded |
461 return True | 465 return True |
1203 if os.path.isdir(path) and not os.path.islink(path): | 1207 if os.path.isdir(path) and not os.path.islink(path): |
1204 shutil.rmtree(path) | 1208 shutil.rmtree(path) |
1205 else: | 1209 else: |
1206 os.remove(path) | 1210 os.remove(path) |
1207 | 1211 |
1208 def archive(self, ui, archiver, prefix): | 1212 def archive(self, ui, archiver, prefix, match=None): |
1209 source, revision = self._state | 1213 source, revision = self._state |
1210 if not revision: | 1214 if not revision: |
1211 return | 1215 return |
1212 self._fetch(source, revision) | 1216 self._fetch(source, revision) |
1213 | 1217 |
1218 tar = tarfile.open(fileobj=tarstream, mode='r|') | 1222 tar = tarfile.open(fileobj=tarstream, mode='r|') |
1219 relpath = subrelpath(self) | 1223 relpath = subrelpath(self) |
1220 ui.progress(_('archiving (%s)') % relpath, 0, unit=_('files')) | 1224 ui.progress(_('archiving (%s)') % relpath, 0, unit=_('files')) |
1221 for i, info in enumerate(tar): | 1225 for i, info in enumerate(tar): |
1222 if info.isdir(): | 1226 if info.isdir(): |
1227 continue | |
1228 if match and not match(info.name): | |
1223 continue | 1229 continue |
1224 if info.issym(): | 1230 if info.issym(): |
1225 data = info.linkname | 1231 data = info.linkname |
1226 else: | 1232 else: |
1227 data = tar.extractfile(info).read() | 1233 data = tar.extractfile(info).read() |