]> git.ipfire.org Git - thirdparty/git.git/commitdiff
blame: report correct number of lines in progress when using ranges
authorEdmundo Carmona Antoranz <eantoranz@gmail.com>
Wed, 6 Apr 2022 18:13:20 +0000 (20:13 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 6 Apr 2022 20:29:59 +0000 (13:29 -0700)
When using ranges, use the range 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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/blame.c
t/annotate-tests.sh

index 7fafeac408141bb89e5c69512c3a7f174729e4dd..832478e88cd85ae0010c15f84a51efe1eb7b93ce 100644 (file)
@@ -897,6 +897,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);
@@ -1127,7 +1128,10 @@ parse_done:
        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);
@@ -1156,7 +1160,7 @@ parse_done:
        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);
 
index 09e86f9ba0804f70d6561b5bda03d69535f11dcf..cc01d891504eb117eb9c367ebc4e89b516157012 100644 (file)
@@ -56,6 +56,10 @@ check_count () {
        ' "$@" <actual
 }
 
+get_progress_result () {
+       tr '\015' '\012' | tail -n 1
+}
+
 test_expect_success 'setup A lines' '
        echo "1A quick brown fox jumps over the" >file &&
        echo "lazy dog" >>file &&
@@ -604,3 +608,39 @@ test_expect_success 'blame -L X,-N (non-numeric N)' '
 test_expect_success 'blame -L ,^/RE/' '
        test_must_fail $PROG -L1,^/99/ file
 '
+
+test_expect_success 'blame progress on a full file' '
+       cat >expect <<-\EOF &&
+       Blaming lines: 100% (10/10), done.
+       EOF
+
+       GIT_PROGRESS_DELAY=0 \
+       git blame --progress hello.c 2>stderr &&
+
+       get_progress_result <stderr >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'blame progress on a single range' '
+       cat >expect <<-\EOF &&
+       Blaming lines: 100% (4/4), done.
+       EOF
+
+       GIT_PROGRESS_DELAY=0 \
+       git blame --progress -L 3,6 hello.c 2>stderr &&
+
+       get_progress_result <stderr >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'blame progress on multiple ranges' '
+       cat >expect <<-\EOF &&
+       Blaming lines: 100% (7/7), done.
+       EOF
+
+       GIT_PROGRESS_DELAY=0 \
+       git blame --progress -L 3,6 -L 8,10 hello.c 2>stderr &&
+
+       get_progress_result <stderr >actual &&
+       test_cmp expect actual
+'