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

Martin von Zweigbergk martinvonz at google.com
Wed May 31 17:47:13 EDT 2017


On Mon, May 29, 2017 at 7:30 AM, Yuya Nishihara <yuya at tcha.org> wrote:
> # 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 == '-'

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 at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


More information about the Mercurial-devel mailing list