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 <whydoubt@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff Smith committed May 24, 2017 at 00:15 UTC 4149c1860b10512cf32410c1f71311a23dc97f07
1 file changed +19 -8
builtin/blame.c
+19 -8
@@ -387,6 +387,10 @@ struct blame_scoreboard {
387 int show_root;
388 int xdl_opts;
389 int no_whole_file_rename;
390 + int debug;
391 +
392 + /* callbacks */
393 + void(*on_sanity_fail)(struct blame_scoreboard *, int);
394 };
395
396 static void sanity_check_refcnt(struct blame_scoreboard *);
@@ -412,7 +416,7 @@ static void blame_coalesce(struct blame_scoreboard *sb)
416 }
417 }
418
415 - if (DEBUG) /* sanity */
419 + if (sb->debug) /* sanity */
420 sanity_check_refcnt(sb);
421 }
422
@@ -1809,7 +1813,7 @@ static void assign_blame(struct blame_scoreboard *sb, int opt)
1813 }
1814 blame_origin_decref(suspect);
1815
1812 - if (DEBUG) /* sanity */
1816 + if (sb->debug) /* sanity */
1817 sanity_check_refcnt(sb);
1818 }
1819
@@ -2148,12 +2152,16 @@ static void sanity_check_refcnt(struct blame_scoreboard *sb)
2152 baa = 1;
2153 }
2154 }
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);
2165 }
2166
2167 static unsigned parse_score(const char *arg)
@@ -2888,6 +2896,9 @@ parse_done:
2896 if (blame_copy_score)
2897 sb.copy_score = blame_copy_score;
2898
2899 + sb.debug = DEBUG;
2900 + sb.on_sanity_fail = &sanity_check_on_fail;
2901 +
2902 sb.show_root = show_root;
2903 sb.xdl_opts = xdl_opts;
2904 sb.no_whole_file_rename = no_whole_file_rename;