[PATCH 2 of 4] cmdutil: extract function checking if pattern should be taken as stdin/out

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


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1495715288 -32400
#      Thu May 25 21:28:08 2017 +0900
# Node ID 92f79d1f0c27a9883d4a5b629dd090367c3a89a4
# Parent  f5488f76ec965a9d84d8101fc856c221c63e7ad9
cmdutil: extract function checking if pattern should be taken as stdin/out

This will be used in commands.cat().

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -610,6 +610,10 @@ def makefilename(repo, pat, node, desc=N
         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 @@ def makefileobj(repo, pat, node=None, de
 
     writable = mode not in ('r', 'rb')
 
-    if not pat or pat == '-':
+    if isstdiofilename(pat):
         if writable:
             fp = repo.ui.fout
         else:


More information about the Mercurial-devel mailing list