Git development
 help / color / mirror / Atom feed
From: "René Scharfe" <l.s.r@web.de>
To: Chris Torek <chris.torek@gmail.com>,
	Hugo Osvaldo Barrera <hugo@whynothugo.nl>
Cc: git@vger.kernel.org
Subject: [PATCH] sideband: clear full line when printing remote messages
Date: Sun, 10 May 2026 14:42:04 +0200	[thread overview]
Message-ID: <9826dabf-c9a6-4397-8ae6-a24f9c507f1b@web.de> (raw)
In-Reply-To: <CAPx1Gvf5Vts3oS2BdFQ4PpCR-UY=5cYW7fgOkRuQpi8ug2JXDg@mail.gmail.com>

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>
---
 sideband.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/sideband.c b/sideband.c
index ea7c25211e..48ed4c8099 100644
--- a/sideband.c
+++ b/sideband.c
@@ -120,7 +120,7 @@ static void maybe_colorize_sideband(struct strbuf *dest, const char *src, int n)
 
 #define DISPLAY_PREFIX "remote: "
 
-#define ANSI_SUFFIX "\033[K"
+#define ANSI_PREFIX "\033[K"
 #define DUMB_SUFFIX "        "
 
 int demultiplex_sideband(const char *me, int status,
@@ -129,15 +129,18 @@ int demultiplex_sideband(const char *me, int status,
 			 struct strbuf *scratch,
 			 enum sideband_type *sideband_type)
 {
-	static const char *suffix;
+	static const char *prefix, *suffix;
 	const char *b, *brk;
 	int band;
 
 	if (!suffix) {
-		if (isatty(2) && !is_terminal_dumb())
-			suffix = ANSI_SUFFIX;
-		else
+		if (isatty(2) && !is_terminal_dumb()) {
+			prefix = ANSI_PREFIX DISPLAY_PREFIX;
+			suffix = "";
+		} else {
+			prefix = DISPLAY_PREFIX;
 			suffix = DUMB_SUFFIX;
+		}
 	}
 
 	if (status == PACKET_READ_EOF) {
@@ -171,8 +174,7 @@ int demultiplex_sideband(const char *me, int status,
 	case 3:
 		if (die_on_error)
 			die(_("remote error: %s"), buf + 1);
-		strbuf_addf(scratch, "%s%s", scratch->len ? "\n" : "",
-			    DISPLAY_PREFIX);
+		strbuf_addf(scratch, "%s%s", scratch->len ? "\n" : "", prefix);
 		maybe_colorize_sideband(scratch, buf + 1, len);
 
 		*sideband_type = SIDEBAND_REMOTE_ERROR;
@@ -203,7 +205,7 @@ int demultiplex_sideband(const char *me, int status,
 				strbuf_addstr(scratch, suffix);
 
 			if (!scratch->len)
-				strbuf_addstr(scratch, DISPLAY_PREFIX);
+				strbuf_addstr(scratch, prefix);
 
 			/*
 			 * A use case that we should not add clear-to-eol suffix
@@ -229,8 +231,8 @@ int demultiplex_sideband(const char *me, int status,
 		}
 
 		if (*b) {
-			strbuf_addstr(scratch, scratch->len ?
-				    "" : DISPLAY_PREFIX);
+			if (!scratch->len)
+				strbuf_addstr(scratch, prefix);
 			maybe_colorize_sideband(scratch, b, strlen(b));
 		}
 		return 0;
-- 
2.54.0

  parent reply	other threads:[~2026-05-10 12:42 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-04 17:01 Git trims the last character of content from remotes Hugo Osvaldo Barrera
2026-05-05  0:34 ` Chris Torek
2026-05-05 19:41   ` René Scharfe
2026-05-06  9:37     ` Mikael Magnusson
2026-05-06  9:40       ` Mikael Magnusson
2026-05-06 16:00         ` René Scharfe
2026-05-10 12:42   ` René Scharfe [this message]
2026-05-10 23:30     ` [PATCH] sideband: clear full line when printing remote messages Junio C Hamano
2026-05-05  9:38 ` Git trims the last character of content from remotes Mikael Magnusson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9826dabf-c9a6-4397-8ae6-a24f9c507f1b@web.de \
    --to=l.s.r@web.de \
    --cc=chris.torek@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=hugo@whynothugo.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox