Skip to content

Commit 20c763f

Browse files
committed
treewide: replace assert() with BUG_IF_NOT() in special cases
When the compiler/linker cannot verify that an assert() invocation is free of side effects for us (e.g. because the assertion includes some kind of function call), replace the use of assert() with BUG_IF_NOT(). Signed-off-by: Elijah Newren <[email protected]>
1 parent 58cb8f6 commit 20c763f

7 files changed

+9
-9
lines changed

Diff for: diffcore-rename.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1406,7 +1406,7 @@ void diffcore_rename_extended(struct diff_options *options,
14061406

14071407
trace2_region_enter("diff", "setup", options->repo);
14081408
info.setup = 0;
1409-
assert(!dir_rename_count || strmap_empty(dir_rename_count));
1409+
BUG_IF_NOT(!dir_rename_count || strmap_empty(dir_rename_count));
14101410
want_copies = (detect_rename == DIFF_DETECT_COPY);
14111411
if (dirs_removed && (break_idx || want_copies))
14121412
BUG("dirs_removed incompatible with break/copy detection");

Diff for: merge-ort.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ static void path_msg(struct merge_options *opt,
791791
struct strbuf tmp = STRBUF_INIT;
792792

793793
/* Sanity checks */
794-
assert(omittable_hint ==
794+
BUG_IF_NOT(omittable_hint ==
795795
(!starts_with(type_short_descriptions[type], "CONFLICT") &&
796796
!starts_with(type_short_descriptions[type], "ERROR")) ||
797797
type == CONFLICT_DIR_RENAME_SUGGESTED);
@@ -1642,7 +1642,7 @@ static int handle_deferred_entries(struct merge_options *opt,
16421642
ci = strmap_get(&opt->priv->paths, path);
16431643
VERIFY_CI(ci);
16441644

1645-
assert(renames->deferred[side].trivial_merges_okay &&
1645+
BUG_IF_NOT(renames->deferred[side].trivial_merges_okay &&
16461646
!strset_contains(&renames->deferred[side].target_dirs,
16471647
path));
16481648
resolve_trivial_directory_merge(ci, side);

Diff for: merge-recursive.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1197,7 +1197,7 @@ static void print_commit(struct repository *repo, struct commit *commit)
11971197
struct pretty_print_context ctx = {0};
11981198
ctx.date_mode.type = DATE_NORMAL;
11991199
/* FIXME: Merge this with output_commit_title() */
1200-
assert(!merge_remote_util(commit));
1200+
BUG_IF_NOT(!merge_remote_util(commit));
12011201
repo_format_commit_message(repo, commit, " %h: %m %s", &sb, &ctx);
12021202
fprintf(stderr, "%s\n", sb.buf);
12031203
strbuf_release(&sb);

Diff for: object-file.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2706,7 +2706,7 @@ static int index_stream_convert_blob(struct index_state *istate,
27062706
struct strbuf sbuf = STRBUF_INIT;
27072707

27082708
assert(path);
2709-
assert(would_convert_to_git_filter_fd(istate, path));
2709+
BUG_IF_NOT(would_convert_to_git_filter_fd(istate, path));
27102710

27112711
convert_to_git_filter_fd(istate, path, fd, &sbuf,
27122712
get_conv_flags(flags));

Diff for: parallel-checkout.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ static int write_pc_item_to_fd(struct parallel_checkout_item *pc_item, int fd,
277277
ssize_t wrote;
278278

279279
/* Sanity check */
280-
assert(is_eligible_for_parallel_checkout(pc_item->ce, &pc_item->ca));
280+
BUG_IF_NOT(is_eligible_for_parallel_checkout(pc_item->ce, &pc_item->ca));
281281

282282
filter = get_stream_filter_ca(&pc_item->ca, &pc_item->ce->oid);
283283
if (filter) {

Diff for: scalar.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ static int add_or_remove_enlistment(int add)
241241

242242
static int start_fsmonitor_daemon(void)
243243
{
244-
assert(have_fsmonitor_support());
244+
BUG_IF_NOT(have_fsmonitor_support());
245245

246246
if (fsmonitor_ipc__get_state() != IPC_STATE__LISTENING)
247247
return run_git("fsmonitor--daemon", "start", NULL);
@@ -251,7 +251,7 @@ static int start_fsmonitor_daemon(void)
251251

252252
static int stop_fsmonitor_daemon(void)
253253
{
254-
assert(have_fsmonitor_support());
254+
BUG_IF_NOT(have_fsmonitor_support());
255255

256256
if (fsmonitor_ipc__get_state() == IPC_STATE__LISTENING)
257257
return run_git("fsmonitor--daemon", "stop", NULL);

Diff for: sequencer.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -4965,7 +4965,7 @@ static int pick_commits(struct repository *r,
49654965

49664966
ctx->reflog_message = sequencer_reflog_action(opts);
49674967
if (opts->allow_ff)
4968-
assert(!(opts->signoff || opts->no_commit ||
4968+
BUG_IF_NOT(!(opts->signoff || opts->no_commit ||
49694969
opts->record_origin || should_edit(opts) ||
49704970
opts->committer_date_is_author_date ||
49714971
opts->ignore_date));

0 commit comments

Comments
 (0)