Skip to content

Commit 45b6251

Browse files
committed
apply: code simplification
Rewrite a bit hard-to-read ternary ?: expression into a cascade of if/else. Given that read-cache.c:add_index_entry() makes sure that the .ce_mode member is filled with a reasonable value before placing a cache entry in the index, if we see (ce_mode == 0), there is something seriously wrong going on. Catch such a bug and abort, instead of silently ignoring such an entry and silently skipping the check. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 01aff0a commit 45b6251

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

apply.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3780,11 +3780,15 @@ static int check_preimage(struct apply_state *state,
37803780
}
37813781

37823782
if (!state->cached && !previous) {
3783-
if (!trust_executable_bit)
3784-
st_mode = (*ce && (*ce)->ce_mode)
3785-
? (*ce)->ce_mode : patch->old_mode;
3786-
else
3783+
if (*ce && !(*ce)->ce_mode)
3784+
BUG("ce_mode == 0 for path '%s'", old_name);
3785+
3786+
if (trust_executable_bit)
37873787
st_mode = ce_mode_from_stat(*ce, st->st_mode);
3788+
else if (*ce)
3789+
st_mode = (*ce)->ce_mode;
3790+
else
3791+
st_mode = patch->old_mode;
37883792
}
37893793

37903794
if (patch->is_new < 0)

0 commit comments

Comments
 (0)