git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] blame: report correct number of lines in progress when using ranges

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Apr 4, 2022, 06:12 UTC
Message-ID
<220404.8635itl6h0.gmgdl@evledraar.gmail.com>
In-Reply-To
<20220403165038.52803-1-eantoranz@gmail.com>
On Sun, Apr 03 2022, Edmundo Carmona Antoranz wrote:
Show 31 quoted lines
> 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 +++++-
>  1 file changed, 5 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;

Here ranges's nr is unsigned int, and the "num_lines" is an int, and the argument to start_delayed_progress() is uint64_t, but both of "start" and "end" are "long".

But we appand multiple differences to num_lines, are we sure we won't overflow here?

Show 22 quoted lines
>  
>  	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);
Previous: Ævar Arnfjörð BjarmasonNext: Junio C Hamano
Message 5 of 6 in “blame: report correct number of lines in progress when using ranges”
  1. blame: report correct number of lines in progress when using rangesEdmundo Carmona Antoranz, Apr 3, 2022
  2. Junio C HamanoApr 3, 2022
  3. Edmundo Carmona AntoranzApr 4, 2022
  4. Ævar Arnfjörð BjarmasonApr 4, 2022
  5. Ævar Arnfjörð BjarmasonApr 4, 2022
  6. Junio C HamanoApr 4, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.