From: Josip Sokcevic <sokcevic@google•com>
To: gitster@pobox•com, jonathantanmy@google•com
Cc: git@vger•kernel.org, git@jeffhostetler•com,
Josip Sokcevic <sokcevic@google•com>
Subject: [PATCH v3] diff-lib: Fix check_removed when fsmonitor is on
Date: Mon, 11 Sep 2023 10:09:02 -0700 [thread overview]
Message-ID: <20230911170901.49050-2-sokcevic@google.com> (raw)
In-Reply-To: <20230906060241.944886-2-sokcevic@google.com>
git-diff-index may return incorrect deleted entries when fsmonitor is used in a
repository with git submodules. This can be observed on Mac machines, but it
can affect all other supported platforms too.
If fsmonitor is used, `stat *st` is not initialized if cache_entry has
CE_FSMONITOR_VALID set. But, there are three call sites that rely on stat
afterwards, which can result in incorrect results.
This change partially reverts commit 4f3d6d0.
Signed-off-by: Josip Sokcevic <sokcevic@google•com>
---
diff-lib.c | 12 ++++++------
t/t7527-builtin-fsmonitor.sh | 5 +++++
2 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/diff-lib.c b/diff-lib.c
index d8aa777a73..5848e4f9ca 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -36,14 +36,14 @@
* exists for ce that is a submodule -- it is a submodule that is not
* checked out). Return negative for an error.
*/
-static int check_removed(const struct index_state *istate, const struct cache_entry *ce, struct stat *st)
+static int check_removed(const struct cache_entry *ce, struct stat *st)
{
- assert(is_fsmonitor_refreshed(istate));
- if (!(ce->ce_flags & CE_FSMONITOR_VALID) && lstat(ce->name, st) < 0) {
+ if (lstat(ce->name, st) < 0) {
if (!is_missing_file_error(errno))
return -1;
return 1;
}
+
if (has_symlink_leading_path(ce->name, ce_namelen(ce)))
return 1;
if (S_ISDIR(st->st_mode)) {
@@ -149,7 +149,7 @@ void run_diff_files(struct rev_info *revs, unsigned int option)
memset(&(dpath->parent[0]), 0,
sizeof(struct combine_diff_parent)*5);
- changed = check_removed(istate, ce, &st);
+ changed = check_removed(ce, &st);
if (!changed)
wt_mode = ce_mode_from_stat(ce, st.st_mode);
else {
@@ -229,7 +229,7 @@ void run_diff_files(struct rev_info *revs, unsigned int option)
} else {
struct stat st;
- changed = check_removed(istate, ce, &st);
+ changed = check_removed(ce, &st);
if (changed) {
if (changed < 0) {
perror(ce->name);
@@ -303,7 +303,7 @@ static int get_stat_data(const struct index_state *istate,
if (!cached && !ce_uptodate(ce)) {
int changed;
struct stat st;
- changed = check_removed(istate, ce, &st);
+ changed = check_removed(ce, &st);
if (changed < 0)
return -1;
else if (changed) {
diff --git a/t/t7527-builtin-fsmonitor.sh b/t/t7527-builtin-fsmonitor.sh
index 0c241d6c14..78503158fd 100755
--- a/t/t7527-builtin-fsmonitor.sh
+++ b/t/t7527-builtin-fsmonitor.sh
@@ -809,6 +809,11 @@ my_match_and_clean () {
status --porcelain=v2 >actual.without &&
test_cmp actual.with actual.without &&
+ git -C super --no-optional-locks diff-index --name-status HEAD >actual.with &&
+ git -C super --no-optional-locks -c core.fsmonitor=false \
+ diff-index --name-status HEAD >actual.without &&
+ test_cmp actual.with actual.without &&
+
git -C super/dir_1/dir_2/sub reset --hard &&
git -C super/dir_1/dir_2/sub clean -d -f
}
--
2.42.0.283.g2d96d420d3-goog
next prev parent reply other threads:[~2023-09-11 21:39 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-29 0:56 Strange diff-index with fsmonitor, submodules Jonathan Tan
2023-08-29 1:20 ` Junio C Hamano
2023-08-29 12:45 ` Jeff Hostetler
2023-08-29 16:57 ` Jeff Hostetler
2023-08-29 17:01 ` Jonathan Tan
2023-09-06 6:02 ` [PATCH] [diff-lib] Fix check_removed when fsmonitor is on Josip Sokcevic
2023-09-06 20:37 ` Jonathan Tan
2023-09-07 17:01 ` [PATCH v2] diff-lib: " Josip Sokcevic
2023-09-07 17:22 ` Jonathan Tan
2023-09-07 18:07 ` Junio C Hamano
2023-09-07 23:08 ` Josip Sokcevic
2023-09-08 15:00 ` Junio C Hamano
2023-09-11 17:09 ` Josip Sokcevic [this message]
2023-09-11 22:53 ` [PATCH v3] " Junio C Hamano
2023-09-12 3:03 ` Josip Sokcevic
2023-09-12 17:07 ` Junio C Hamano
2023-09-14 22:39 ` Josip Sokcevic
2023-09-18 16:35 ` 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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230911170901.49050-2-sokcevic@google.com \
--to=sokcevic@google$(echo .)com \
--cc=git@jeffhostetler$(echo .)com \
--cc=git@vger$(echo .)kernel.org \
--cc=gitster@pobox$(echo .)com \
--cc=jonathantanmy@google$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox