comparison mercurial/subrepo.py @ 23575:a2f139d25845

subrepo: drop the 'ui' parameter to archive() The current state of subrepo methods is to pass a 'ui' object to some methods, which has the effect of overriding the subrepo configuration since it is the root repo's 'ui' that is passed along as deep as there are subrepos. Other subrepo method are *not* passed the root 'ui', and instead delegate to their repo object's 'ui'. Even in the former case where the root 'ui' is available, some methods are inconsistent in their use of both the root 'ui' and the local repo's 'ui'. (Consider hg._incoming() uses the root 'ui' for path expansion and some status messages, but also calls bundlerepo.getremotechanges(), which eventually calls discovery.findcommonincoming(), which calls setdiscovery.findcommonheads(), which calls status() on the local repo 'ui'.) This inconsistency with respect to the configured output level is probably always hidden, because --verbose, --debug and --quiet, along with their 'ui.xxx' equivalents in the global and user level hgrc files are propagated from the parent repo to the subrepo via 'baseui'. The 'ui.xxx' settings in the parent repo hgrc file are not propagated, but that seems like an unusual thing to set on a per repo config file. Any 'ui.xxx' options changed by --config are also not propagated, because they are set on repo.ui by dispatch.py, not repo.baseui. The goal here is to cleanup the subrepo methods by dropping the 'ui' parameter, which in turn prevents mixing subtly different 'ui' instances on a given subrepo level. Some methods use more than just the output level settings in 'ui' (add for example ends up calling scmutil.checkportabilityalert() with both the root and local repo's 'ui' at different points). This series just goes for the low hanging fruit and switches methods that only use the output level. If we really care about not letting a subrepo config override the root repo's output level, we can propagate the verbose, debug and quiet settings to the subrepo in the same way 'ui.commitsubrepos' is in hgsubrepo.__init__. Archive only uses the 'ui' object to call its progress() method, and gitsubrepo calls status().
author Matt Harbison <matt_harbison@yahoo.com>
date Sat, 13 Dec 2014 14:53:46 -0500
parents faa3d6af154e
children 70a7478c33de
comparison
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):