sideband: clear full line when printing remote messages

demultiplex_sideband() can write its remote output over active local progress lines. That's why it has been using ANSI code Erase in Line on smart terminals to clear the remainder of lines it writes since ebe8fa738d (fix display overlap between remote and local progress, 2007-11-04). This erases the last character of remote lines that span the full width of the terminal, though, as the cursor is stuck at the rightmost column for them. It's the same effect as in the following command, which clears the 1 and shows just the leading zeros: $ EL="\033[K" $ printf "%0${COLUMNS}d${EL}\n" 1 If we move the ANSI code to the start we get to see the 1 as well: $ printf "${EL}%0${COLUMNS}d\n" 1 So do the same in demultiplex_sideband() and emit the ANSI code as a prefix instead of a suffix to show messages in full even if they happen to fill the whole width of a smart terminal. Reported-by: Hugo Osvaldo Barrera <hugo@whynothugo.nl> Suggested-by: Chris Torek <chris.torek@gmail.com> Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed May 10, 2026 at 14:42 UTC 31e8fcabd8a75b2c27cd4c98ea694c6836c29ad2
1 file changed +12 -10
sideband.c
+12 -10
@@ -120,7 +120,7 @@ static void maybe_colorize_sideband(struct strbuf *dest, const char *src, int n)
120
121 #define DISPLAY_PREFIX "remote: "
122
123 -#define ANSI_SUFFIX "\033[K"
123 +#define ANSI_PREFIX "\033[K"
124 #define DUMB_SUFFIX " "
125
126 int demultiplex_sideband(const char *me, int status,
@@ -129,15 +129,18 @@ int demultiplex_sideband(const char *me, int status,
129 struct strbuf *scratch,
130 enum sideband_type *sideband_type)
131 {
132 - static const char *suffix;
132 + static const char *prefix, *suffix;
133 const char *b, *brk;
134 int band;
135
136 if (!suffix) {
137 - if (isatty(2) && !is_terminal_dumb())
138 - suffix = ANSI_SUFFIX;
139 - else
137 + if (isatty(2) && !is_terminal_dumb()) {
138 + prefix = ANSI_PREFIX DISPLAY_PREFIX;
139 + suffix = "";
140 + } else {
141 + prefix = DISPLAY_PREFIX;
142 suffix = DUMB_SUFFIX;
143 + }
144 }
145
146 if (status == PACKET_READ_EOF) {
@@ -171,8 +174,7 @@ int demultiplex_sideband(const char *me, int status,
174 case 3:
175 if (die_on_error)
176 die(_("remote error: %s"), buf + 1);
174 - strbuf_addf(scratch, "%s%s", scratch->len ? "\n" : "",
175 - DISPLAY_PREFIX);
177 + strbuf_addf(scratch, "%s%s", scratch->len ? "\n" : "", prefix);
178 maybe_colorize_sideband(scratch, buf + 1, len);
179
180 *sideband_type = SIDEBAND_REMOTE_ERROR;
@@ -203,7 +205,7 @@ int demultiplex_sideband(const char *me, int status,
205 strbuf_addstr(scratch, suffix);
206
207 if (!scratch->len)
206 - strbuf_addstr(scratch, DISPLAY_PREFIX);
208 + strbuf_addstr(scratch, prefix);
209
210 /*
211 * A use case that we should not add clear-to-eol suffix
@@ -229,8 +231,8 @@ int demultiplex_sideband(const char *me, int status,
231 }
232
233 if (*b) {
232 - strbuf_addstr(scratch, scratch->len ?
233 - "" : DISPLAY_PREFIX);
234 + if (!scratch->len)
235 + strbuf_addstr(scratch, prefix);
236 maybe_colorize_sideband(scratch, b, strlen(b));
237 }
238 return 0;