comparison mercurial/cmdutil.py @ 32572:447bbd970047

cmdutil: extract function checking if pattern should be taken as stdin/out This will be used in commands.cat().
author Yuya Nishihara <yuya@tcha.org>
date Thu, 25 May 2017 21:28:08 +0900
parents 2dd8d4108249
children f4cd4c49e302
comparison
equal deleted inserted replaced
32571:2dd8d4108249 32572:447bbd970047
608 return ''.join(newname) 608 return ''.join(newname)
609 except KeyError as inst: 609 except KeyError as inst:
610 raise error.Abort(_("invalid format spec '%%%s' in output filename") % 610 raise error.Abort(_("invalid format spec '%%%s' in output filename") %
611 inst.args[0]) 611 inst.args[0])
612 612
613 def isstdiofilename(pat):
614 """True if the given pat looks like a filename denoting stdin/stdout"""
615 return not pat or pat == '-'
616
613 class _unclosablefile(object): 617 class _unclosablefile(object):
614 def __init__(self, fp): 618 def __init__(self, fp):
615 self._fp = fp 619 self._fp = fp
616 620
617 def close(self): 621 def close(self):
633 seqno=None, revwidth=None, mode='wb', modemap=None, 637 seqno=None, revwidth=None, mode='wb', modemap=None,
634 pathname=None): 638 pathname=None):
635 639
636 writable = mode not in ('r', 'rb') 640 writable = mode not in ('r', 'rb')
637 641
638 if not pat or pat == '-': 642 if isstdiofilename(pat):
639 if writable: 643 if writable:
640 fp = repo.ui.fout 644 fp = repo.ui.fout
641 else: 645 else:
642 fp = repo.ui.fin 646 fp = repo.ui.fin
643 return _unclosablefile(fp) 647 return _unclosablefile(fp)