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 <gitster@pobox.com>
Junio C Hamano committed
Dec 26, 2023 at 15:32 UTC
45b625142d8ca2218af1fb2b37216e58953e775d
1 file changed
+8
-4
apply.c
+8
-4
@@ -3780,11 +3780,15 @@ static int check_preimage(struct apply_state *state,
3780
}
3781
3782
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)
3787
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;
3792
}
3793
3794
if (patch->is_new < 0)