@matheusbsbs / matheus-bagliano / commits / 4a0fc95f18
Fork 0

git-pickaxe: introduce heuristics to avoid "trivial" chunks

This adds scoring logic to blame_entry to prevent blames on very trivial chunks (e.g. lots of empty lines, indent followed by a closing brace) from being passed down to unrelated lines in the parent. The current heuristics are quite simple and may need to be tweaked later, but we need to start somewhere. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Oct 20, 2006 at 15:37 UTC 4a0fc95f182dbf5b0c58e6d6cfe8cd7459da7ab6
1 file changed +32 -4
builtin-pickaxe.c
+32 -4
@@ -40,6 +40,15 @@ static int max_score_digits;
40 #define PICKAXE_BLAME_COPY 02
41 #define PICKAXE_BLAME_COPY_HARDER 04
42
43 +/*
44 + * blame for a blame_entry with score lower than these thresholds
45 + * is not passed to the parent using move/copy logic.
46 + */
47 +static unsigned blame_move_score;
48 +static unsigned blame_copy_score;
49 +#define BLAME_DEFAULT_MOVE_SCORE 20
50 +#define BLAME_DEFAULT_COPY_SCORE 40
51 +
52 /* bits #0..7 in revision.h, #8..11 used for merge_bases() in commit.c */
53 #define METAINFO_SHOWN (1u<<12)
54 #define MORE_THAN_ONE_PATH (1u<<13)
@@ -645,7 +654,8 @@ static int find_move_in_parent(struct scoreboard *sb,
654 if (ent->suspect != target || ent->guilty)
655 continue;
656 find_copy_in_blob(sb, ent, parent, split, &file_p);
648 - if (split[1].suspect)
657 + if (split[1].suspect &&
658 + blame_move_score < ent_score(sb, &split[1]))
659 split_blame(sb, split, ent);
660 }
661 free(blob_p);
@@ -716,7 +726,8 @@ static int find_copy_in_parent(struct scoreboard *sb,
726 find_copy_in_blob(sb, ent, norigin, this, &file_p);
727 copy_split_if_better(sb, split, this);
728 }
719 - if (split[1].suspect)
729 + if (split[1].suspect &&
730 + blame_copy_score < ent_score(sb, &split[1]))
731 split_blame(sb, split, ent);
732 }
733 diff_flush(&diff_opts);
@@ -1180,6 +1191,15 @@ static int has_path_in_work_tree(const char *path)
1191 return !lstat(path, &st);
1192 }
1193
1194 +static unsigned parse_score(const char *arg)
1195 +{
1196 + char *end;
1197 + unsigned long score = strtoul(arg, &end, 10);
1198 + if (*end)
1199 + return 0;
1200 + return score;
1201 +}
1202 +
1203 int cmd_pickaxe(int argc, const char **argv, const char *prefix)
1204 {
1205 struct rev_info revs;
@@ -1209,12 +1229,15 @@ int cmd_pickaxe(int argc, const char **argv, const char *prefix)
1229 output_option |= OUTPUT_LONG_OBJECT_NAME;
1230 else if (!strcmp("-S", arg) && ++i < argc)
1231 revs_file = argv[i];
1212 - else if (!strcmp("-M", arg))
1232 + else if (!strncmp("-M", arg, 2)) {
1233 opt |= PICKAXE_BLAME_MOVE;
1214 - else if (!strcmp("-C", arg)) {
1234 + blame_move_score = parse_score(arg+2);
1235 + }
1236 + else if (!strncmp("-C", arg, 2)) {
1237 if (opt & PICKAXE_BLAME_COPY)
1238 opt |= PICKAXE_BLAME_COPY_HARDER;
1239 opt |= PICKAXE_BLAME_COPY | PICKAXE_BLAME_MOVE;
1240 + blame_copy_score = parse_score(arg+2);
1241 }
1242 else if (!strcmp("-L", arg) && ++i < argc) {
1243 char *term;
@@ -1252,6 +1275,11 @@ int cmd_pickaxe(int argc, const char **argv, const char *prefix)
1275 argv[unk++] = arg;
1276 }
1277
1278 + if (!blame_move_score)
1279 + blame_move_score = BLAME_DEFAULT_MOVE_SCORE;
1280 + if (!blame_copy_score)
1281 + blame_copy_score = BLAME_DEFAULT_COPY_SCORE;
1282 +
1283 /* We have collected options unknown to us in argv[1..unk]
1284 * which are to be passed to revision machinery if we are
1285 * going to do the "bottom" procesing.