git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: "SZEDER Gábor" <szeder.dev@gmail.com>
Cc: Junio C Hamano <gitster@pobox.com>, git@vger.kernel.org
Subject: Re: [PATCH v3 5/5] progress: use term_clear_line()
Date: Tue, 25 Jun 2019 11:10:57 +0200 (CEST)	[thread overview]
Message-ID: <nycvar.QRO.7.76.6.1906251110160.44@tvgsbejvaqbjf.bet> (raw)
In-Reply-To: <20190624181318.17388-6-szeder.dev@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 5225 bytes --]

Hi Gábor,

On Mon, 24 Jun 2019, SZEDER Gábor wrote:

> To make sure that the previously displayed progress line is completely
> covered up when the new line is shorter, commit 545dc345eb (progress:
> break too long progress bar lines, 2019-04-12) added a bunch of
> calculations to figure out how many characters it needs to overwrite
> with spaces.
>
> Use the just introduced term_clear_line() helper function to, well,
> clear the last line, making all these calculations unnecessary, and
> thus simplifying the code considerably.
>
> Three tests in 't5541-http-push-smart.sh' 'grep' for specific text
> shown in the progress lines at the beginning of the line, but now
> those lines begin either with the ANSI escape sequence or with the
> terminal width worth of space characters clearing the line.  Relax the
> 'grep' patterns to match anywhere on the line.  Note that only two of
> these three tests fail without relaxing their 'grep' pattern, but the
> third looks for the absence of the pattern, so it still succeeds, but
> without the adjustment would potentially hide future regressions.
>
> Note also that with this change we no longer need the length of the
> previously displayed progress line, so the strbuf added to 'struct
> progress' in d53ba841d4 (progress: assemble percentage and counters in
> a strbuf before printing, 2019-04-05) is not strictly necessary
> anymore.  We still keep it, though, as it avoids allocating and
> releasing a strbuf each time the progress is updated.

Very nice change, indeed, I totally love how much simpler the post-image
looks. Well done, for the entire patch series, and thank you so much!
Dscho

>
> Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
> ---
>  progress.c                 | 28 +++++++++++-----------------
>  t/t5541-http-push-smart.sh |  6 +++---
>  2 files changed, 14 insertions(+), 20 deletions(-)
>
> diff --git a/progress.c b/progress.c
> index a2e8cf64a8..095dcd0ddf 100644
> --- a/progress.c
> +++ b/progress.c
> @@ -88,7 +88,6 @@ static void display(struct progress *progress, uint64_t n, const char *done)
>  	const char *tp;
>  	struct strbuf *counters_sb = &progress->counters_sb;
>  	int show_update = 0;
> -	int last_count_len = counters_sb->len;
>
>  	if (progress->delay && (!progress_update || --progress->delay))
>  		return;
> @@ -116,26 +115,21 @@ static void display(struct progress *progress, uint64_t n, const char *done)
>  	if (show_update) {
>  		if (is_foreground_fd(fileno(stderr)) || done) {
>  			const char *eol = done ? done : "\r";
> -			size_t clear_len = counters_sb->len < last_count_len ?
> -					last_count_len - counters_sb->len + 1 :
> -					0;
> -			size_t progress_line_len = progress->title_len +
> -						counters_sb->len + 2;
> -			int cols = term_columns();
>
> +			term_clear_line();
>  			if (progress->split) {
> -				fprintf(stderr, "  %s%*s", counters_sb->buf,
> -					(int) clear_len, eol);
> -			} else if (!done && cols < progress_line_len) {
> -				clear_len = progress->title_len + 1 < cols ?
> -					    cols - progress->title_len - 1 : 0;
> -				fprintf(stderr, "%s:%*s\n  %s%s",
> -					progress->title, (int) clear_len, "",
> -					counters_sb->buf, eol);
> +				fprintf(stderr, "  %s%s", counters_sb->buf,
> +					eol);
> +			} else if (!done &&
> +				   /* The "+ 2" accounts for the ": ". */
> +				   term_columns() < progress->title_len +
> +						    counters_sb->len + 2) {
> +				fprintf(stderr, "%s:\n  %s%s",
> +					progress->title, counters_sb->buf, eol);
>  				progress->split = 1;
>  			} else {
> -				fprintf(stderr, "%s: %s%*s", progress->title,
> -					counters_sb->buf, (int) clear_len, eol);
> +				fprintf(stderr, "%s: %s%s", progress->title,
> +					counters_sb->buf, eol);
>  			}
>  			fflush(stderr);
>  		}
> diff --git a/t/t5541-http-push-smart.sh b/t/t5541-http-push-smart.sh
> index 8ef8763e06..2e4802e206 100755
> --- a/t/t5541-http-push-smart.sh
> +++ b/t/t5541-http-push-smart.sh
> @@ -213,7 +213,7 @@ test_expect_success TTY 'push shows progress when stderr is a tty' '
>  	cd "$ROOT_PATH"/test_repo_clone &&
>  	test_commit noisy &&
>  	test_terminal git push >output 2>&1 &&
> -	test_i18ngrep "^Writing objects" output
> +	test_i18ngrep "Writing objects" output
>  '
>
>  test_expect_success TTY 'push --quiet silences status and progress' '
> @@ -228,7 +228,7 @@ test_expect_success TTY 'push --no-progress silences progress but not status' '
>  	test_commit no-progress &&
>  	test_terminal git push --no-progress >output 2>&1 &&
>  	test_i18ngrep "^To http" output &&
> -	test_i18ngrep ! "^Writing objects" output
> +	test_i18ngrep ! "Writing objects" output
>  '
>
>  test_expect_success 'push --progress shows progress to non-tty' '
> @@ -236,7 +236,7 @@ test_expect_success 'push --progress shows progress to non-tty' '
>  	test_commit progress &&
>  	git push --progress >output 2>&1 &&
>  	test_i18ngrep "^To http" output &&
> -	test_i18ngrep "^Writing objects" output
> +	test_i18ngrep "Writing objects" output
>  '
>
>  test_expect_success 'http push gives sane defaults to reflog' '
> --
> 2.22.0.589.g5bd7971b91
>
>

  reply	other threads:[~2019-06-25  9:10 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-30 14:25 [PATCH] rebase: fix garbled progress display with '-x' SZEDER Gábor
2019-04-30 22:25 ` Johannes Schindelin
2019-05-01 23:16   ` SZEDER Gábor
2019-05-03  8:41     ` Johannes Schindelin
2019-06-11 12:38     ` SZEDER Gábor
2019-06-11 13:03 ` [PATCH v2 0/4] rebase/progress: add and use term_clear_line() SZEDER Gábor
2019-06-11 13:03   ` [PATCH v2 1/4] t3404-rebase-interactive: use the 'q_to_cr' helper SZEDER Gábor
2019-06-11 13:03   ` [PATCH v2 2/4] pager: add a helper function to clear the last line in the terminal SZEDER Gábor
2019-06-11 13:03   ` [PATCH v2 3/4] rebase: fix garbled progress display with '-x' SZEDER Gábor
2019-06-11 20:36     ` Junio C Hamano
2019-06-11 21:11       ` SZEDER Gábor
2019-06-12 19:14         ` Johannes Schindelin
2019-06-12 19:41           ` SZEDER Gábor
2019-06-13  7:54             ` Johannes Schindelin
2019-06-14 18:42             ` Johannes Schindelin
2019-06-17 18:40               ` SZEDER Gábor
2019-06-17 19:13               ` SZEDER Gábor
2019-06-17 19:25                 ` SZEDER Gábor
2019-06-24 18:39           ` SZEDER Gábor
2019-06-25 10:08             ` Phillip Wood
2019-06-25 11:31               ` SZEDER Gábor
2019-06-25 13:33                 ` Phillip Wood
2019-06-25 18:00                 ` Phillip Wood
2019-06-25 11:38               ` Johannes Schindelin
2019-06-25 13:35                 ` Phillip Wood
2019-06-11 20:48     ` Junio C Hamano
2019-06-11 23:50       ` SZEDER Gábor
2019-06-12 16:21       ` Junio C Hamano
2019-06-11 13:03   ` [PATCH v2 4/4] progress: use term_clear_line() SZEDER Gábor
2019-06-12 20:00     ` Johannes Schindelin
2019-06-24 18:13   ` [PATCH v3 0/5] rebase/progress: add and " SZEDER Gábor
2019-06-24 18:13     ` [PATCH v3 1/5] t3404: modernize here doc style SZEDER Gábor
2019-06-25  9:06       ` Johannes Schindelin
2019-06-24 18:13     ` [PATCH v3 2/5] t3404: make the 'rebase.missingCommitsCheck=ignore' test more focused SZEDER Gábor
2019-06-25  9:07       ` Johannes Schindelin
2019-06-24 18:13     ` [PATCH v3 3/5] pager: add a helper function to clear the last line in the terminal SZEDER Gábor
2019-06-24 18:13     ` [PATCH v3 4/5] rebase: fix garbled progress display with '-x' SZEDER Gábor
2019-06-27 13:42       ` [PATCH v3.1 " SZEDER Gábor
2019-06-24 18:13     ` [PATCH v3 5/5] progress: use term_clear_line() SZEDER Gábor
2019-06-25  9:10       ` Johannes Schindelin [this message]
2019-06-25 19:44         ` Junio C Hamano

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=nycvar.QRO.7.76.6.1906251110160.44@tvgsbejvaqbjf.bet \
    --to=johannes.schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=szeder.dev@gmail.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).