Mercurial > hg
comparison mercurial/ui.py @ 40539:04a9dd8da959
ui: move pre/post processes from low-level write()s to _writenobuf()
This helps adding a dedicated stream for status/error messages. I don't
want to add _write*() function per stream.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 03 Nov 2018 18:03:09 +0900 |
parents | c5e964f75bf7 |
children | 06e841e72523 |
comparison
equal
deleted
inserted
replaced
40538:c5e964f75bf7 | 40539:04a9dd8da959 |
---|---|
960 msg = b''.join(args) | 960 msg = b''.join(args) |
961 | 961 |
962 # opencode timeblockedsection because this is a critical path | 962 # opencode timeblockedsection because this is a critical path |
963 starttime = util.timer() | 963 starttime = util.timer() |
964 try: | 964 try: |
965 if dest is self.ferr and not getattr(self.fout, 'closed', False): | |
966 self.fout.flush() | |
965 if self._colormode == 'win32': | 967 if self._colormode == 'win32': |
966 # windows color printing is its own can of crab, defer to | 968 # windows color printing is its own can of crab, defer to |
967 # the color module and that is it. | 969 # the color module and that is it. |
968 color.win32print(self, write, msg, **opts) | 970 color.win32print(self, write, msg, **opts) |
969 else: | 971 else: |
970 if self._colormode is not None: | 972 if self._colormode is not None: |
971 label = opts.get(r'label', '') | 973 label = opts.get(r'label', '') |
972 msg = self.label(msg, label) | 974 msg = self.label(msg, label) |
973 write(msg) | 975 write(msg) |
976 # stderr may be buffered under win32 when redirected to files, | |
977 # including stdout. | |
978 if dest is self.ferr and not getattr(self.ferr, 'closed', False): | |
979 dest.flush() | |
980 except IOError as err: | |
981 if (dest is self.ferr | |
982 and err.errno in (errno.EPIPE, errno.EIO, errno.EBADF)): | |
983 # no way to report the error, so ignore it | |
984 return | |
985 raise error.StdioError(err) | |
974 finally: | 986 finally: |
975 self._blockedtimes['stdio_blocked'] += \ | 987 self._blockedtimes['stdio_blocked'] += \ |
976 (util.timer() - starttime) * 1000 | 988 (util.timer() - starttime) * 1000 |
977 | 989 |
978 def _write(self, data): | 990 def _write(self, data): |
979 try: | 991 self.fout.write(data) |
980 self.fout.write(data) | |
981 except IOError as err: | |
982 raise error.StdioError(err) | |
983 | 992 |
984 def write_err(self, *args, **opts): | 993 def write_err(self, *args, **opts): |
985 if self._bufferstates and self._bufferstates[-1][0]: | 994 if self._bufferstates and self._bufferstates[-1][0]: |
986 self.write(*args, **opts) | 995 self.write(*args, **opts) |
987 else: | 996 else: |
988 self._writenobuf(self.ferr, *args, **opts) | 997 self._writenobuf(self.ferr, *args, **opts) |
989 | 998 |
990 def _write_err(self, data): | 999 def _write_err(self, data): |
991 try: | 1000 self.ferr.write(data) |
992 if True: | |
993 if not getattr(self.fout, 'closed', False): | |
994 self.fout.flush() | |
995 self.ferr.write(data) | |
996 # stderr may be buffered under win32 when redirected to files, | |
997 # including stdout. | |
998 if not getattr(self.ferr, 'closed', False): | |
999 self.ferr.flush() | |
1000 except IOError as inst: | |
1001 if inst.errno not in (errno.EPIPE, errno.EIO, errno.EBADF): | |
1002 raise error.StdioError(inst) | |
1003 | 1001 |
1004 def flush(self): | 1002 def flush(self): |
1005 # opencode timeblockedsection because this is a critical path | 1003 # opencode timeblockedsection because this is a critical path |
1006 starttime = util.timer() | 1004 starttime = util.timer() |
1007 try: | 1005 try: |