# HG changeset patch # User Yuya Nishihara # Date 2017-05-25 12:28:08 # Node ID 447bbd9700471a4477dc7b4414efb4be06776d6c # Parent 2dd8d410824999d28dc06697a82055cf5045cca0 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: