git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: Edmundo Carmona Antoranz <eantoranz@gmail.com>
Cc: gitster@pobox.com, whydoubt@gmail.com, git@vger.kernel.org
Subject: Re: [PATCH v2] blame: report correct number of lines in progress when using ranges
Date: Tue, 05 Apr 2022 11:36:05 +0200	[thread overview]
Message-ID: <220405.86o81flve1.gmgdl@evledraar.gmail.com> (raw)
In-Reply-To: <20220404182129.33992-1-eantoranz@gmail.com>


On Mon, Apr 04 2022, Edmundo Carmona Antoranz wrote:

> When using ranges, use their sizes as the limit for progress
> instead of the size of the full file.
>
> Before:
> $ git blame --progress builtin/blame.c > /dev/null
> Blaming lines: 100% (1210/1210), done.
> $ git blame --progress -L 100,120 -L 200,300 builtin/blame.c > /dev/null
> Blaming lines:  10% (122/1210), done.
> $
>
> After:
> $ ./git blame --progress builtin/blame.c > /dev/null
> Blaming lines: 100% (1210/1210), done.
> $ ./git blame --progress -L 100,120 -L 200,300 builtin/blame.c > /dev/null
> Blaming lines: 100% (122/122), done.
> $
>
> Signed-off-by: Edmundo Carmona Antoranz <eantoranz@gmail.com>
> ---
>  builtin/blame.c  |  6 +++++-
>  t/t8002-blame.sh | 28 ++++++++++++++++++++++++++++
>  2 files changed, 33 insertions(+), 1 deletion(-)
>
> diff --git a/builtin/blame.c b/builtin/blame.c
> index 8d15b68afc..e33372c56b 100644
> --- a/builtin/blame.c
> +++ b/builtin/blame.c
> @@ -898,6 +898,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
>  	unsigned int range_i;
>  	long anchor;
>  	const int hexsz = the_hash_algo->hexsz;
> +	long num_lines = 0;
>  
>  	setup_default_color_by_age();
>  	git_config(git_blame_config, &output_option);
> @@ -1129,7 +1130,10 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
>  	for (range_i = ranges.nr; range_i > 0; --range_i) {
>  		const struct range *r = &ranges.ranges[range_i - 1];
>  		ent = blame_entry_prepend(ent, r->start, r->end, o);
> +		num_lines += (r->end - r->start);
>  	}
> +	if (!num_lines)
> +		num_lines = sb.num_lines;
>  
>  	o->suspects = ent;
>  	prio_queue_put(&sb.commits, o->commit);
> @@ -1158,7 +1162,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
>  	sb.found_guilty_entry = &found_guilty_entry;
>  	sb.found_guilty_entry_data = &pi;
>  	if (show_progress)
> -		pi.progress = start_delayed_progress(_("Blaming lines"), sb.num_lines);
> +		pi.progress = start_delayed_progress(_("Blaming lines"), num_lines);
>  
>  	assign_blame(&sb, opt);

Looking good.

> diff --git a/t/t8002-blame.sh b/t/t8002-blame.sh
> index ee4fdd8f18..151a6fddfd 100755
> --- a/t/t8002-blame.sh
> +++ b/t/t8002-blame.sh
> @@ -129,6 +129,34 @@ test_expect_success '--exclude-promisor-objects does not BUG-crash' '
>  	test_must_fail git blame --exclude-promisor-objects one
>  '
>  
> +test_expect_success 'blame progress on a full file' '
> +	cat >progress.txt <<-\EOF &&
> +	a simple test file
> +
> +	no relevant content is expected here
> +
> +	If the file is too short, we cannot test ranges
> +
> +	EOF
> +	git add progress.txt &&
> +	git commit -m "add a file for testing progress" &&

Let's just skip this then and use existing test setup. A quick glance at
the state after this test shows that e.g. the "hello.c" we already
created would be a good candidate.

> +	GIT_PROGRESS_DELAY=0 \
> +	git blame --progress progress.txt > /dev/null 2> full_progress.txt &&
> +	grep "Blaming lines: 100% (6/6), done." full_progress.txt

Let's use test_cmp here instead, as we expect nothing else on stderr,
and with grep one wonders why it's not ^$ anchored, but just:

    echo "Blaming lines: 100% (6/6), done." >expect &&
    git blame ... 2>actual &&
    test_cmp expect actual

is better, both because it's more exhaustive as a test, and because
it'll give better debug (diff) output on failure than grep will (just no
output at all).

> +test_expect_success 'blame progress on a single range' '
> +	GIT_PROGRESS_DELAY=0 \
> +	git blame --progress -L 2,5 progress.txt > /dev/null 2> range_progress.txt &&
> +	grep "Blaming lines: 100% (4/4), done." range_progress.txt
> +'
> +
> +test_expect_success 'blame progress on multiple ranges' '
> +	GIT_PROGRESS_DELAY=0 \
> +	git blame --progress -L 1,2 -L 4,6 progress.txt > /dev/null 2> range_progress.txt &&
> +	grep "Blaming lines: 100% (5/5), done." range_progress.txt
> +'

Style nit, no space after ">", so e.g. 2>err.

Also shorter names are easier to read, so just:

    [...] 2>err

Or "actual" per the suggestion above.

And no need to redirect stdout to /dev/null, it's helpful to see it by
default in the verbose test output, we let that take care of suppressing
all of it ornot.


>  test_expect_success 'blame with uncommitted edits in partial clone does not crash' '
>  	git init server &&
>  	echo foo >server/file.txt &&


      parent reply	other threads:[~2022-04-05  9:53 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-04 18:21 [PATCH v2] blame: report correct number of lines in progress when using ranges Edmundo Carmona Antoranz
2022-04-04 18:25 ` Edmundo Carmona Antoranz
2022-04-04 19:32   ` Junio C Hamano
2022-04-05  7:34 ` Bagas Sanjaya
2022-04-05  7:46   ` Ævar Arnfjörð Bjarmason
2022-04-05  7:55     ` Edmundo Carmona Antoranz
2022-04-05  9:42   ` Philip Oakley
2022-04-06 15:14     ` Junio C Hamano
2022-04-08  8:03       ` Philip Oakley
2022-04-08 18:16         ` Junio C Hamano
2022-04-05  9:36 ` Ævar Arnfjörð Bjarmason [this message]

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=220405.86o81flve1.gmgdl@evledraar.gmail.com \
    --to=avarab@gmail.com \
    --cc=eantoranz@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=whydoubt@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.
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).