Patchwork [1,of,2,V4] perf: omit copying ui and redirect to ferr if buffer API is in use

login
register
mail settings
Submitter Philippe Pepiot
Date Nov. 16, 2016, 9:28 a.m.
Message ID <ab6e50ddc2c56dcf1709.1479288487@sh71.tls.logilab.fr>
Download mbox | patch
Permalink /patch/17598/
State Accepted
Headers show

Comments

Philippe Pepiot - Nov. 16, 2016, 9:28 a.m.
# HG changeset patch
# User Philippe Pepiot <philippe.pepiot@logilab.fr>
# Date 1479222657 -3600
#      Tue Nov 15 16:10:57 2016 +0100
# Node ID ab6e50ddc2c56dcf170991293005be6d6f80a232
# Parent  e1d6aa0e4c3aed73e0dc523b8a8fd5f9fe23510a
perf: omit copying ui and redirect to ferr if buffer API is in use

This allow to get the output of contrib/perf.py commands using the
ui.pushbuffer() API.
Yuya Nishihara - Nov. 16, 2016, 1:10 p.m.
On Wed, 16 Nov 2016 10:28:07 +0100, Philippe Pepiot wrote:
> # HG changeset patch
> # User Philippe Pepiot <philippe.pepiot@logilab.fr>
> # Date 1479222657 -3600
> #      Tue Nov 15 16:10:57 2016 +0100
> # Node ID ab6e50ddc2c56dcf170991293005be6d6f80a232
> # Parent  e1d6aa0e4c3aed73e0dc523b8a8fd5f9fe23510a
> perf: omit copying ui and redirect to ferr if buffer API is in use

Queued the series per the last reviews. Thanks for both writing and reviewing
this.

Patch

diff --git a/contrib/perf.py b/contrib/perf.py
--- a/contrib/perf.py
+++ b/contrib/perf.py
@@ -136,13 +136,14 @@  def gettimer(ui, opts=None):
 
     if opts is None:
         opts = {}
-    # redirect all to stderr
-    ui = ui.copy()
-    uifout = safeattrsetter(ui, 'fout', ignoremissing=True)
-    if uifout:
-        # for "historical portability":
-        # ui.fout/ferr have been available since 1.9 (or 4e1ccd4c2b6d)
-        uifout.set(ui.ferr)
+    # redirect all to stderr unless buffer api is in use
+    if not ui._buffers:
+        ui = ui.copy()
+        uifout = safeattrsetter(ui, 'fout', ignoremissing=True)
+        if uifout:
+            # for "historical portability":
+            # ui.fout/ferr have been available since 1.9 (or 4e1ccd4c2b6d)
+            uifout.set(ui.ferr)
 
     # get a formatter
     uiformatter = getattr(ui, 'formatter', None)