git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steffen Daode Nurpmeso <sdaoden@googlemail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>, Jeff King <peff@peff.net>,
	Nicolas Pitre <nico@cam.org>, Johannes Sixt <j6t@kdbg.org>
Subject: [PATCH/RFC] sideband: remove line padding (was: Re: [PATCH] progress: use \r as EOL only if isatty(stderr) is true)
Date: Wed, 29 Jun 2011 19:42:20 +0200	[thread overview]
Message-ID: <20110629174220.GA36658@sherwood.local> (raw)
In-Reply-To: <7vwrg5u7oz.fsf@alter.siamese.dyndns.org>

I desperately tried to reproduce the 'xy  ^Mxy  ^M' case, but i
can't.  In fact i cannot even find a piece of code which would do
it.  :-/  Such a shame.
Still: i insist on having that seen in my arena-manager.log.

While searching around i stumbled over fetch-pack output with an
ANSI escape sequence after a '(xy) 2>&1 | tee LOG'.
--
Ciao, Steffen
sdaoden(*)(gmail.com)
() ascii ribbon campaign - against html e-mail
/\ www.asciiribbon.org - against proprietary attachments

-- >8 --
Subject: [PATCH/RFC] sideband: remove line padding

For formatting purposes recv_sideband() sofar appended a suffix to
band #2 (informative) messages: dependent on getenv("TERM") lines
may have been space-filled ("dumb") or padded with an ANSI escape
sequence (ANSI EL, mode 0: clear from cursor to end of line).  This
patch removes handling of terminal specifics and any pad suffixes.

It also fixes two 'signed/unsigned comparison' compiler warnings.

Signed-off-by: Steffen Daode Nurpmeso <sdaoden@gmail.com>
---
I believe that users of fetch-pack, send-pack and archive, the three
affected operations, will ensure that lines are refreshed as approbiate,
even if 'brk-1' == CR.  But even if not: i would move handling of
"TERM" and dumb/non-dumb terminals out of this packet handler and
into some terminal encapsulator, which can only be color.* as far
as i see.  The question would be how this should be done.  Maybe
term_fprintf_padln(?, desired-line-length-or--1)?  Such a thing would
surely find other users in the codebase.  A second approach would
be to only use the "dumb" pad, as in

    fprintf(stderr, "%.*s        %c", brk - 1, b, b[brk - 1]);

What do you think of that?

 sideband.c |   35 +++++------------------------------
 1 files changed, 5 insertions(+), 30 deletions(-)

diff --git a/sideband.c b/sideband.c
index d5ffa1c..17e1793 100644
--- a/sideband.c
+++ b/sideband.c
@@ -14,26 +14,13 @@
 
 #define PREFIX "remote:"
 
-#define ANSI_SUFFIX "\033[K"
-#define DUMB_SUFFIX "        "
-
-#define FIX_SIZE 10  /* large enough for any of the above */
-
 int recv_sideband(const char *me, int in_stream, int out)
 {
-	unsigned pf = strlen(PREFIX);
-	unsigned sf;
-	char buf[LARGE_PACKET_MAX + 2*FIX_SIZE];
-	char *suffix, *term;
+	unsigned pf = sizeof(PREFIX) - 1;
+	char buf[LARGE_PACKET_MAX + 2*sizeof(PREFIX)];
 	int skip_pf = 0;
 
 	memcpy(buf, PREFIX, pf);
-	term = getenv("TERM");
-	if (term && strcmp(term, "dumb"))
-		suffix = ANSI_SUFFIX;
-	else
-		suffix = DUMB_SUFFIX;
-	sf = strlen(suffix);
 
 	while (1) {
 		int band, len;
@@ -82,20 +69,8 @@ int recv_sideband(const char *me, int in_stream, int out)
 						break;
 				}
 
-				/*
-				 * Let's insert a suffix to clear the end
-				 * of the screen line if a line break was
-				 * found.  Also, if we don't skip the
-				 * prefix, then a non-empty string must be
-				 * present too.
-				 */
-				if (brk > (skip_pf ? 0 : (pf+1 + 1))) {
-					char save[FIX_SIZE];
-					memcpy(save, b + brk, sf);
-					b[brk + sf - 1] = b[brk - 1];
-					memcpy(b + brk - 1, suffix, sf);
-					fprintf(stderr, "%.*s", brk + sf, b);
-					memcpy(b + brk, save, sf);
+				if ((unsigned)brk > (skip_pf ? 0 : (pf+1 +1))) {
+					fprintf(stderr, "%.*s", brk, b);
 					len -= brk;
 				} else {
 					int l = brk ? brk : len;
@@ -133,7 +108,7 @@ ssize_t send_sideband(int fd, int band, const char *data, ssize_t sz, int packet
 		char hdr[5];
 
 		n = sz;
-		if (packet_max - 5 < n)
+		if ((unsigned)packet_max - 5 < n)
 			n = packet_max - 5;
 		if (0 <= band) {
 			sprintf(hdr, "%04x", n + 5);
-- 
1.7.6.1.ge79e.dirty

  parent reply	other threads:[~2011-06-29 17:42 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-28 14:40 [PATCH] progress: use \r as EOL only if isatty(stderr) is true Steffen Daode Nurpmeso
     [not found] ` <BANLkTinRe=pA=_obCmPKBjJMXH_pDfwCtw@mail.gmail.com>
2011-06-28 16:51   ` Steffen Daode Nurpmeso
2011-06-28 18:04   ` Steffen Daode Nurpmeso
2011-06-28 18:33 ` Junio C Hamano
2011-06-28 18:48   ` Steffen Daode Nurpmeso
2011-06-28 18:55   ` Steffen Daode Nurpmeso
2011-06-28 22:45   ` Jeff King
2011-06-29 21:36     ` Junio C Hamano
2011-06-30  4:33       ` Miles Bader
2011-06-29 17:42   ` Steffen Daode Nurpmeso [this message]
2011-06-29 18:15     ` [PATCH/RFC] sideband: remove line padding (was: Re: [PATCH] progress: use \r as EOL only if isatty(stderr) is true) Nicolas Pitre
2011-06-30 21:13       ` Steffen Daode Nurpmeso
2011-07-01  3:46         ` Nicolas Pitre
2011-08-27 19:45   ` [PATCH] checkout: be quiet if not on isatty() Steffen Daode Nurpmeso
2011-08-27 19:45     ` Steffen Daode Nurpmeso
2011-08-28  6:22       ` Junio C Hamano
2011-08-28  6:28         ` martin f krafft
2011-08-28 17:37         ` [PATCH] checkout: add --verbose, and restrict progress reporting (was: Re: [PATCH] checkout: be quiet if not on isatty()) Steffen Daode Nurpmeso
2011-08-29 20:14         ` [PATCH 0/2 RFC] Add update_progress(), divert checkout messages sdaoden
2011-08-29 20:17           ` [PATCH 1/2] progress: add update_progress() sdaoden
2011-08-29 20:17             ` [PATCH 2/2] unpack-trees: divert check_updates() output via update_progress() sdaoden

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=20110629174220.GA36658@sherwood.local \
    --to=sdaoden@googlemail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j6t@kdbg.org \
    --cc=nico@cam.org \
    --cc=peff@peff.net \
    /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;
as well as URLs for NNTP newsgroup(s).