1000 a label of "status.modified" for modified files. |
1000 a label of "status.modified" for modified files. |
1001 ''' |
1001 ''' |
1002 dest = self._fout |
1002 dest = self._fout |
1003 |
1003 |
1004 # inlined _write() for speed |
1004 # inlined _write() for speed |
|
1005 if self._buffers: |
|
1006 label = opts.get(r'label', '') |
|
1007 if label and self._bufferapplylabels: |
|
1008 self._buffers[-1].extend(self.label(a, label) for a in args) |
|
1009 else: |
|
1010 self._buffers[-1].extend(args) |
|
1011 return |
|
1012 |
|
1013 # inliend _writenobuf() for speed |
|
1014 self._progclear() |
|
1015 msg = b''.join(args) |
|
1016 |
|
1017 # opencode timeblockedsection because this is a critical path |
|
1018 starttime = util.timer() |
|
1019 try: |
|
1020 if self._colormode == 'win32': |
|
1021 # windows color printing is its own can of crab, defer to |
|
1022 # the color module and that is it. |
|
1023 color.win32print(self, dest.write, msg, **opts) |
|
1024 else: |
|
1025 if self._colormode is not None: |
|
1026 label = opts.get(r'label', '') |
|
1027 msg = self.label(msg, label) |
|
1028 dest.write(msg) |
|
1029 except IOError as err: |
|
1030 raise error.StdioError(err) |
|
1031 finally: |
|
1032 self._blockedtimes['stdio_blocked'] += \ |
|
1033 (util.timer() - starttime) * 1000 |
|
1034 |
|
1035 def write_err(self, *args, **opts): |
|
1036 self._write(self._ferr, *args, **opts) |
|
1037 |
|
1038 def _write(self, dest, *args, **opts): |
|
1039 # update write() as well if you touch this code |
1005 if self._isbuffered(dest): |
1040 if self._isbuffered(dest): |
1006 label = opts.get(r'label', '') |
1041 label = opts.get(r'label', '') |
1007 if label and self._bufferapplylabels: |
1042 if label and self._bufferapplylabels: |
1008 self._buffers[-1].extend(self.label(a, label) for a in args) |
1043 self._buffers[-1].extend(self.label(a, label) for a in args) |
1009 else: |
1044 else: |
1010 self._buffers[-1].extend(args) |
1045 self._buffers[-1].extend(args) |
1011 return |
1046 else: |
1012 |
1047 self._writenobuf(dest, *args, **opts) |
1013 # inliend _writenobuf() for speed |
1048 |
|
1049 def _writenobuf(self, dest, *args, **opts): |
|
1050 # update write() as well if you touch this code |
1014 self._progclear() |
1051 self._progclear() |
1015 msg = b''.join(args) |
1052 msg = b''.join(args) |
1016 |
1053 |
1017 # opencode timeblockedsection because this is a critical path |
1054 # opencode timeblockedsection because this is a critical path |
1018 starttime = util.timer() |
1055 starttime = util.timer() |
1044 raise error.StdioError(err) |
1081 raise error.StdioError(err) |
1045 finally: |
1082 finally: |
1046 self._blockedtimes['stdio_blocked'] += \ |
1083 self._blockedtimes['stdio_blocked'] += \ |
1047 (util.timer() - starttime) * 1000 |
1084 (util.timer() - starttime) * 1000 |
1048 |
1085 |
1049 def write_err(self, *args, **opts): |
|
1050 self._write(self._ferr, *args, **opts) |
|
1051 |
|
1052 def _write(self, dest, *args, **opts): |
|
1053 # update write() as well if you touch this code |
|
1054 if self._isbuffered(dest): |
|
1055 label = opts.get(r'label', '') |
|
1056 if label and self._bufferapplylabels: |
|
1057 self._buffers[-1].extend(self.label(a, label) for a in args) |
|
1058 else: |
|
1059 self._buffers[-1].extend(args) |
|
1060 else: |
|
1061 self._writenobuf(dest, *args, **opts) |
|
1062 |
|
1063 def _writenobuf(self, dest, *args, **opts): |
|
1064 # update write() as well if you touch this code |
|
1065 self._progclear() |
|
1066 msg = b''.join(args) |
|
1067 |
|
1068 # opencode timeblockedsection because this is a critical path |
|
1069 starttime = util.timer() |
|
1070 try: |
|
1071 if dest is self._ferr and not getattr(self._fout, 'closed', False): |
|
1072 self._fout.flush() |
|
1073 if getattr(dest, 'structured', False): |
|
1074 # channel for machine-readable output with metadata, where |
|
1075 # no extra colorization is necessary. |
|
1076 dest.write(msg, **opts) |
|
1077 elif self._colormode == 'win32': |
|
1078 # windows color printing is its own can of crab, defer to |
|
1079 # the color module and that is it. |
|
1080 color.win32print(self, dest.write, msg, **opts) |
|
1081 else: |
|
1082 if self._colormode is not None: |
|
1083 label = opts.get(r'label', '') |
|
1084 msg = self.label(msg, label) |
|
1085 dest.write(msg) |
|
1086 # stderr may be buffered under win32 when redirected to files, |
|
1087 # including stdout. |
|
1088 if dest is self._ferr and not getattr(self._ferr, 'closed', False): |
|
1089 dest.flush() |
|
1090 except IOError as err: |
|
1091 if (dest is self._ferr |
|
1092 and err.errno in (errno.EPIPE, errno.EIO, errno.EBADF)): |
|
1093 # no way to report the error, so ignore it |
|
1094 return |
|
1095 raise error.StdioError(err) |
|
1096 finally: |
|
1097 self._blockedtimes['stdio_blocked'] += \ |
|
1098 (util.timer() - starttime) * 1000 |
|
1099 |
|
1100 def _writemsg(self, dest, *args, **opts): |
1086 def _writemsg(self, dest, *args, **opts): |
1101 _writemsgwith(self._write, dest, *args, **opts) |
1087 _writemsgwith(self._write, dest, *args, **opts) |
1102 |
1088 |
1103 def _writemsgnobuf(self, dest, *args, **opts): |
1089 def _writemsgnobuf(self, dest, *args, **opts): |
1104 _writemsgwith(self._writenobuf, dest, *args, **opts) |
1090 _writemsgwith(self._writenobuf, dest, *args, **opts) |