# HG changeset patch # User Yuya Nishihara # Date 1537365467 -32400 # Node ID a93fe297dfb3f017ce9f9e252d980ed750433b80 # Parent fd805a44b89d3bb61d62057df48179cb99b876ce chgserver: add separate flag to remember if stdio fds are replaced I want to make it use a separate saved buffer for "attachio" requests within "runcommand" session. See the next patch for details. diff -r fd805a44b89d -r a93fe297dfb3 mercurial/chgserver.py --- a/mercurial/chgserver.py Sat Sep 15 21:35:36 2018 +0900 +++ b/mercurial/chgserver.py Wed Sep 19 22:57:47 2018 +0900 @@ -311,6 +311,7 @@ _newchgui(ui, channeledsystem(fin, fout, 'S'), self.attachio), repo, fin, fout) self.clientsock = sock + self._ioattached = False self._oldios = [] # original (self.ch, ui.fp, fd) before "attachio" self.hashstate = hashstate self.baseaddress = baseaddress @@ -324,6 +325,7 @@ # handled by dispatch._dispatch() self.ui.flush() self._restoreio() + self._ioattached = False def attachio(self): """Attach to client's stdio passed via unix domain socket; all @@ -337,13 +339,13 @@ ui = self.ui ui.flush() - first = self._saveio() + self._saveio() for fd, (cn, fn, mode) in zip(clientfds, _iochannels): assert fd > 0 fp = getattr(ui, fn) os.dup2(fd, fp.fileno()) os.close(fd) - if not first: + if self._ioattached: continue # reset buffering mode when client is first attached. as we want # to see output immediately on pager, the mode stays unchanged @@ -362,18 +364,18 @@ setattr(ui, fn, newfp) setattr(self, cn, newfp) + self._ioattached = True self.cresult.write(struct.pack('>i', len(clientfds))) def _saveio(self): if self._oldios: - return False + return ui = self.ui for cn, fn, _mode in _iochannels: ch = getattr(self, cn) fp = getattr(ui, fn) fd = os.dup(fp.fileno()) self._oldios.append((ch, fp, fd)) - return True def _restoreio(self): ui = self.ui