changeset 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
files hgext/largefiles/overrides.py mercurial/archival.py mercurial/subrepo.py
diffstat 3 files changed, 19 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/largefiles/overrides.py	Sat Dec 13 22:44:22 2014 -0500
+++ b/hgext/largefiles/overrides.py	Sat Dec 13 14:53:46 2014 -0500
@@ -890,16 +890,16 @@
         for subpath in sorted(ctx.substate):
             sub = ctx.sub(subpath)
             submatch = match_.narrowmatcher(subpath, matchfn)
-            sub.archive(repo.ui, archiver, prefix, submatch)
+            sub.archive(archiver, prefix, submatch)
 
     archiver.done()
 
-def hgsubrepoarchive(orig, repo, ui, archiver, prefix, match=None):
+def hgsubrepoarchive(orig, repo, archiver, prefix, match=None):
     repo._get(repo._state + ('hg',))
     rev = repo._state[1]
     ctx = repo._repo[rev]
 
-    lfcommands.cachelfiles(ui, repo._repo, ctx.node())
+    lfcommands.cachelfiles(repo.ui, repo._repo, ctx.node())
 
     def write(name, mode, islink, getdata):
         # At this point, the standin has been replaced with the largefile name,
@@ -937,8 +937,7 @@
     for subpath in sorted(ctx.substate):
         sub = ctx.sub(subpath)
         submatch = match_.narrowmatcher(subpath, match)
-        sub.archive(ui, archiver, os.path.join(prefix, repo._path) + '/',
-                    submatch)
+        sub.archive(archiver, os.path.join(prefix, repo._path) + '/', submatch)
 
 # If a largefile is modified, the change is not reflected in its
 # standin until a commit. cmdutil.bailifchanged() raises an exception
--- a/mercurial/archival.py	Sat Dec 13 22:44:22 2014 -0500
+++ b/mercurial/archival.py	Sat Dec 13 14:53:46 2014 -0500
@@ -304,7 +304,7 @@
         for subpath in sorted(ctx.substate):
             sub = ctx.sub(subpath)
             submatch = matchmod.narrowmatcher(subpath, matchfn)
-            total += sub.archive(repo.ui, archiver, prefix, submatch)
+            total += sub.archive(archiver, prefix, submatch)
 
     if total == 0:
         raise error.Abort(_('no files match the archive pattern'))
--- a/mercurial/subrepo.py	Sat Dec 13 22:44:22 2014 -0500
+++ b/mercurial/subrepo.py	Sat Dec 13 14:53:46 2014 -0500
@@ -469,24 +469,24 @@
         """return file flags"""
         return ''
 
-    def archive(self, ui, archiver, prefix, match=None):
+    def archive(self, archiver, prefix, match=None):
         if match is not None:
             files = [f for f in self.files() if match(f)]
         else:
             files = self.files()
         total = len(files)
         relpath = subrelpath(self)
-        ui.progress(_('archiving (%s)') % relpath, 0,
-                    unit=_('files'), total=total)
+        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)
+            self.ui.progress(_('archiving (%s)') % relpath, i + 1,
+                             unit=_('files'), total=total)
+        self.ui.progress(_('archiving (%s)') % relpath, None)
         return total
 
     def walk(self, match):
@@ -670,16 +670,16 @@
                           % (inst, subrelpath(self)))
 
     @annotatesubrepoerror
-    def archive(self, ui, archiver, prefix, match=None):
+    def archive(self, archiver, prefix, match=None):
         self._get(self._state + ('hg',))
-        total = abstractsubrepo.archive(self, ui, archiver, prefix, match)
+        total = abstractsubrepo.archive(self, archiver, prefix, match)
         rev = self._state[1]
         ctx = self._repo[rev]
         for subpath in ctx.substate:
             s = subrepo(ctx, subpath)
             submatch = matchmod.narrowmatcher(subpath, match)
             total += s.archive(
-                ui, archiver, os.path.join(prefix, self._path), submatch)
+                archiver, os.path.join(prefix, self._path), submatch)
         return total
 
     @annotatesubrepoerror
@@ -1543,7 +1543,7 @@
             else:
                 os.remove(path)
 
-    def archive(self, ui, archiver, prefix, match=None):
+    def archive(self, archiver, prefix, match=None):
         total = 0
         source, revision = self._state
         if not revision:
@@ -1556,7 +1556,7 @@
         tarstream = self._gitcommand(['archive', revision], stream=True)
         tar = tarfile.open(fileobj=tarstream, mode='r|')
         relpath = subrelpath(self)
-        ui.progress(_('archiving (%s)') % relpath, 0, unit=_('files'))
+        self.ui.progress(_('archiving (%s)') % relpath, 0, unit=_('files'))
         for i, info in enumerate(tar):
             if info.isdir():
                 continue
@@ -1569,9 +1569,9 @@
             archiver.addfile(os.path.join(prefix, self._path, info.name),
                              info.mode, info.issym(), data)
             total += 1
-            ui.progress(_('archiving (%s)') % relpath, i + 1,
-                        unit=_('files'))
-        ui.progress(_('archiving (%s)') % relpath, None)
+            self.ui.progress(_('archiving (%s)') % relpath, i + 1,
+                             unit=_('files'))
+        self.ui.progress(_('archiving (%s)') % relpath, None)
         return total