[PATCH 3 of 4] cat: pass filename template as explicit argument

Yuya Nishihara yuya at tcha.org
Mon May 29 10:30:50 EDT 2017


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1495878605 -32400
#      Sat May 27 18:50:05 2017 +0900
# Node ID 40e47e738813d92676f838c8a8e0757f9f7d70f3
# Parent  92f79d1f0c27a9883d4a5b629dd090367c3a89a4
cat: pass filename template as explicit argument

I'll move the handling of the '-' filename to commands.cat().

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2632,11 +2632,11 @@ def remove(ui, repo, m, prefix, after, f
 
     return ret
 
-def cat(ui, repo, ctx, matcher, prefix, **opts):
+def cat(ui, repo, ctx, matcher, fntemplate, prefix, **opts):
     err = 1
 
     def write(path):
-        fp = makefileobj(repo, opts.get('output'), ctx.node(),
+        fp = makefileobj(repo, fntemplate, ctx.node(),
                          pathname=os.path.join(prefix, path))
         data = ctx[path].data()
         if opts.get('decode'):
@@ -2666,8 +2666,8 @@ def cat(ui, repo, ctx, matcher, prefix, 
         try:
             submatch = matchmod.subdirmatcher(subpath, matcher)
 
-            if not sub.cat(submatch, os.path.join(prefix, sub._path),
-                           **opts):
+            if not sub.cat(submatch, fntemplate,
+                           os.path.join(prefix, sub._path), **opts):
                 err = 0
         except error.RepoLookupError:
             ui.status(_("skipping missing subrepository: %s\n")
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1363,9 +1363,10 @@ def cat(ui, repo, file1, *pats, **opts):
     """
     ctx = scmutil.revsingle(repo, opts.get('rev'))
     m = scmutil.match(ctx, (file1,) + pats, opts)
+    fntemplate = opts.pop('output', '')
 
     ui.pager('cat')
-    return cmdutil.cat(ui, repo, ctx, m, '', **opts)
+    return cmdutil.cat(ui, repo, ctx, m, fntemplate, '', **opts)
 
 @command('^clone',
     [('U', 'noupdate', None, _('the clone will include an empty working '
diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -538,7 +538,7 @@ class abstractsubrepo(object):
         self.ui.warn("%s: %s" % (prefix, _("addremove is not supported")))
         return 1
 
-    def cat(self, match, prefix, **opts):
+    def cat(self, match, fntemplate, prefix, **opts):
         return 1
 
     def status(self, rev2, **opts):
@@ -767,10 +767,11 @@ class hgsubrepo(abstractsubrepo):
                                  dry_run, similarity)
 
     @annotatesubrepoerror
-    def cat(self, match, prefix, **opts):
+    def cat(self, match, fntemplate, prefix, **opts):
         rev = self._state[1]
         ctx = self._repo[rev]
-        return cmdutil.cat(self.ui, self._repo, ctx, match, prefix, **opts)
+        return cmdutil.cat(self.ui, self._repo, ctx, match, fntemplate, prefix,
+                           **opts)
 
     @annotatesubrepoerror
     def status(self, rev2, **opts):
@@ -1832,7 +1833,7 @@ class gitsubrepo(abstractsubrepo):
 
 
     @annotatesubrepoerror
-    def cat(self, match, prefix, **opts):
+    def cat(self, match, fntemplate, prefix, **opts):
         rev = self._state[1]
         if match.anypats():
             return 1 #No support for include/exclude yet
@@ -1842,7 +1843,7 @@ class gitsubrepo(abstractsubrepo):
 
         for f in match.files():
             output = self._gitcommand(["show", "%s:%s" % (rev, f)])
-            fp = cmdutil.makefileobj(self._subparent, opts.get('output'),
+            fp = cmdutil.makefileobj(self._subparent, fntemplate,
                                      self._ctx.node(),
                                      pathname=self.wvfs.reljoin(prefix, f))
             fp.write(output)


More information about the Mercurial-devel mailing list