[Concept,04/11] patman: Fix output ordering when running git send-email

Message ID 20260329150140.4095446-5-sjg@u-boot.org
State New
Headers
Series patman: Add workflow tracking for patch series |

Commit Message

Simon Glass March 29, 2026, 3:01 p.m. UTC
  From: Simon Glass <sjg@chromium.org>

When patman runs git send-email, stdout goes through a PTY filter while
stderr goes directly to the terminal. Since git send-email writes
prompts to stderr and email details to stdout, the prompts appear before
the context they relate to (e.g. "Send this email?" appears before the
email headers).

Add a merge_stderr parameter to run_pipe() and use it for the
send-email invocation. This redirects stderr to stdout so both streams
go through the same PTY, preserving the correct output order.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/u_boot_pylib/command.py | 10 ++++++++--
 tools/u_boot_pylib/gitutil.py |  2 +-
 2 files changed, 9 insertions(+), 3 deletions(-)
  

Patch

diff --git a/tools/u_boot_pylib/command.py b/tools/u_boot_pylib/command.py
index 54a7ee8e672..c44bed6acc0 100644
--- a/tools/u_boot_pylib/command.py
+++ b/tools/u_boot_pylib/command.py
@@ -66,7 +66,8 @@  class CommandResult:
 
 def run_pipe(pipe_list, infile=None, outfile=None, capture=False,
              capture_stderr=False, oneline=False, raise_on_error=True, cwd=None,
-             binary=False, output_func=None, stdin_data=None, **kwargs):
+             binary=False, output_func=None, stdin_data=None,
+             merge_stderr=False, **kwargs):
     """
     Perform a command pipeline, with optional input/output filenames.
 
@@ -87,6 +88,9 @@  def run_pipe(pipe_list, infile=None, outfile=None, capture=False,
         output_func (function): Output function to call with each output
             fragment (if it returns True the function terminates)
         stdin_data (str or None): Data to send to the first command's stdin
+        merge_stderr (bool): True to redirect stderr to stdout so that both
+            streams are interleaved in order. Use this for interactive
+            processes where output ordering matters.
         **kwargs: Additional keyword arguments to cros_subprocess.Popen()
     Returns:
         CommandResult object
@@ -123,7 +127,9 @@  def run_pipe(pipe_list, infile=None, outfile=None, capture=False,
                 kwargs['stdout'] = cros_subprocess.PIPE
         elif outfile:
             kwargs['stdout'] = open(outfile, 'wb')
-        if capture_stderr:
+        if merge_stderr:
+            kwargs['stderr'] = cros_subprocess.STDOUT
+        elif capture_stderr:
             kwargs['stderr'] = cros_subprocess.PIPE
 
         try:
diff --git a/tools/u_boot_pylib/gitutil.py b/tools/u_boot_pylib/gitutil.py
index 22414d250a9..8e45727b47a 100644
--- a/tools/u_boot_pylib/gitutil.py
+++ b/tools/u_boot_pylib/gitutil.py
@@ -563,7 +563,7 @@  send --cc-cmd cc-fname" cover p1 p2', 0)
 
         result = command.run_pipe(
             [cmd], capture=True, output_func=echo_output,
-            raise_on_error=False, cwd=cwd)
+            raise_on_error=False, cwd=cwd, merge_stderr=True)
         num_sent = result.stdout.count('Result: ')
     cmd_str = ' '.join([f'"{x}"' if ' ' in x and '"' not in x else x
                         for x in cmd])