Subject: [PATCH v2 3/4] sideband: append suffix for message whose CR in next pktline

From: Jiang Xin <[email-masked]>
Date: Sat, 12 Jun 2021 13:07:10 +0800

From: Jiang Xin <[email-masked]>

When calling "demultiplex_sideband" on a sideband-2 message, will try to
split the message by line breaks, and append a suffix to each nonempty
line to clear the end of the screen line. But in the following example,
there will be no suffix (8 spaces) for "<message-3>":

    PKT-LINE(\2 <message-1> CR <message-2> CR <message-3>)
    PKT-LINE(\2 CR <message-4> CR <message-5> CR)

This is because the line break of "<message-3>" is placed in the next
pktline message.

Without this fix, t5411 must remove trailing spaces of the actual output
of "git-push" command before comparing.

Signed-off-by: Jiang Xin <[email-masked]>
---
 sideband.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/sideband.c b/sideband.c
index 6f9e026732..abf2be98e1 100644
--- a/sideband.c
+++ b/sideband.c
@@ -185,6 +185,10 @@ int demultiplex_sideband(const char *me, int status,
 
 			if (!scratch->len)
 				strbuf_addstr(scratch, DISPLAY_PREFIX);
+			else if (!linelen)
+				/* buf has a leading CR which ends the remaining
+				 * scratch of last round of "demultiplex_sideband" */
+				strbuf_addstr(scratch, suffix);
 			if (linelen > 0) {
 				maybe_colorize_sideband(scratch, b, linelen);
 				strbuf_addstr(scratch, suffix);
-- 
2.32.0.rc0.27.g7b1e85181b