Skip to content

Commit 4149c18

Browse files
whydoubtgitster
authored andcommitted
blame: make sanity_check use a callback in scoreboard
Allow the interface user to decide how to handle a failed sanity check, whether that be to output with the current state or to do nothing. Signed-off-by: Jeff Smith <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1f44129 commit 4149c18

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

builtin/blame.c

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,10 @@ struct blame_scoreboard {
387387
int show_root;
388388
int xdl_opts;
389389
int no_whole_file_rename;
390+
int debug;
391+
392+
/* callbacks */
393+
void(*on_sanity_fail)(struct blame_scoreboard *, int);
390394
};
391395

392396
static void sanity_check_refcnt(struct blame_scoreboard *);
@@ -412,7 +416,7 @@ static void blame_coalesce(struct blame_scoreboard *sb)
412416
}
413417
}
414418

415-
if (DEBUG) /* sanity */
419+
if (sb->debug) /* sanity */
416420
sanity_check_refcnt(sb);
417421
}
418422

@@ -1809,7 +1813,7 @@ static void assign_blame(struct blame_scoreboard *sb, int opt)
18091813
}
18101814
blame_origin_decref(suspect);
18111815

1812-
if (DEBUG) /* sanity */
1816+
if (sb->debug) /* sanity */
18131817
sanity_check_refcnt(sb);
18141818
}
18151819

@@ -2148,12 +2152,16 @@ static void sanity_check_refcnt(struct blame_scoreboard *sb)
21482152
baa = 1;
21492153
}
21502154
}
2151-
if (baa) {
2152-
int opt = 0160;
2153-
find_alignment(sb, &opt);
2154-
output(sb, opt);
2155-
die("Baa %d!", baa);
2156-
}
2155+
if (baa)
2156+
sb->on_sanity_fail(sb, baa);
2157+
}
2158+
2159+
static void sanity_check_on_fail(struct blame_scoreboard *sb, int baa)
2160+
{
2161+
int opt = OUTPUT_SHOW_SCORE | OUTPUT_SHOW_NUMBER | OUTPUT_SHOW_NAME;
2162+
find_alignment(sb, &opt);
2163+
output(sb, opt);
2164+
die("Baa %d!", baa);
21572165
}
21582166

21592167
static unsigned parse_score(const char *arg)
@@ -2888,6 +2896,9 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
28882896
if (blame_copy_score)
28892897
sb.copy_score = blame_copy_score;
28902898

2899+
sb.debug = DEBUG;
2900+
sb.on_sanity_fail = &sanity_check_on_fail;
2901+
28912902
sb.show_root = show_root;
28922903
sb.xdl_opts = xdl_opts;
28932904
sb.no_whole_file_rename = no_whole_file_rename;

0 commit comments

Comments
 (0)