Merge branch 'ab/bug-if-bug'

A new bug() and BUG_if_bug() API is introduced to make it easier to
uniformly log "detect multiple bugs and abort in the end" pattern.

* ab/bug-if-bug:
  cache-tree.c: use bug() and BUG_if_bug()
  receive-pack: use bug() and BUG_if_bug()
  parse-options.c: use optbug() instead of BUG() "opts" check
  parse-options.c: use new bug() API for optbug()
  usage.c: add a non-fatal bug() function to go with BUG()
  common-main.c: move non-trace2 exit() behavior out of trace2.c
This commit is contained in:
Junio C Hamano
2022-06-10 15:04:15 -07:00
12 changed files with 232 additions and 71 deletions

View File

@ -722,14 +722,14 @@ struct tree* write_in_core_index_as_tree(struct repository *repo) {
ret = write_index_as_tree_internal(&o, index_state, was_valid, 0, NULL);
if (ret == WRITE_TREE_UNMERGED_INDEX) {
int i;
fprintf(stderr, "BUG: There are unmerged index entries:\n");
bug("there are unmerged index entries:");
for (i = 0; i < index_state->cache_nr; i++) {
const struct cache_entry *ce = index_state->cache[i];
if (ce_stage(ce))
fprintf(stderr, "BUG: %d %.*s\n", ce_stage(ce),
(int)ce_namelen(ce), ce->name);
bug("%d %.*s", ce_stage(ce),
(int)ce_namelen(ce), ce->name);
}
BUG("unmerged index entries when writing inmemory index");
BUG("unmerged index entries when writing in-core index");
}
return lookup_tree(repo, &index_state->cache_tree->oid);