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@xxxxxxxxx> --- blame.h | 4 ++++ builtin/blame.c | 23 +++++++++++++++-------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/blame.h b/blame.h index c140f41..e85db06 100644 --- a/blame.h +++ b/blame.h @@ -134,6 +134,10 @@ struct blame_scoreboard { int show_root; int xdl_opts; int no_whole_file_rename; + int debug; + + /* callbacks */ + void(*on_sanity_fail)(struct blame_scoreboard *, int); }; #endif /* BLAME_H */ diff --git a/builtin/blame.c b/builtin/blame.c index bd295eb..d7b3b5a 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -285,7 +285,7 @@ static void coalesce(struct blame_scoreboard *sb) } } - if (DEBUG) /* sanity */ + if (sb->debug) /* sanity */ sanity_check_refcnt(sb); } @@ -1682,7 +1682,7 @@ static void assign_blame(struct blame_scoreboard *sb, int opt) } origin_decref(suspect); - if (DEBUG) /* sanity */ + if (sb->debug) /* sanity */ sanity_check_refcnt(sb); } @@ -2021,12 +2021,16 @@ static void sanity_check_refcnt(struct blame_scoreboard *sb) baa = 1; } } - if (baa) { - int opt = 0160; - find_alignment(sb, &opt); - output(sb, opt); - die("Baa %d!", baa); - } + if (baa) + sb->on_sanity_fail(sb, baa); +} + +static void sanity_check_on_fail(struct blame_scoreboard *sb, int baa) +{ + int opt = OUTPUT_SHOW_SCORE | OUTPUT_SHOW_NUMBER | OUTPUT_SHOW_NAME; + find_alignment(sb, &opt); + output(sb, opt); + die("Baa %d!", baa); } static unsigned parse_score(const char *arg) @@ -2761,6 +2765,9 @@ int cmd_blame(int argc, const char **argv, const char *prefix) if (blame_copy_score) sb.copy_score = blame_copy_score; + sb.debug = DEBUG; + sb.on_sanity_fail = &sanity_check_on_fail; + sb.show_root = show_root; sb.xdl_opts = xdl_opts; sb.no_whole_file_rename = no_whole_file_rename; -- 2.9.3