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

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

Comments

Yuya Nishihara - May 29, 2017, 2:30 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@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().
via Mercurial-devel - May 31, 2017, 9:47 p.m.
On Mon, May 29, 2017 at 7:30 AM, Yuya Nishihara <yuya@tcha.org> wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@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 == '-'

Looks like you could use this in logmessage() as well.

> +
>  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:
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

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: