Patchwork [4,of,4] cat: do not start pager if output will be written to file

login
register
mail settings
Submitter Yuya Nishihara
Date May 29, 2017, 2:30 p.m.
Message ID <83f8983d78df7b104718.1496068251@mimosa>
Download mbox | patch
Permalink /patch/21045/
State Accepted
Headers show

Comments

Yuya Nishihara - May 29, 2017, 2:30 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1495878766 -32400
#      Sat May 27 18:52:46 2017 +0900
# Node ID 83f8983d78df7b104718d8b791573e2264a9c38c
# Parent  40e47e738813d92676f838c8a8e0757f9f7d70f3
cat: do not start pager if output will be written to file
Augie Fackler - May 29, 2017, 2:34 p.m.
> On May 29, 2017, at 10:30 AM, Yuya Nishihara <yuya@tcha.org> wrote:
> 
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1495878766 -32400
> #      Sat May 27 18:52:46 2017 +0900
> # Node ID 83f8983d78df7b104718d8b791573e2264a9c38c
> # Parent  40e47e738813d92676f838c8a8e0757f9f7d70f3
> cat: do not start pager if output will be written to file

Nice, queued.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1364,8 +1364,11 @@  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')
+    if cmdutil.isstdiofilename(fntemplate):
+        fntemplate = ''
+
+    if not fntemplate:
+        ui.pager('cat')
     return cmdutil.cat(ui, repo, ctx, m, fntemplate, '', **opts)
 
 @command('^clone',
diff --git a/tests/test-pager.t b/tests/test-pager.t
--- a/tests/test-pager.t
+++ b/tests/test-pager.t
@@ -1,7 +1,11 @@ 
   $ cat >> fakepager.py <<EOF
   > import sys
+  > printed = False
   > for line in sys.stdin:
   >     sys.stdout.write('paged! %r\n' % line)
+  >     printed = True
+  > if not printed:
+  >     sys.stdout.write('paged empty output!\n')
   > EOF
 
 Enable ui.formatted because pager won't fire without it, and set up
@@ -281,6 +285,15 @@  explicit flags work too:
    9: a 9
   10: a 10
 
+A command with --output option:
+
+  $ hg cat -r0 a
+  paged! 'a\n'
+  $ hg cat -r0 a --output=-
+  paged! 'a\n'
+  $ hg cat -r0 a --output=out
+  $ rm out
+
 Put annotate in the ignore list for pager:
   $ cat >> $HGRCPATH <<EOF
   > [pager]