Skip to content

Commit 18ec0d6

Browse files
whydoubtgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8449528 commit 18ec0d6

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

builtin/blame.c

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,6 @@ static struct string_list mailmap = STRING_LIST_INIT_NODUP;
6666
#define PICKAXE_BLAME_COPY_HARDER 04
6767
#define PICKAXE_BLAME_COPY_HARDEST 010
6868

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-
*/
7369
static unsigned blame_move_score;
7470
static unsigned blame_copy_score;
7571
#define BLAME_DEFAULT_MOVE_SCORE 20
@@ -375,6 +371,13 @@ struct blame_scoreboard {
375371
int num_read_blob;
376372
int num_get_patch;
377373
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;
378381
};
379382

380383
static void sanity_check_refcnt(struct blame_scoreboard *);
@@ -1156,7 +1159,7 @@ static void find_move_in_parent(struct blame_scoreboard *sb,
11561159
next = e->next;
11571160
find_copy_in_blob(sb, e, parent, split, &file_p);
11581161
if (split[1].suspect &&
1159-
blame_move_score < blame_entry_score(sb, &split[1])) {
1162+
sb->move_score < blame_entry_score(sb, &split[1])) {
11601163
split_blame(blamed, &unblamedtail, split, e);
11611164
} else {
11621165
e->next = leftover;
@@ -1165,7 +1168,7 @@ static void find_move_in_parent(struct blame_scoreboard *sb,
11651168
decref_split(split);
11661169
}
11671170
*unblamedtail = NULL;
1168-
toosmall = filter_small(sb, toosmall, &unblamed, blame_move_score);
1171+
toosmall = filter_small(sb, toosmall, &unblamed, sb->move_score);
11691172
} while (unblamed);
11701173
target->suspects = reverse_blame(leftover, NULL);
11711174
}
@@ -1286,7 +1289,7 @@ static void find_copy_in_parent(struct blame_scoreboard *sb,
12861289
for (j = 0; j < num_ents; j++) {
12871290
struct blame_entry *split = blame_list[j].split;
12881291
if (split[1].suspect &&
1289-
blame_copy_score < blame_entry_score(sb, &split[1])) {
1292+
sb->copy_score < blame_entry_score(sb, &split[1])) {
12901293
split_blame(blamed, &unblamedtail, split,
12911294
blame_list[j].ent);
12921295
} else {
@@ -1297,7 +1300,7 @@ static void find_copy_in_parent(struct blame_scoreboard *sb,
12971300
}
12981301
free(blame_list);
12991302
*unblamedtail = NULL;
1300-
toosmall = filter_small(sb, toosmall, &unblamed, blame_copy_score);
1303+
toosmall = filter_small(sb, toosmall, &unblamed, sb->copy_score);
13011304
} while (unblamed);
13021305
target->suspects = reverse_blame(leftover, NULL);
13031306
diff_flush(&diff_opts);
@@ -1454,7 +1457,7 @@ static void pass_blame(struct blame_scoreboard *sb, struct blame_origin *origin,
14541457
* Optionally find moves in parents' files.
14551458
*/
14561459
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);
14581461
if (origin->suspects) {
14591462
for (i = 0, sg = first_scapegoat(revs, commit);
14601463
i < num_sg && sg;
@@ -1473,12 +1476,12 @@ static void pass_blame(struct blame_scoreboard *sb, struct blame_origin *origin,
14731476
* Optionally find copies from parents' files.
14741477
*/
14751478
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) {
14791482
origin->suspects = blame_merge(origin->suspects, toosmall);
14801483
toosmall = NULL;
1481-
filter_small(sb, &toosmall, &origin->suspects, blame_copy_score);
1484+
filter_small(sb, &toosmall, &origin->suspects, sb->copy_score);
14821485
}
14831486
if (!origin->suspects)
14841487
goto finish;
@@ -2675,11 +2678,6 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
26752678
opt |= (PICKAXE_BLAME_COPY | PICKAXE_BLAME_MOVE |
26762679
PICKAXE_BLAME_COPY_HARDER);
26772680

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-
26832681
/*
26842682
* We have collected options unknown to us in argv[1..unk]
26852683
* which are to be passed to revision machinery if we are
@@ -2733,6 +2731,8 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
27332731
revs.disable_stdin = 1;
27342732
setup_revisions(argc, argv, &revs, NULL);
27352733
memset(&sb, 0, sizeof(sb));
2734+
sb.move_score = BLAME_DEFAULT_MOVE_SCORE;
2735+
sb.copy_score = BLAME_DEFAULT_COPY_SCORE;
27362736

27372737
sb.revs = &revs;
27382738
if (!reverse) {
@@ -2871,6 +2871,11 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
28712871
sb.ent = NULL;
28722872
sb.path = path;
28732873

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+
28742879
read_mailmap(&mailmap, NULL);
28752880

28762881
assign_blame(&sb, opt);

0 commit comments

Comments
 (0)