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 @@ 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); @@ -1158,7 +1162,7 @@ parse_done: sb.found_guilty_entry = &found_guilty_entry; sb.found_guilty_entry_data = π 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); diff --git a/t/annotate-tests.sh b/t/annotate-tests.sh index 09e86f9ba0..cc01d89150 100644 --- a/t/annotate-tests.sh +++ b/t/annotate-tests.sh @@ -56,6 +56,10 @@ check_count () { ' "$@" 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 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 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 actual && + test_cmp expect actual +'