blame: move copy/move thresholds to scoreboard

Copy and move score thresholds are used in parts of blame that are being moved to libgit, and should be accessible via the scoreboard structure. Signed-off-by: Jeff Smith <whydoubt@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff Smith committed May 24, 2017 at 00:15 UTC 18ec0d62ee9819adde8afdc0fb33d37766109b02
1 file changed +23 -18
builtin/blame.c
+23 -18
@@ -66,10 +66,6 @@ static struct string_list mailmap = STRING_LIST_INIT_NODUP;
66 #define PICKAXE_BLAME_COPY_HARDER 04
67 #define PICKAXE_BLAME_COPY_HARDEST 010
68
69 -/*
70 - * blame for a blame_entry with score lower than these thresholds
71 - * is not passed to the parent using move/copy logic.
72 - */
69 static unsigned blame_move_score;
70 static unsigned blame_copy_score;
71 #define BLAME_DEFAULT_MOVE_SCORE 20
@@ -375,6 +371,13 @@ struct blame_scoreboard {
371 int num_read_blob;
372 int num_get_patch;
373 int num_commits;
374 +
375 + /*
376 + * blame for a blame_entry with score lower than these thresholds
377 + * is not passed to the parent using move/copy logic.
378 + */
379 + unsigned move_score;
380 + unsigned copy_score;
381 };
382
383 static void sanity_check_refcnt(struct blame_scoreboard *);
@@ -1156,7 +1159,7 @@ static void find_move_in_parent(struct blame_scoreboard *sb,
1159 next = e->next;
1160 find_copy_in_blob(sb, e, parent, split, &file_p);
1161 if (split[1].suspect &&
1159 - blame_move_score < blame_entry_score(sb, &split[1])) {
1162 + sb->move_score < blame_entry_score(sb, &split[1])) {
1163 split_blame(blamed, &unblamedtail, split, e);
1164 } else {
1165 e->next = leftover;
@@ -1165,7 +1168,7 @@ static void find_move_in_parent(struct blame_scoreboard *sb,
1168 decref_split(split);
1169 }
1170 *unblamedtail = NULL;
1168 - toosmall = filter_small(sb, toosmall, &unblamed, blame_move_score);
1171 + toosmall = filter_small(sb, toosmall, &unblamed, sb->move_score);
1172 } while (unblamed);
1173 target->suspects = reverse_blame(leftover, NULL);
1174 }
@@ -1286,7 +1289,7 @@ static void find_copy_in_parent(struct blame_scoreboard *sb,
1289 for (j = 0; j < num_ents; j++) {
1290 struct blame_entry *split = blame_list[j].split;
1291 if (split[1].suspect &&
1289 - blame_copy_score < blame_entry_score(sb, &split[1])) {
1292 + sb->copy_score < blame_entry_score(sb, &split[1])) {
1293 split_blame(blamed, &unblamedtail, split,
1294 blame_list[j].ent);
1295 } else {
@@ -1297,7 +1300,7 @@ static void find_copy_in_parent(struct blame_scoreboard *sb,
1300 }
1301 free(blame_list);
1302 *unblamedtail = NULL;
1300 - toosmall = filter_small(sb, toosmall, &unblamed, blame_copy_score);
1303 + toosmall = filter_small(sb, toosmall, &unblamed, sb->copy_score);
1304 } while (unblamed);
1305 target->suspects = reverse_blame(leftover, NULL);
1306 diff_flush(&diff_opts);
@@ -1454,7 +1457,7 @@ static void pass_blame(struct blame_scoreboard *sb, struct blame_origin *origin,
1457 * Optionally find moves in parents' files.
1458 */
1459 if (opt & PICKAXE_BLAME_MOVE) {
1457 - filter_small(sb, &toosmall, &origin->suspects, blame_move_score);
1460 + filter_small(sb, &toosmall, &origin->suspects, sb->move_score);
1461 if (origin->suspects) {
1462 for (i = 0, sg = first_scapegoat(revs, commit);
1463 i < num_sg && sg;
@@ -1473,12 +1476,12 @@ static void pass_blame(struct blame_scoreboard *sb, struct blame_origin *origin,
1476 * Optionally find copies from parents' files.
1477 */
1478 if (opt & PICKAXE_BLAME_COPY) {
1476 - if (blame_copy_score > blame_move_score)
1477 - filter_small(sb, &toosmall, &origin->suspects, blame_copy_score);
1478 - else if (blame_copy_score < blame_move_score) {
1479 + if (sb->copy_score > sb->move_score)
1480 + filter_small(sb, &toosmall, &origin->suspects, sb->copy_score);
1481 + else if (sb->copy_score < sb->move_score) {
1482 origin->suspects = blame_merge(origin->suspects, toosmall);
1483 toosmall = NULL;
1481 - filter_small(sb, &toosmall, &origin->suspects, blame_copy_score);
1484 + filter_small(sb, &toosmall, &origin->suspects, sb->copy_score);
1485 }
1486 if (!origin->suspects)
1487 goto finish;
@@ -2675,11 +2678,6 @@ parse_done:
2678 opt |= (PICKAXE_BLAME_COPY | PICKAXE_BLAME_MOVE |
2679 PICKAXE_BLAME_COPY_HARDER);
2680
2678 - if (!blame_move_score)
2679 - blame_move_score = BLAME_DEFAULT_MOVE_SCORE;
2680 - if (!blame_copy_score)
2681 - blame_copy_score = BLAME_DEFAULT_COPY_SCORE;
2682 -
2681 /*
2682 * We have collected options unknown to us in argv[1..unk]
2683 * which are to be passed to revision machinery if we are
@@ -2733,6 +2731,8 @@ parse_done:
2731 revs.disable_stdin = 1;
2732 setup_revisions(argc, argv, &revs, NULL);
2733 memset(&sb, 0, sizeof(sb));
2734 + sb.move_score = BLAME_DEFAULT_MOVE_SCORE;
2735 + sb.copy_score = BLAME_DEFAULT_COPY_SCORE;
2736
2737 sb.revs = &revs;
2738 if (!reverse) {
@@ -2871,6 +2871,11 @@ parse_done:
2871 sb.ent = NULL;
2872 sb.path = path;
2873
2874 + if (blame_move_score)
2875 + sb.move_score = blame_move_score;
2876 + if (blame_copy_score)
2877 + sb.copy_score = blame_copy_score;
2878 +
2879 read_mailmap(&mailmap, NULL);
2880
2881 assign_blame(&sb, opt);