changeset 32572:447bbd970047

cmdutil: extract function checking if pattern should be taken as stdin/out This will be used in commands.cat().
author Yuya Nishihara <yuya@tcha.org>
date Thu, 25 May 2017 21:28:08 +0900
parents 2dd8d4108249
children f4cd4c49e302
files mercurial/cmdutil.py
diffstat 1 files changed, 5 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cmdutil.py	Thu May 25 21:25:49 2017 +0900
+++ b/mercurial/cmdutil.py	Thu May 25 21:28:08 2017 +0900
@@ -610,6 +610,10 @@
         raise error.Abort(_("invalid format spec '%%%s' in output filename") %
                          inst.args[0])
 
+def isstdiofilename(pat):
+    """True if the given pat looks like a filename denoting stdin/stdout"""
+    return not pat or pat == '-'
+
 class _unclosablefile(object):
     def __init__(self, fp):
         self._fp = fp
@@ -635,7 +639,7 @@
 
     writable = mode not in ('r', 'rb')
 
-    if not pat or pat == '-':
+    if isstdiofilename(pat):
         if writable:
             fp = repo.ui.fout
         else: