# HG changeset patch # User Pierre-Yves David # Date 1397705817 14400 # Node ID 350dc24a553dfa0188b7fd2380f5d420a200b6b8 # Parent b7435117d9511f186cc34421b728d8ece845f0d5 ui: pushbuffer can now also capture stderr We need an easy way to capture both stderr and stdout during bundle2 processing of a remote bundle. This changeset adds simple changes to the `ui` class to make this possible. I expect the interface to change in future releases as bundle2 will probably want to distinguish stdout and stderr. The current change will, however, do for now. diff -r b7435117d951 -r 350dc24a553d mercurial/ui.py --- a/mercurial/ui.py Wed Apr 16 14:22:24 2014 -0400 +++ b/mercurial/ui.py Wed Apr 16 23:36:57 2014 -0400 @@ -12,7 +12,10 @@ class ui(object): def __init__(self, src=None): + # _buffers: used for temporary capture of output self._buffers = [] + # _bufferstates: Should the temporary capture includes stderr + self._bufferstates = [] self.quiet = self.verbose = self.debugflag = self.tracebackflag = False self._reportuntrusted = True self._ocfg = config.config() # overlay @@ -471,8 +474,12 @@ path = self.config('paths', default) return path or loc - def pushbuffer(self): + def pushbuffer(self, error=False): + """install a buffer to capture standar output of the ui object + + If error is True, the error output will be captured too.""" self._buffers.append([]) + self._bufferstates.append(error) def popbuffer(self, labeled=False): '''pop the last buffer and return the buffered output @@ -484,6 +491,7 @@ is being buffered so it can be captured and parsed or processed, labeled should not be set to True. ''' + self._bufferstates.pop() return "".join(self._buffers.pop()) def write(self, *args, **opts): @@ -511,6 +519,8 @@ def write_err(self, *args, **opts): try: + if self._bufferstates and self._bufferstates[-1]: + return self.write(*args, **opts) if not getattr(self.fout, 'closed', False): self.fout.flush() for a in args: