cmdutil: extract function checking if pattern should be taken as stdin/out
authorYuya Nishihara <yuya@tcha.org>
Thu, 25 May 2017 21:28:08 +0900
changeset 32572 447bbd970047
parent 32571 2dd8d4108249
child 32573 f4cd4c49e302
cmdutil: extract function checking if pattern should be taken as stdin/out This will be used in commands.cat().
mercurial/cmdutil.py
--- 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: