Re: [PATCH v3] Teach git apply to respect core.fileMode settings
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Dec 26, 2023, 17:35 UTC
- Message-ID
- <xmqq4jg4j28z.fsf@gitster.g>
- In-Reply-To
- <82dadb69-5016-dec6-3699-4d994ea7929d@gmx.de>
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
Show 12 quoted lines
> I noticed a CI breakage in t2106.3 in `seen` that seems to be caused by > this, and I can make it go away with this patch: > > -- snip -- > From 5c2a709b629d396528dabe2f92bf3d4deb5bbdb2 Mon Sep 17 00:00:00 2001 > From: Johannes Schindelin <johannes.schindelin@gmx.de> > Date: Sun, 24 Dec 2023 14:01:49 +0100 > Subject: [PATCH] fixup! Teach git apply to respect core.fileMode settings > > As pointed out e.g. by t2016.3(git checkout -p), if the patch is to be > applied in reverse (`git apply -R`), then the `old_mode` is actually 0, > and we must use `new_mode` instead.
Good finding.
> While at it, add some defensive code to ignore `ce_mode` should it be 0.
Is it defensive or is it hiding a problematic index under the rug?
If there is an index entry whose ce_mode is 0, I suspect we would want to error out with a BUG(), unless it is an intent-to-add entry.
Shouldn't it cause an error to apply a patch that mucks with "newfile" after you did
$ git add -N newfile
If we allow ce_mode==0 to be propagated to st_mode, I suspect we will catch such a case with the "mode is different" warning code, at least.
Show 23 quoted lines
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
> apply.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/apply.c b/apply.c
> index 58f26c404136..5ad06ef2f843 100644
> --- a/apply.c
> +++ b/apply.c
> @@ -3780,7 +3780,9 @@ static int check_preimage(struct apply_state *state,
>
> if (!state->cached && !previous) {
> if (!trust_executable_bit)
> - st_mode = *ce ? (*ce)->ce_mode : patch->old_mode;
> + st_mode = *ce && (*ce)->ce_mode ? (*ce)->ce_mode :
> + (state->apply_in_reverse ?
> + patch->new_mode : patch->old_mode);
> else
> st_mode = ce_mode_from_stat(*ce, st->st_mode);
> }
> -- snap --
>
> I guess you can slap on that `Reviewed-by:` footer again, after all... ;-)Yup, Reviewed-by: is what the reviewer says "this version was reviewed by me and I found it satisfactory", so once you said the above, I can certainly do so.