mercurial/ui.py
changeset 40540 06e841e72523
parent 40539 04a9dd8da959
child 40541 c2aea007130b
equal deleted inserted replaced
40539:04a9dd8da959 40540:06e841e72523
   949         else:
   949         else:
   950             self._writenobuf(self.fout, *args, **opts)
   950             self._writenobuf(self.fout, *args, **opts)
   951 
   951 
   952     def _writenobuf(self, dest, *args, **opts):
   952     def _writenobuf(self, dest, *args, **opts):
   953         self._progclear()
   953         self._progclear()
   954         if dest is self.fout:
       
   955             write = self._write
       
   956         elif dest is self.ferr:
       
   957             write = self._write_err
       
   958         else:
       
   959             raise error.ProgrammingError('unsupported file to write')
       
   960         msg = b''.join(args)
   954         msg = b''.join(args)
   961 
   955 
   962         # opencode timeblockedsection because this is a critical path
   956         # opencode timeblockedsection because this is a critical path
   963         starttime = util.timer()
   957         starttime = util.timer()
   964         try:
   958         try:
   965             if dest is self.ferr and not getattr(self.fout, 'closed', False):
   959             if dest is self.ferr and not getattr(self.fout, 'closed', False):
   966                 self.fout.flush()
   960                 self.fout.flush()
   967             if self._colormode == 'win32':
   961             if self._colormode == 'win32':
   968                 # windows color printing is its own can of crab, defer to
   962                 # windows color printing is its own can of crab, defer to
   969                 # the color module and that is it.
   963                 # the color module and that is it.
   970                 color.win32print(self, write, msg, **opts)
   964                 color.win32print(self, dest.write, msg, **opts)
   971             else:
   965             else:
   972                 if self._colormode is not None:
   966                 if self._colormode is not None:
   973                     label = opts.get(r'label', '')
   967                     label = opts.get(r'label', '')
   974                     msg = self.label(msg, label)
   968                     msg = self.label(msg, label)
   975                 write(msg)
   969                 dest.write(msg)
   976             # stderr may be buffered under win32 when redirected to files,
   970             # stderr may be buffered under win32 when redirected to files,
   977             # including stdout.
   971             # including stdout.
   978             if dest is self.ferr and not getattr(self.ferr, 'closed', False):
   972             if dest is self.ferr and not getattr(self.ferr, 'closed', False):
   979                 dest.flush()
   973                 dest.flush()
   980         except IOError as err:
   974         except IOError as err:
   985             raise error.StdioError(err)
   979             raise error.StdioError(err)
   986         finally:
   980         finally:
   987             self._blockedtimes['stdio_blocked'] += \
   981             self._blockedtimes['stdio_blocked'] += \
   988                 (util.timer() - starttime) * 1000
   982                 (util.timer() - starttime) * 1000
   989 
   983 
   990     def _write(self, data):
       
   991         self.fout.write(data)
       
   992 
       
   993     def write_err(self, *args, **opts):
   984     def write_err(self, *args, **opts):
   994         if self._bufferstates and self._bufferstates[-1][0]:
   985         if self._bufferstates and self._bufferstates[-1][0]:
   995             self.write(*args, **opts)
   986             self.write(*args, **opts)
   996         else:
   987         else:
   997             self._writenobuf(self.ferr, *args, **opts)
   988             self._writenobuf(self.ferr, *args, **opts)
   998 
       
   999     def _write_err(self, data):
       
  1000         self.ferr.write(data)
       
  1001 
   989 
  1002     def flush(self):
   990     def flush(self):
  1003         # opencode timeblockedsection because this is a critical path
   991         # opencode timeblockedsection because this is a critical path
  1004         starttime = util.timer()
   992         starttime = util.timer()
  1005         try:
   993         try: