cat: do not start pager if output will be written to file

This commit is contained in:
Yuya Nishihara 2017-05-27 18:52:46 +09:00
parent 1d54e26edc
commit 4a4dca2dbc
2 changed files with 17 additions and 1 deletions

View File

@ -1364,8 +1364,11 @@ def cat(ui, repo, file1, *pats, **opts):
ctx = scmutil.revsingle(repo, opts.get('rev')) ctx = scmutil.revsingle(repo, opts.get('rev'))
m = scmutil.match(ctx, (file1,) + pats, opts) m = scmutil.match(ctx, (file1,) + pats, opts)
fntemplate = opts.pop('output', '') fntemplate = opts.pop('output', '')
if cmdutil.isstdiofilename(fntemplate):
fntemplate = ''
ui.pager('cat') if not fntemplate:
ui.pager('cat')
return cmdutil.cat(ui, repo, ctx, m, fntemplate, '', **opts) return cmdutil.cat(ui, repo, ctx, m, fntemplate, '', **opts)
@command('^clone', @command('^clone',

View File

@ -1,7 +1,11 @@
$ cat >> fakepager.py <<EOF $ cat >> fakepager.py <<EOF
> import sys > import sys
> printed = False
> for line in sys.stdin: > for line in sys.stdin:
> sys.stdout.write('paged! %r\n' % line) > sys.stdout.write('paged! %r\n' % line)
> printed = True
> if not printed:
> sys.stdout.write('paged empty output!\n')
> EOF > EOF
Enable ui.formatted because pager won't fire without it, and set up Enable ui.formatted because pager won't fire without it, and set up
@ -281,6 +285,15 @@ explicit flags work too:
9: a 9 9: a 9
10: a 10 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: Put annotate in the ignore list for pager:
$ cat >> $HGRCPATH <<EOF $ cat >> $HGRCPATH <<EOF
> [pager] > [pager]