[PATCH v2] diff-lib: Fix check_removed when fsmonitor is on

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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` may not be initialized. Since `lstat` calls
aren't not desired when fsmonitor is on, skip the entire gitlink check using
the same condition used to initialize `stat *st`.

Signed-off-by: Josip Sokcevic <sokcevic@xxxxxxxxxx>
---
 diff-lib.c                   | 19 +++++++++++++++----
 t/t7527-builtin-fsmonitor.sh |  5 +++++
 2 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/diff-lib.c b/diff-lib.c
index d8aa777a73..664613bb1b 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -39,11 +39,22 @@
 static int check_removed(const struct index_state *istate, 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 (!is_missing_file_error(errno))
-			return -1;
-		return 1;
+	if (ce->ce_flags & CE_FSMONITOR_VALID) {
+		/*
+		 * Both check_removed() and its callers expect lstat() to have
+		 * happened and, in particular, the st_mode field to be set.
+		 * Simulate this with the contents of ce.
+		 */
+		memset(st, 0, sizeof(*st));
+		st->st_mode = ce->ce_mode;
+	} else {
+		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)) {
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





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux