From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Cc: Johannes Schindelin <johannes.schindelin@gmx.de>
Subject: [PATCH v4 2/3] apply: correctly reverse patch's pre- and post-image mode bits
Date: Tue, 26 Dec 2023 15:32:17 -0800 [thread overview]
Message-ID: <20231226233218.472054-3-gitster@pobox.com> (raw)
In-Reply-To: <20231226233218.472054-1-gitster@pobox.com>
When parsing the patch header, unless it is a patch that changes
file modes, we only read the mode bits into the .old_mode member of
the patch structure and leave .new_mode member as initialized, i.e.,
to 0. Later when we need the original mode bits, we consult .old_mode.
However, reverse_patches() that is used to swap the names and modes
of the preimage and postimage files is not aware of this convention,
leading the .old_mode to be 0 while the mode we read from the patch
is left in .new_mode.
Only swap .old_mode and .new_mode when .new_mode is not 0 (i.e. we
saw a patch that modifies the filemode and know what the new mode
is). When .new_mode is set to 0, it means the preimage and the
postimage files have the same mode (which is in the .old_mode member)
and when applying such a patch in reverse, the value in .old_mode is
what we expect the (reverse-) preimage file to have.
Reported-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
apply.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/apply.c b/apply.c
index 3b090652cf..6b1adccb2f 100644
--- a/apply.c
+++ b/apply.c
@@ -2220,7 +2220,8 @@ static void reverse_patches(struct patch *p)
struct fragment *frag = p->fragments;
SWAP(p->new_name, p->old_name);
- SWAP(p->new_mode, p->old_mode);
+ if (p->new_mode)
+ SWAP(p->new_mode, p->old_mode);
SWAP(p->is_new, p->is_delete);
SWAP(p->lines_added, p->lines_deleted);
SWAP(p->old_oid_prefix, p->new_oid_prefix);
@@ -3780,9 +3781,8 @@ 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 :
- (state->apply_in_reverse
- ? patch->new_mode : patch->old_mode);
+ st_mode = (*ce && (*ce)->ce_mode)
+ ? (*ce)->ce_mode : patch->old_mode;
else
st_mode = ce_mode_from_stat(*ce, st->st_mode);
}
--
2.43.0-174-g055bb6e996
next prev parent reply other threads:[~2023-12-26 23:32 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-18 14:09 [PATCH] Teach git apply to respect core.fileMode settings Chandra Pratap via GitGitGadget
2023-12-18 18:04 ` Junio C Hamano
2023-12-18 18:10 ` Junio C Hamano
2023-12-19 17:07 ` Chandra Pratap
2023-12-19 18:30 ` [PATCH v2] " Chandra Pratap via GitGitGadget
2023-12-19 20:46 ` Torsten Bögershausen
2023-12-19 22:21 ` Junio C Hamano
2023-12-20 10:08 ` [PATCH v3] " Chandra Pratap via GitGitGadget
2023-12-24 13:42 ` Johannes Schindelin
2023-12-26 17:35 ` Junio C Hamano
2023-12-26 19:18 ` Johannes Schindelin
2023-12-26 20:10 ` Junio C Hamano
2023-12-26 20:58 ` Junio C Hamano
2023-12-26 21:35 ` Junio C Hamano
2023-12-26 23:32 ` [PATCH v4 0/3] apply with core.filemode=false Junio C Hamano
2023-12-26 23:32 ` [PATCH v4 1/3] apply: ignore working tree filemode when !core.filemode Junio C Hamano
2023-12-26 23:32 ` Junio C Hamano [this message]
2023-12-26 23:32 ` [PATCH v4 3/3] apply: code simplification Junio C Hamano
2024-02-07 22:15 ` [PATCH v4 0/3] apply with core.filemode=false Junio C Hamano
2024-02-18 22:38 ` Johannes Schindelin
2024-02-19 21:24 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231226233218.472054-3-gitster@pobox.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=johannes.schindelin@gmx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).