aboutsummaryrefslogtreecommitdiffstats
path: root/apply.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2023-12-26 15:32:18 -0800
committerJunio C Hamano <gitster@pobox.com>2023-12-26 21:20:32 -0800
commit45b625142d8ca2218af1fb2b37216e58953e775d (patch)
treefe2f7df714cf0d4cfac8bae919358bb8371110dc /apply.c
parent01aff0ae85af100c4d88df753078158b82774ea0 (diff)
downloadgit-45b625142d8ca2218af1fb2b37216e58953e775d.tar.gz
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>
Diffstat (limited to 'apply.c')
-rw-r--r--apply.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/apply.c b/apply.c
index 6b1adccb2f..493a263a48 100644
--- a/apply.c
+++ b/apply.c
@@ -3780,11 +3780,15 @@ static int check_preimage(struct apply_state *state,
}
if (!state->cached && !previous) {
- if (!trust_executable_bit)
- st_mode = (*ce && (*ce)->ce_mode)
- ? (*ce)->ce_mode : patch->old_mode;
- else
+ if (*ce && !(*ce)->ce_mode)
+ BUG("ce_mode == 0 for path '%s'", old_name);
+
+ if (trust_executable_bit)
st_mode = ce_mode_from_stat(*ce, st->st_mode);
+ else if (*ce)
+ st_mode = (*ce)->ce_mode;
+ else
+ st_mode = patch->old_mode;
}
if (patch->is_new < 0)