From patchwork Fri Feb 23 03:18:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Hostetler X-Patchwork-Id: 13568516 Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 62E36C2FD for ; Fri, 23 Feb 2024 03:18:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708658309; cv=none; b=BcVl2fLY7V8O9ZYquFzGZ+0e1/qkHE/YRY9DBPIC6YhzW/oUYBgpsm/GwZODrQMDgBenaBK8okwqYqGwjax/Dv1CGmU+YGloGrU5gEPZFGCh9cv2j02NAzS7I7bp5OmGWZIYNjWm/O4Ctmq3WQ+4nq7seV8ZYdaeV8QbmubdAsc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708658309; c=relaxed/simple; bh=X7z8wM+7z4Wo03bBfMBc+EcBTjaJj/HA91HRxeVfVXg=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=jpD+3mhgBzvDagpUF7JHiJtpX1dZzo44oZhXTCPT+pIxgRjOdk+Sa7Kqa1JOB0iLkw3RWxgfuvOtFqQLYAVky98Yfch7t4E5awkThNMJqg3+3lkdOJBDgAevv4XhpVnhzyFsNWNZe4uJDKbU9D3fYhTWa4WFzlUQ/a92DiYfZpI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=NZsHnSOb; arc=none smtp.client-ip=209.85.208.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NZsHnSOb" Received: by mail-lj1-f177.google.com with SMTP id 38308e7fff4ca-2d228a132acso6345491fa.0 for ; Thu, 22 Feb 2024 19:18:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708658303; x=1709263103; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=9Mj+I5jSFetbDnyRBkw1H3MLII/QvfFpIXksGvxGp74=; b=NZsHnSObnUowfGMSdpB7/OUCw0CRxXQxT/NGAMZfPrbZ0xy0rXgyM7CngcABB0yebq P9w0jAD7mlz8e/k287VZtV6PoAxliskNx3CoLJuTSC1IuYoXVT0N1JCmw70iS+Ve83Rk gRFHEKp6Ba51lgzoFNKhP3d2GYxZ430wkc37BNhXzXaSwCzRiCMOcUljaJWSUw/3kI8d 7C16gY8bQ55SDMk/LQ6H1C714ihNTWYh4G0/asVJAwpKxdrE1mvf1SsR4ctL5cPwe/OM af5DTC7OX1PxbsKNNx38x/+3D3p8H8dgIXXH11q9dfPIEKSbTkFd9KZsyW0gUIHG3o8i f46w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708658303; x=1709263103; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9Mj+I5jSFetbDnyRBkw1H3MLII/QvfFpIXksGvxGp74=; b=luTlWlGc6RVc5rPUMlS+tLdGf4c3u7LivwzHULH5cU7f+1u4612A/UfNJTy0s7v4UQ LGFVrNBOxj4N52tX865AhnAIwbeZ8QHb61D3R08wI8OoRShBKB7OwgzdPPYeki0PUpvM 3/Q+R3JizlypVP0LWrD3r1+64W5NGNx/YV1DyqE/4x6FP2VA9A+pL8dblJpBljL0pEsx zmGrIRlhET0vRUCM+80CeatZhOUfVdA3j4Hii7nbxiRqdp4QAMA4Y49KJA5xlUX3G1G7 Psn5tkuif1ET2/dnSsD+xRtExe1Wsd19HCsw0oQHGFxPzGwJ27dPn73+IhDIxp4oPLCv XvdA== X-Gm-Message-State: AOJu0YyFeHlutFvwADSHfKz6+vb6VP882rkcd+0dpVCswaMkkOU4yW8c 1ZnDEQRDq/hBzj2Exye1qInoT7JG4qR583MiEAc+Z2/JaTY6PnIZiVrtVcgC X-Google-Smtp-Source: AGHT+IGHBautectAYohF85KfJm9cMIMD0TGlXWRCz84fLVls03g3m6dH5zlZolXZpUOxRrXkVYmPPw== X-Received: by 2002:a05:651c:211:b0:2d2:3f09:ca3e with SMTP id y17-20020a05651c021100b002d23f09ca3emr407765ljn.50.1708658303063; Thu, 22 Feb 2024 19:18:23 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id p11-20020a05600c468b00b004128812dcb6sm583597wmo.28.2024.02.22.19.18.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 19:18:22 -0800 (PST) Message-ID: <03b07d9c25edb951db4de518212f8a3e9e184e49.1708658300.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 23 Feb 2024 03:18:05 +0000 Subject: [PATCH v2 01/16] name-hash: add index_dir_find() Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Patrick Steinhardt , Jeff Hostetler , Jeff Hostetler , Jeff Hostetler From: Jeff Hostetler From: Jeff Hostetler Replace the index_dir_exists() function with index_dir_find() and change the API to take an optional strbuf to return the canonical spelling of the matched directory prefix. Create an index_dir_exists() wrapper macro for existing callers. The existing index_dir_exists() returns a boolean to indicate if there is a case-insensitive match in the directory name-hash, but it doesn't tell the caller the exact spelling of that match. The new version also copies the matched spelling to a provided strbuf. This lets the caller, for example, then call index_name_pos() with the correct case to search the cache-entry array for the real insertion position. Signed-off-by: Jeff Hostetler --- name-hash.c | 9 ++++++++- name-hash.h | 7 ++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/name-hash.c b/name-hash.c index 251f036eef6..3a58ce03d9c 100644 --- a/name-hash.c +++ b/name-hash.c @@ -685,13 +685,20 @@ static int same_name(const struct cache_entry *ce, const char *name, int namelen return slow_same_name(name, namelen, ce->name, len); } -int index_dir_exists(struct index_state *istate, const char *name, int namelen) +int index_dir_find(struct index_state *istate, const char *name, int namelen, + struct strbuf *canonical_path) { struct dir_entry *dir; lazy_init_name_hash(istate); expand_to_path(istate, name, namelen, 0); dir = find_dir_entry(istate, name, namelen); + + if (canonical_path && dir && dir->nr) { + strbuf_reset(canonical_path); + strbuf_add(canonical_path, dir->name, dir->namelen); + } + return dir && dir->nr; } diff --git a/name-hash.h b/name-hash.h index b1b4b0fb337..0cbfc428631 100644 --- a/name-hash.h +++ b/name-hash.h @@ -4,7 +4,12 @@ struct cache_entry; struct index_state; -int index_dir_exists(struct index_state *istate, const char *name, int namelen); + +int index_dir_find(struct index_state *istate, const char *name, int namelen, + struct strbuf *canonical_path); + +#define index_dir_exists(i, n, l) index_dir_find((i), (n), (l), NULL) + void adjust_dirname_case(struct index_state *istate, char *name); struct cache_entry *index_file_exists(struct index_state *istate, const char *name, int namelen, int igncase); From patchwork Fri Feb 23 03:18:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Hostetler X-Patchwork-Id: 13568518 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A5824C2FE for ; Fri, 23 Feb 2024 03:18:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708658310; cv=none; b=Fj8EiREWp7Rs+7QZtm0/w7CBNfu5hPu0tpKY/yXxXZPeNlNm1u37zPDq5fNu1wekUt/dcdpxaLWq3+i/D6PehFR+C5Wg98J6o9NA1YEd0heh58OGwIfB17zEpkRNA28O3gPhQDCOHmdjIaSSUb7/92qpxZgmSH3scxnnPmvBwGE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708658310; c=relaxed/simple; bh=4JKneJwbNMSmAuubfrlVVtUKbJ6fLoga89RW/eoe/eQ=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=njAJ+amBFdLVYo561jcdZARCqnCPsRimvxNBheMwSkxuijfNUytL1xrwuihd4ViBmx02il6MZP1OiaOgmta5s5CD18RF0NylzdhpI9Mml1hpvj8/Twmom0w1EkBpbQz7qBRQtWtSmurFJF5HVO/8BqJ3zQC2YzswG+cugpm6i5E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Yq3PdlLk; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Yq3PdlLk" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-4127190ad83so2820285e9.0 for ; Thu, 22 Feb 2024 19:18:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708658305; x=1709263105; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=PUTT3EwPugWChbjPami5aVSlXG19814a92C62fz4OHw=; b=Yq3PdlLk1qYKVISrZPcqL7pWWnyGy+SMFgmedbJX+QwNE2Xe+nIy9mmJz1msYtnw38 RifaAjlZ2UrAwFsL7WZMvWtLd4/UQ96gBXi5v1rHFT65DM6SoX7HJl1eBCcR+np5bfIR PGPzQgXVLD+2r8ZgfcPfauFWvZ26TGxz03v1A98nPAAgquFE2HgnuQ0RquIoWnWsKcaA D6/TYs2w4Y9suK/yHmqgWzA4xptzFmuUc1w+5nGiPMraWReY07k6VHCchFHf0hlZy6vN t+ImZLLzHV2zj/SS97r1X+cdspC2uLfhTKJXK0P4PV6ItUlYs9RnmtWWeX+KeMY9EHLQ hH1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708658305; x=1709263105; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PUTT3EwPugWChbjPami5aVSlXG19814a92C62fz4OHw=; b=tQAfPFh6g2/I+qs6APTRV7mQDQ2T4vp8WNh5qnZSAo9RBVH0IwhNTfKIbEYpU5XsHz bS20P2AFcc+PaPvCZgamYmCIy6X9p4KYK/0Qb2A6a3yrlESEGGQM8cf9oXSR85Yj9fDi fhQxywT20AhVbR707/KUaRGnYuIMxkXHgFmKaaAuKtY3kGYQwUBAsLArymEtPpl+F8ws XOm5Z9Rlg05y200I4OwlnCYaudhmN0sCpUM7ZWaPhXtIyAU9WA4VKF0LkgmfwpiGARnH pEONOUlse6f9ryJoFjRDjPecAVLl4VgWjKnrsxNRowevkQFSuTrCilzK0gdkIrgJlVlh JW/A== X-Gm-Message-State: AOJu0YzUPZhUU4cWrgyo8PPnPGFAJLGCfXHfMVNC+Tx/b+C/LhaLX7Lh a3UR1kSHqPTsniVWXeUxfXFDvRdUD1VYTauHl5i9xZ7JpxoNMIWcq7xOXXvb X-Google-Smtp-Source: AGHT+IHcWtvgXnjBpcEjSGfYjg2TCr9ymdY1Mh2HM9MDS9APfeDr8VZk/0bmq6xuf+BVP9KpN2rLoA== X-Received: by 2002:a05:600c:4f54:b0:412:283e:5782 with SMTP id m20-20020a05600c4f5400b00412283e5782mr305425wmq.28.1708658305020; Thu, 22 Feb 2024 19:18:25 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id p3-20020a05600c358300b004128d7520e8sm581658wmq.45.2024.02.22.19.18.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 19:18:23 -0800 (PST) Message-ID: <7778cee1c1056963eaf4c28c667b7194b9eeb450.1708658300.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 23 Feb 2024 03:18:06 +0000 Subject: [PATCH v2 02/16] t7527: add case-insensitve test for FSMonitor Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Patrick Steinhardt , Jeff Hostetler , Jeff Hostetler , Jeff Hostetler From: Jeff Hostetler From: Jeff Hostetler The FSMonitor client code trusts the spelling of the pathnames in the FSEvents received from the FSMonitor daemon. On case-insensitive file systems, these OBSERVED pathnames may be spelled differently than the EXPECTED pathnames listed in the .git/index. This causes a miss when using `index_name_pos()` which expects the given case to be correct. When this happens, the FSMonitor client code does not update the state of the CE_FSMONITOR_VALID bit when refreshing the index (and before starting to scan the worktree). This results in modified files NOT being reported by `git status` when there is a discrepancy in the case-spelling of a tracked file's pathname. This commit contains a (rather contrived) test case to demonstrate this. A later commit in this series will update the FSMonitor client code to recognize these discrepancies and update the CE_ bit accordingly. Signed-off-by: Jeff Hostetler --- t/t7527-builtin-fsmonitor.sh | 217 +++++++++++++++++++++++++++++++++++ 1 file changed, 217 insertions(+) diff --git a/t/t7527-builtin-fsmonitor.sh b/t/t7527-builtin-fsmonitor.sh index 363f9dc0e41..3d21295f789 100755 --- a/t/t7527-builtin-fsmonitor.sh +++ b/t/t7527-builtin-fsmonitor.sh @@ -1037,4 +1037,221 @@ test_expect_success 'split-index and FSMonitor work well together' ' ) ' +# The FSMonitor daemon reports the OBSERVED pathname of modified files +# and thus contains the OBSERVED spelling on case-insensitive file +# systems. The daemon does not (and should not) load the .git/index +# file and therefore does not know the expected case-spelling. Since +# it is possible for the user to create files/subdirectories with the +# incorrect case, a modified file event for a tracked will not have +# the EXPECTED case. This can cause `index_name_pos()` to incorrectly +# report that the file is untracked. This causes the client to fail to +# mark the file as possibly dirty (keeping the CE_FSMONITOR_VALID bit +# set) so that `git status` will avoid inspecting it and thus not +# present in the status output. +# +# The setup is a little contrived. +# +test_expect_success CASE_INSENSITIVE_FS 'fsmonitor subdir case wrong on disk' ' + test_when_finished "stop_daemon_delete_repo subdir_case_wrong" && + + git init subdir_case_wrong && + ( + cd subdir_case_wrong && + echo x >AAA && + echo x >BBB && + + mkdir dir1 && + echo x >dir1/file1 && + mkdir dir1/dir2 && + echo x >dir1/dir2/file2 && + mkdir dir1/dir2/dir3 && + echo x >dir1/dir2/dir3/file3 && + + echo x >yyy && + echo x >zzz && + git add . && + git commit -m "data" && + + # This will cause "dir1/" and everything under it + # to be deleted. + git sparse-checkout set --cone --sparse-index && + + # Create dir2 with the wrong case and then let Git + # repopulate dir3 -- it will not correct the spelling + # of dir2. + mkdir dir1 && + mkdir dir1/DIR2 && + git sparse-checkout add dir1/dir2/dir3 + ) && + + start_daemon -C subdir_case_wrong --tf "$PWD/subdir_case_wrong.trace" && + + # Enable FSMonitor in the client. Run enough commands for + # the .git/index to sync up with the daemon with everything + # marked clean. + git -C subdir_case_wrong config core.fsmonitor true && + git -C subdir_case_wrong update-index --fsmonitor && + git -C subdir_case_wrong status && + + # Make some files dirty so that FSMonitor gets FSEvents for + # each of them. + echo xx >>subdir_case_wrong/AAA && + echo xx >>subdir_case_wrong/dir1/DIR2/dir3/file3 && + echo xx >>subdir_case_wrong/zzz && + + GIT_TRACE_FSMONITOR="$PWD/subdir_case_wrong.log" \ + git -C subdir_case_wrong --no-optional-locks status --short \ + >"$PWD/subdir_case_wrong.out" && + + # "git status" should have gotten file events for each of + # the 3 files. + # + # "dir2" should be in the observed case on disk. + grep "fsmonitor_refresh_callback" \ + <"$PWD/subdir_case_wrong.log" \ + >"$PWD/subdir_case_wrong.log1" && + + grep -q "AAA.*pos 0" "$PWD/subdir_case_wrong.log1" && + grep -q "zzz.*pos 6" "$PWD/subdir_case_wrong.log1" && + + grep -q "dir1/DIR2/dir3/file3.*pos -3" "$PWD/subdir_case_wrong.log1" && + + # The refresh-callbacks should have caused "git status" to clear + # the CE_FSMONITOR_VALID bit on each of those files and caused + # the worktree scan to visit them and mark them as modified. + grep -q " M AAA" "$PWD/subdir_case_wrong.out" && + grep -q " M zzz" "$PWD/subdir_case_wrong.out" && + + # However, with the fsmonitor client bug, the "(pos -3)" causes + # the client to not update the bit and never rescan the file + # and therefore not report it as dirty. + ! grep -q " M dir1/dir2/dir3/file3" "$PWD/subdir_case_wrong.out" +' + +test_expect_success CASE_INSENSITIVE_FS 'fsmonitor file case wrong on disk' ' + test_when_finished "stop_daemon_delete_repo file_case_wrong" && + + git init file_case_wrong && + ( + cd file_case_wrong && + echo x >AAA && + echo x >BBB && + + mkdir dir1 && + mkdir dir1/dir2 && + mkdir dir1/dir2/dir3 && + echo x >dir1/dir2/dir3/FILE-3-B && + echo x >dir1/dir2/dir3/XXXX-3-X && + echo x >dir1/dir2/dir3/file-3-a && + echo x >dir1/dir2/dir3/yyyy-3-y && + mkdir dir1/dir2/dir4 && + echo x >dir1/dir2/dir4/FILE-4-A && + echo x >dir1/dir2/dir4/XXXX-4-X && + echo x >dir1/dir2/dir4/file-4-b && + echo x >dir1/dir2/dir4/yyyy-4-y && + + echo x >yyy && + echo x >zzz && + git add . && + git commit -m "data" + ) && + + start_daemon -C file_case_wrong --tf "$PWD/file_case_wrong.trace" && + + # Enable FSMonitor in the client. Run enough commands for + # the .git/index to sync up with the daemon with everything + # marked clean. + git -C file_case_wrong config core.fsmonitor true && + git -C file_case_wrong update-index --fsmonitor && + git -C file_case_wrong status && + + # Make some files dirty so that FSMonitor gets FSEvents for + # each of them. + echo xx >>file_case_wrong/AAA && + echo xx >>file_case_wrong/zzz && + + # Rename some files so that FSMonitor sees a create and delete + # FSEvent for each. (A simple "mv foo FOO" is not portable + # between macOS and Windows. It works on both platforms, but makes + # the test messy, since (1) one platform updates "ctime" on the + # moved file and one does not and (2) it causes a directory event + # on one platform and not on the other which causes additional + # scanning during "git status" which causes a "H" vs "h" discrepancy + # in "git ls-files -f".) So old-school it and move it out of the + # way and copy it to the case-incorrect name so that we get fresh + # "ctime" and "mtime" values. + + mv file_case_wrong/dir1/dir2/dir3/file-3-a file_case_wrong/dir1/dir2/dir3/ORIG && + cp file_case_wrong/dir1/dir2/dir3/ORIG file_case_wrong/dir1/dir2/dir3/FILE-3-A && + rm file_case_wrong/dir1/dir2/dir3/ORIG && + mv file_case_wrong/dir1/dir2/dir4/FILE-4-A file_case_wrong/dir1/dir2/dir4/ORIG && + cp file_case_wrong/dir1/dir2/dir4/ORIG file_case_wrong/dir1/dir2/dir4/file-4-a && + rm file_case_wrong/dir1/dir2/dir4/ORIG && + + # Run status enough times to fully sync. + # + # The first instance should get the create and delete FSEvents + # for each pair. Status should update the index with a new FSM + # token (so the next invocation will not see data for these + # events). + + GIT_TRACE_FSMONITOR="$PWD/file_case_wrong-try1.log" \ + git -C file_case_wrong status --short \ + >"$PWD/file_case_wrong-try1.out" && + grep -q "fsmonitor_refresh_callback.*FILE-3-A.*pos -3" "$PWD/file_case_wrong-try1.log" && + grep -q "fsmonitor_refresh_callback.*file-3-a.*pos 4" "$PWD/file_case_wrong-try1.log" && + grep -q "fsmonitor_refresh_callback.*FILE-4-A.*pos 6" "$PWD/file_case_wrong-try1.log" && + grep -q "fsmonitor_refresh_callback.*file-4-a.*pos -9" "$PWD/file_case_wrong-try1.log" && + + # FSM refresh will have invalidated the FSM bit and cause a regular + # (real) scan of these tracked files, so they should have "H" status. + # (We will not see a "h" status until the next refresh (on the next + # command).) + + git -C file_case_wrong ls-files -f >"$PWD/file_case_wrong-lsf1.out" && + grep -q "H dir1/dir2/dir3/file-3-a" "$PWD/file_case_wrong-lsf1.out" && + grep -q "H dir1/dir2/dir4/FILE-4-A" "$PWD/file_case_wrong-lsf1.out" && + + + # Try the status again. We assume that the above status command + # advanced the token so that the next one will not see those events. + + GIT_TRACE_FSMONITOR="$PWD/file_case_wrong-try2.log" \ + git -C file_case_wrong status --short \ + >"$PWD/file_case_wrong-try2.out" && + ! grep -q "fsmonitor_refresh_callback.*FILE-3-A.*pos" "$PWD/file_case_wrong-try2.log" && + ! grep -q "fsmonitor_refresh_callback.*file-3-a.*pos" "$PWD/file_case_wrong-try2.log" && + ! grep -q "fsmonitor_refresh_callback.*FILE-4-A.*pos" "$PWD/file_case_wrong-try2.log" && + ! grep -q "fsmonitor_refresh_callback.*file-4-a.*pos" "$PWD/file_case_wrong-try2.log" && + + # FSM refresh saw nothing, so it will mark all files as valid, + # so they should now have "h" status. + + git -C file_case_wrong ls-files -f >"$PWD/file_case_wrong-lsf2.out" && + grep -q "h dir1/dir2/dir3/file-3-a" "$PWD/file_case_wrong-lsf2.out" && + grep -q "h dir1/dir2/dir4/FILE-4-A" "$PWD/file_case_wrong-lsf2.out" && + + + # We now have files with clean content, but with case-incorrect + # file names. Modify them to see if status properly reports + # them. + + echo xx >>file_case_wrong/dir1/dir2/dir3/FILE-3-A && + echo xx >>file_case_wrong/dir1/dir2/dir4/file-4-a && + + GIT_TRACE_FSMONITOR="$PWD/file_case_wrong-try3.log" \ + git -C file_case_wrong --no-optional-locks status --short \ + >"$PWD/file_case_wrong-try3.out" && + # FSEvents are in observed case. + grep -q "fsmonitor_refresh_callback.*FILE-3-A.*pos -3" "$PWD/file_case_wrong-try3.log" && + grep -q "fsmonitor_refresh_callback.*file-4-a.*pos -9" "$PWD/file_case_wrong-try3.log" && + + # Status should say these files are modified, but with the case + # bug, the "pos -3" cause the client to not update the FSM bit + # and never cause the file to be rescanned and therefore to not + # report it dirty. + ! grep -q " M dir1/dir2/dir3/file-3-a" "$PWD/file_case_wrong-try3.out" && + ! grep -q " M dir1/dir2/dir4/FILE-4-A" "$PWD/file_case_wrong-try3.out" +' + test_done From patchwork Fri Feb 23 03:18:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Hostetler X-Patchwork-Id: 13568517 Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0138BB64C for ; Fri, 23 Feb 2024 03:18:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708658309; cv=none; b=pEGbwKtUxKTzbrB5jT/NsEO1t/EbE8gfYyRYBxRneMLwZ0gHVq7LNZ//a+aQxto5V8DiSoONBgXGlFkRIX6jp3hCFavODEBs9VA6Ltqy2IbyxeXD7/f+aLB5p313pjb7J+VAI8vtx+0bKXlQTPZjxjVcUC0v13EDgJhiHPcQxpQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708658309; c=relaxed/simple; bh=nvIzn7oVbV3QlBqTXXG8JwzeEDEpJ1m5+6x5d3KATLQ=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=DcLufMoJCA5qaJ7mWdA6TFWd716yRlhJp/mMQr4Tr4aOTRTiGOfM3wM5gGjEyOwOHIJNJe5wpVnfBbkVaKSpTmEWX0VNefn+0meC5RUGhrBIv7oAToGIGBDYFhEVJTEOGlqMusfiqejybECw53Jz9djdg//ZQEmB1RRwcQkrp6o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fsnppaVi; arc=none smtp.client-ip=209.85.208.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fsnppaVi" Received: by mail-lj1-f178.google.com with SMTP id 38308e7fff4ca-2d23a22233fso5594041fa.2 for ; Thu, 22 Feb 2024 19:18:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708658305; x=1709263105; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=Zyv4HE+62H12UhKwJANnJSL70xjGQPKa7udGRWyRwEU=; b=fsnppaViH/dIF4UM/lpcK0QIOMGIffo2qityVlyxTmN4UxytSIZmYIJE6sngzIXL1w xQI9jZP+3a+SzdnQGI2Ky1IxFYfHl704pj42Bo2IS8Owxxl/UcinBWarpZiswwj6QpbK fFOfGKGyOzq/Qk6Bjsx0pHWNI66L2GDwX2Y4LU7u2nAPWev0eTcrpkE15PzEtsvqqxZc WYiEwRt0TZltxwxBplndkYe8Mtf7lvSlG8lB5c46cr0RmlntJw38dYMfJG1Nk4Bf4bBx QtakQKOdpN30D1yeuO5cUsjUOpxGoOYXHB+cjkZxnEqS8MVFutvqrk6UsZGHrDXjxZ+9 5TSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708658305; x=1709263105; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Zyv4HE+62H12UhKwJANnJSL70xjGQPKa7udGRWyRwEU=; b=jE+hcXub7oRS9IKg9ckZolZ8YPLRFG/5t3BTzyl9Iy/gVkNgTpqv38agR53JmfTiJ6 ubz9TUaGj3eC/wcEbIf0mmCSnOKryPmYqJRrRlO6yYrYjgdO942274k7BEWwOZcT7BQm hz2JBDGcpAeeT+kzc0Y4lqVfUYGWssQAIZheSfoasFpT0sEB2mVfW0JBFvLyvswn1T2W HNESruTa0MA8QYaC5b7RW5YU6amfeqCQw29F2bCOcgCtM/Ye+cK5yfL2p7l2UDwNB5zN kAcoqUu+h5QNHbp4pRUGtGoQQ/Hb4JqdEyWJh2OKtAWgXYN2VBbIZ8v2RlSGOQdxoVFL mueA== X-Gm-Message-State: AOJu0Ywxm0m+BbHv7fGjd9JyKb/2AfDhK94gLhzVmbxAWycPiKHEFggr qbxNHdi/00M5lIIcGJamZLdD4PAxe330I+fQuAG9ynY9mVmrMnyFV2923e3S X-Google-Smtp-Source: AGHT+IFmMHnMSLWwLbjhn+y/EpV1Q8yDT9SDvyGbsyjLyE/cn1pcFSd1U7cL5xJZj9T0YGvbNy/QUw== X-Received: by 2002:a2e:9e85:0:b0:2d2:4703:1ac2 with SMTP id f5-20020a2e9e85000000b002d247031ac2mr490775ljk.32.1708658305582; Thu, 22 Feb 2024 19:18:25 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n12-20020a05600c294c00b004101f27737asm574716wmd.29.2024.02.22.19.18.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 19:18:25 -0800 (PST) Message-ID: In-Reply-To: References: Date: Fri, 23 Feb 2024 03:18:07 +0000 Subject: [PATCH v2 03/16] t7527: temporarily disable case-insensitive tests Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Patrick Steinhardt , Jeff Hostetler , Jeff Hostetler , Jeff Hostetler From: Jeff Hostetler From: Jeff Hostetler Add non-existent "SKIPME" prereq to the case-insensitive tests. The previous commit added test cases to demonstrate an error where FSMonitor can get confused on a case-insensitive file system when the on-disk spelling of a file or directory is wrong. Let's disable those tests before we incrementally teach Git to properly recognize and handle those types of problems (so that a bisect between here and the final commit in this patch series won't throw a false alarm). Signed-off-by: Jeff Hostetler --- t/t7527-builtin-fsmonitor.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/t7527-builtin-fsmonitor.sh b/t/t7527-builtin-fsmonitor.sh index 3d21295f789..4acb547819c 100755 --- a/t/t7527-builtin-fsmonitor.sh +++ b/t/t7527-builtin-fsmonitor.sh @@ -1051,7 +1051,7 @@ test_expect_success 'split-index and FSMonitor work well together' ' # # The setup is a little contrived. # -test_expect_success CASE_INSENSITIVE_FS 'fsmonitor subdir case wrong on disk' ' +test_expect_success SKIPME,CASE_INSENSITIVE_FS 'fsmonitor subdir case wrong on disk' ' test_when_finished "stop_daemon_delete_repo subdir_case_wrong" && git init subdir_case_wrong && @@ -1128,7 +1128,7 @@ test_expect_success CASE_INSENSITIVE_FS 'fsmonitor subdir case wrong on disk' ' ! grep -q " M dir1/dir2/dir3/file3" "$PWD/subdir_case_wrong.out" ' -test_expect_success CASE_INSENSITIVE_FS 'fsmonitor file case wrong on disk' ' +test_expect_success SKIPME,CASE_INSENSITIVE_FS 'fsmonitor file case wrong on disk' ' test_when_finished "stop_daemon_delete_repo file_case_wrong" && git init file_case_wrong && From patchwork Fri Feb 23 03:18:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Hostetler X-Patchwork-Id: 13568520 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 49C5AD29B for ; Fri, 23 Feb 2024 03:18:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708658311; cv=none; b=Ou6mU6Z+S+GcPcufO2UomZhSXpnes84KrGKE/N0Y3qxWfEknvtjU2tFCSSIKFxy0sWpKqyLmpfMxSA4sPL98haVRzZrN5jrCwkAeU4do74ERwaTob9YJ3dwoJPdfMA9K4ng1wCct96u8GomhplShCufzTJ6zma3Z3f4yzK3rlH4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708658311; c=relaxed/simple; bh=erNCQFjvIiC2NHLYEteWfRNdfyr0Xh9cfM3eyTbANwk=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=jh75wLTJbqmSUMmI/WGuyWWK92Jbey2IbobgTU/S2BNRNTtad8YoRruqGdLleFTcBRGnhlmicA8VyBk2m8m7xgmLYpbm+8L5otp7tKBSYdmNykNO4b5jGsq82t3prHEeJc0gNeJkAWbW8zNWZLd7uZH2GmjvdWK3oGWa7iGZmao= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=g6w47fHA; arc=none smtp.client-ip=209.85.128.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="g6w47fHA" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-41275855dc4so3212445e9.0 for ; Thu, 22 Feb 2024 19:18:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708658307; x=1709263107; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=sRBX0CPHr6Kn4VU7i/3jgm014tLL34H/9vHqAiywal4=; b=g6w47fHAmYB0+eNjfDV+ebRJx3iBnSM0lVMsiUu+CEJ2M+bW0jnjqFVe8LXa5YTxNC pR39sg6PfLFF59JVz1ZS5/4gLO6SsmdgvZPTt01umIdB9jTiVaicYyQFFZwImj4zKDR0 tV1oS0HMQ+22jjEHgpjSdZS805TDRFitVzOCb/ow5n3jxakQFnbrtdvenLtvq0Bs9Dtf vEvYx2rOz8hlm02AyZdHGBWOoyihV/9NQoDsECvYqf+b5OFJs3UMIif/6mbKnI1Y0mkI 6KDAwGPDKhrD8Ps/HHbhTR6E4HQkg18wuzjYjokjAUnWym6xjqw/enOn0QSdBlHTRTCr +2NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708658307; x=1709263107; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sRBX0CPHr6Kn4VU7i/3jgm014tLL34H/9vHqAiywal4=; b=iq+ofM0rMq6ls5ETrZgbHFebBvufuidFFbCbr/nnVEpIScOHjF5KZCTRHQlkPyt/cQ zGRS5o5H2ANuzSXMEg6Z2I7BIV/I6IdCmVjx3ovC/412dGvYzW5X4YyDK6Wtsb/Wjm06 NOl1wUCnaJDZwPTQ57m1OqQiataxjySizaP8GQ6WntfmREH/jUJz736Y5ysDNjpI9gW9 BRzahL3DRPDCI6xo5vYN1etYP65L7JVT/CRGfUI4c/wNIYRGxukLUhpqPClXavvxlWSX 2j5gcNhBGqCONtzGTL1D3EOsWJV1PC75H6M+Kgh2RyR6t6WL4H/iPzg5np2V4ZpVlGp5 gGcg== X-Gm-Message-State: AOJu0YxI/EzBf1uOd/u3qqV9MprzD0v5ZKQFmmXnYpaJKnz7wGEOruh9 Hznh6I6+rYEmgJB7tRznc2/ScimtNM8RUPsIcAJcSHUoP5k7WdWm08ndwuwR X-Google-Smtp-Source: AGHT+IFhmc+b4gewiHJmjL1dJtphxUigIZw4r93j5EOoi/mAgzc8Lm8a3WAcHC2RtqUGEe9H+cLl3A== X-Received: by 2002:a05:600c:4e0d:b0:412:901d:a844 with SMTP id b13-20020a05600c4e0d00b00412901da844mr332334wmq.37.1708658306800; Thu, 22 Feb 2024 19:18:26 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id g11-20020a05600c4ecb00b004124219a8c9sm585950wmq.32.2024.02.22.19.18.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 19:18:25 -0800 (PST) Message-ID: <5516670e30e26c5b50c67b69e48e3e8a5e0d8990.1708658300.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 23 Feb 2024 03:18:08 +0000 Subject: [PATCH v2 04/16] fsmonitor: refactor refresh callback on directory events Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Patrick Steinhardt , Jeff Hostetler , Jeff Hostetler , Jeff Hostetler From: Jeff Hostetler From: Jeff Hostetler Move the code to handle directory FSEvents (containing pathnames with a trailing slash) into a helper function. Signed-off-by: Jeff Hostetler --- fsmonitor.c | 52 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/fsmonitor.c b/fsmonitor.c index f670c509378..6fecae9aeb2 100644 --- a/fsmonitor.c +++ b/fsmonitor.c @@ -183,6 +183,35 @@ static int query_fsmonitor_hook(struct repository *r, return result; } +static void handle_path_with_trailing_slash( + struct index_state *istate, const char *name, int pos) +{ + int i; + + /* + * The daemon can decorate directory events, such as + * moves or renames, with a trailing slash if the OS + * FS Event contains sufficient information, such as + * MacOS. + * + * Use this to invalidate the entire cone under that + * directory. + * + * We do not expect an exact match because the index + * does not normally contain directory entries, so we + * start at the insertion point and scan. + */ + if (pos < 0) + pos = -pos - 1; + + /* Mark all entries for the folder invalid */ + for (i = pos; i < istate->cache_nr; i++) { + if (!starts_with(istate->cache[i]->name, name)) + break; + istate->cache[i]->ce_flags &= ~CE_FSMONITOR_VALID; + } +} + static void fsmonitor_refresh_callback(struct index_state *istate, char *name) { int i, len = strlen(name); @@ -193,28 +222,7 @@ static void fsmonitor_refresh_callback(struct index_state *istate, char *name) name, pos); if (name[len - 1] == '/') { - /* - * The daemon can decorate directory events, such as - * moves or renames, with a trailing slash if the OS - * FS Event contains sufficient information, such as - * MacOS. - * - * Use this to invalidate the entire cone under that - * directory. - * - * We do not expect an exact match because the index - * does not normally contain directory entries, so we - * start at the insertion point and scan. - */ - if (pos < 0) - pos = -pos - 1; - - /* Mark all entries for the folder invalid */ - for (i = pos; i < istate->cache_nr; i++) { - if (!starts_with(istate->cache[i]->name, name)) - break; - istate->cache[i]->ce_flags &= ~CE_FSMONITOR_VALID; - } + handle_path_with_trailing_slash(istate, name, pos); /* * We need to remove the traling "/" from the path From patchwork Fri Feb 23 03:18:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Hostetler X-Patchwork-Id: 13568519 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 64271D30B for ; Fri, 23 Feb 2024 03:18:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708658310; cv=none; b=WK/jBOI8m/z7QaOCer03sERFo/gLKsnxTcxMbyeoIjeABBA9NY8I4nRZFkUXGsDva6V4MJeQrtQGhbNCUqovYe48crKqmcc26Tr7f5APNhtMj9yJh3uDPMwfFdrQepMQmI4s0onRjEILOW4TtHYnjAFvk6A5KLiLh5rms1mw0s0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708658310; c=relaxed/simple; bh=yUFjxGXoa9Iu5ABIv8e5hSygDvEud2XumKI6i0VwrCo=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=uhyBGTNMJOddcSMtSRhaBBPx0bEg+Je6klzO3Yf9c9Xwfl9+dYTDA8PUoki3Xu7KHiB3CRJDEGWbHGEQVS60W/m6QmaWmxFMCZG4glHZePxGFhBRmHDJ7LLLQF/hPKTHhKidHnxQANHB1XdDW8z/lU4h8AxXSd90WJ/SzofUkHc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kFJgqlBM; arc=none smtp.client-ip=209.85.128.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kFJgqlBM" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-41282f05409so3100425e9.0 for ; Thu, 22 Feb 2024 19:18:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708658307; x=1709263107; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=tj66rkJA3Q9yHv6pTHD9ZT5In/BWmtsX624blZGveos=; b=kFJgqlBMQf0NI1bUoyLulPcFZJcjqaiy73W/cMF7AkEmo1fTA9FJ2JBRzRf4a+A1OP eb19Jh0T7JSdKrRReBvR65Fy0IMzwnNV2SJU8Y7r5B41H7fH7w0Sq0N7I5xdz3icXLSf PS5y8xYlXsaMjwgmYrmuZItloMUeQh4XD5MncWf7P+b2q9vGpAin2g1WFydVn1DfMQlT uIeuhbMmy3AEwXe89twuKo69F0rwUy/p1uWyoogH2TDivfhjd1h7k6n22ZwTVN0zb3TB JOUrBIns8S6hBvHSnsxa8d2HMf4QhbP3Pr7xnAjxkmXyATnULqymVb/zxnQEOEMbPCqC ceCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708658307; x=1709263107; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tj66rkJA3Q9yHv6pTHD9ZT5In/BWmtsX624blZGveos=; b=dNZEHW9fLvBVWdjevnRMa+qOi/+KsEey8Hcplxe5zniAFQxKu6JTrbjgpTw5hSMpvl UjFgtqh1KEZTFl9rqgyYHN8HckUgPF5w9bznPYr0uNgKWXmdH7hKR3szahlhC9HJVY70 qzGVCLFnlKeO95GYIKrC0NM9cKEmYpCrHrRRc/m4Fp4N8uUpXf2VNuflssXbSqt+KqZS GmHpQoqHvomkKPjWJRtBYNEWhaLfaobE6ju7nflT411O3S83flgOhbh5jYmDl+wV94b6 ArR+cLSTCp2oet9hNcmcGRTsbdpfSehZWe2phiTFe8ar1WVK60vxq6Gnd3TLBrC4Ddcd N+eA== X-Gm-Message-State: AOJu0Yz4pJwQ0BWoGw+Sb7lAOuZUcbeeggG0pdoJod5j/0HeDnBfrfU1 kGkOQoXoBr8LZbnoW8EdWFFHHKoSk+3TxcoZxOnZg9bDGJbp8Ukuoa2hh+fQ X-Google-Smtp-Source: AGHT+IHmxLlcdbopOE1Q5lT3YWrQz/yDq1/8WqbsEd4mKMk5hYzflfYsZmHhtVQWc3Xd39nrjbiOKQ== X-Received: by 2002:a05:600c:1f86:b0:412:9008:b252 with SMTP id je6-20020a05600c1f8600b004129008b252mr273440wmb.40.1708658307435; Thu, 22 Feb 2024 19:18:27 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id z18-20020a1c4c12000000b004120537210esm573743wmf.46.2024.02.22.19.18.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 19:18:27 -0800 (PST) Message-ID: In-Reply-To: References: Date: Fri, 23 Feb 2024 03:18:09 +0000 Subject: [PATCH v2 05/16] fsmonitor: clarify handling of directory events in callback helper Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Patrick Steinhardt , Jeff Hostetler , Jeff Hostetler , Jeff Hostetler From: Jeff Hostetler From: Jeff Hostetler Improve documentation of the refresh callback helper function used for directory FSEvents. Signed-off-by: Jeff Hostetler --- fsmonitor.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/fsmonitor.c b/fsmonitor.c index 6fecae9aeb2..29cce32d81c 100644 --- a/fsmonitor.c +++ b/fsmonitor.c @@ -183,24 +183,35 @@ static int query_fsmonitor_hook(struct repository *r, return result; } +/* + * The daemon can decorate directory events, such as a move or rename, + * by adding a trailing slash to the observed name. Use this to + * explicitly invalidate the entire cone under that directory. + * + * The daemon can only reliably do that if the OS FSEvent contains + * sufficient information in the event. + * + * macOS FSEvents have enough information. + * + * Other platforms may or may not be able to do it (and it might + * depend on the type of event (for example, a daemon could lstat() an + * observed pathname after a rename, but not after a delete)). + * + * If we find an exact match in the index for a path with a trailing + * slash, it means that we matched a sparse-index directory in a + * cone-mode sparse-checkout (since that's the only time we have + * directories in the index). We should never see this in practice + * (because sparse directories should not be present and therefore + * not generating FS events). Either way, we can treat them in the + * same way and just invalidate the cache-entry and the untracked + * cache (and in this case, the forward cache-entry scan won't find + * anything and it doesn't hurt to let it run). + */ static void handle_path_with_trailing_slash( struct index_state *istate, const char *name, int pos) { int i; - /* - * The daemon can decorate directory events, such as - * moves or renames, with a trailing slash if the OS - * FS Event contains sufficient information, such as - * MacOS. - * - * Use this to invalidate the entire cone under that - * directory. - * - * We do not expect an exact match because the index - * does not normally contain directory entries, so we - * start at the insertion point and scan. - */ if (pos < 0) pos = -pos - 1; From patchwork Fri Feb 23 03:18:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Hostetler X-Patchwork-Id: 13568521 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4064FFBFD for ; Fri, 23 Feb 2024 03:18:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708658312; cv=none; b=dIldS75M4y/PlMonhtqif1BsijLidWcDcysfhuE4gYggj5ogsWzbLf6Mvi6ROXdn7SXXIAe27JzOjInmL7cRGuLU0IabHFdMX1DldEjXAhwc+UvifpytLrOdPZcGmAa8waTX1Ieqody7p4v33Ci9TtnwItcYIsCYdGPTlcGM1cg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708658312; c=relaxed/simple; bh=4szOJUbnumzcLWgNk92lQAmCwY/gpNS2Mi6gpmHr3vQ=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=VDLsO02YmSnsdnzzg4HzdOGMB2nqqZNegnaNJw+JXoxLaJ+05rMA4rCc8g3nzi0m7XO2jd3T2kU19oZFmsGfuCNMAJWPwPbQruolRtJdx1qbMTd81SU/S2hxqILNndYkMCXpPVsndmka8+dcDvJ5GM42RYWXrPNai71UaaYdshM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=bSt4EFfx; arc=none smtp.client-ip=209.85.221.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bSt4EFfx" Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-33d568fbf62so208108f8f.3 for ; Thu, 22 Feb 2024 19:18:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708658308; x=1709263108; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=vQySpqc/GX+20PebOQNWz8bpck9mFzkDsq0Dr42tSAo=; b=bSt4EFfxwZj0SIxjF95cN/T1UQO8KQdHEDUsUQlKic+JGf9fncerPHOXVMX0ew+hRA lwO7vx5Tml4Yj9W/VMZYo6ZURCtmDUDILKMH43cw99Wft+sEbuQEfNUCn+ZsEPUyH2ee GccabCYnNjtzoLZLOCTthh/Vid0WtE1v+BAFAb4+fBLfsNWsXpYFc33bLCwwJUcLcSS9 abaQhzy0wptkxG37WN2LAXPRi2rtwTNGCpOny5XnM2QRg9w34bE11ByGS0lexZJvuOcj nLhemie94t6yG0r6jOURyY7Eei4+P3uuFlm3MQS1jb1AzPDW3n8iHi9D/9B+Xgv23R7o FTmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708658308; x=1709263108; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vQySpqc/GX+20PebOQNWz8bpck9mFzkDsq0Dr42tSAo=; b=InBQVouYlsHlWt9WN0h/7N0hfjUfOze3yV64suWIbQHWGXuf2xM8tOoqphq57IBEGM ubcJ6ec4Jhr1nSj/m9EuXkqFOr+HwYeGY0h8rml1EzTDLSmwntaRVFl2kxyIh3fw0njA bUwpEaCgjLQcw1ZE3nE2kPs6bC+GMAlyomjKexqYFdK4ne31JpXtJp39zSEiVBbmti0+ mpVRPAMvn4bZaRc8YhE8rVwyQJmo16TOyxZbzVAuocP8g3uS3T5/iDniBsLI5ETYI28i MvBuA1vF2+nFmvJ6pRmToMo1al1GzBGweJ7gWm/Ut4TqPJwBmcdS2/ODjnfLAjgNaKo+ Jgvw== X-Gm-Message-State: AOJu0Yz4SahV7NtvB+m39jDrFYp88QEJ/lzdAtKpFxeeI2owWabJTQ4b 03jWSgbJjQs1UZh+wyW3/KGPseCeE2Qil6DLqY7g/3Gcz/BbtEUvrn6hvVhZ X-Google-Smtp-Source: AGHT+IECnRj89tOxeoXvAi0p+w8VrCbR1Z6JW8LcOXTf9sIQgq0UpCmpYQutqPtxHjFuZkCsQuludg== X-Received: by 2002:adf:f551:0:b0:33d:3b82:ab2a with SMTP id j17-20020adff551000000b0033d3b82ab2amr514338wrp.19.1708658308358; Thu, 22 Feb 2024 19:18:28 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id b3-20020adfe643000000b0033cffd1a302sm1007295wrn.57.2024.02.22.19.18.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 19:18:27 -0800 (PST) Message-ID: <7ee6ca1aefd34a37d749300e317df10d80ef2b29.1708658300.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 23 Feb 2024 03:18:10 +0000 Subject: [PATCH v2 06/16] fsmonitor: refactor refresh callback for non-directory events Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Patrick Steinhardt , Jeff Hostetler , Jeff Hostetler , Jeff Hostetler From: Jeff Hostetler From: Jeff Hostetler Move the code handle unqualified FSEvents (without a trailing slash) into a helper function. Signed-off-by: Jeff Hostetler --- fsmonitor.c | 67 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 28 deletions(-) diff --git a/fsmonitor.c b/fsmonitor.c index 29cce32d81c..364198d258f 100644 --- a/fsmonitor.c +++ b/fsmonitor.c @@ -183,6 +183,43 @@ static int query_fsmonitor_hook(struct repository *r, return result; } +static void handle_path_without_trailing_slash( + struct index_state *istate, const char *name, int pos) +{ + int i; + + if (pos >= 0) { + /* + * We have an exact match for this path and can just + * invalidate it. + */ + istate->cache[pos]->ce_flags &= ~CE_FSMONITOR_VALID; + } else { + /* + * The path is not a tracked file -or- it is a + * directory event on a platform that cannot + * distinguish between file and directory events in + * the event handler, such as Windows. + * + * Scan as if it is a directory and invalidate the + * cone under it. (But remember to ignore items + * between "name" and "name/", such as "name-" and + * "name.". + */ + int len = strlen(name); + pos = -pos - 1; + + for (i = pos; i < istate->cache_nr; i++) { + if (!starts_with(istate->cache[i]->name, name)) + break; + if ((unsigned char)istate->cache[i]->name[len] > '/') + break; + if (istate->cache[i]->name[len] == '/') + istate->cache[i]->ce_flags &= ~CE_FSMONITOR_VALID; + } + } +} + /* * The daemon can decorate directory events, such as a move or rename, * by adding a trailing slash to the observed name. Use this to @@ -225,7 +262,7 @@ static void handle_path_with_trailing_slash( static void fsmonitor_refresh_callback(struct index_state *istate, char *name) { - int i, len = strlen(name); + int len = strlen(name); int pos = index_name_pos(istate, name, len); trace_printf_key(&trace_fsmonitor, @@ -240,34 +277,8 @@ static void fsmonitor_refresh_callback(struct index_state *istate, char *name) * for the untracked cache. */ name[len - 1] = '\0'; - } else if (pos >= 0) { - /* - * We have an exact match for this path and can just - * invalidate it. - */ - istate->cache[pos]->ce_flags &= ~CE_FSMONITOR_VALID; } else { - /* - * The path is not a tracked file -or- it is a - * directory event on a platform that cannot - * distinguish between file and directory events in - * the event handler, such as Windows. - * - * Scan as if it is a directory and invalidate the - * cone under it. (But remember to ignore items - * between "name" and "name/", such as "name-" and - * "name.". - */ - pos = -pos - 1; - - for (i = pos; i < istate->cache_nr; i++) { - if (!starts_with(istate->cache[i]->name, name)) - break; - if ((unsigned char)istate->cache[i]->name[len] > '/') - break; - if (istate->cache[i]->name[len] == '/') - istate->cache[i]->ce_flags &= ~CE_FSMONITOR_VALID; - } + handle_path_without_trailing_slash(istate, name, pos); } /* From patchwork Fri Feb 23 03:18:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Hostetler X-Patchwork-Id: 13568522 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 803D710A25 for ; Fri, 23 Feb 2024 03:18:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708658313; cv=none; b=mDJl0mwwzUyY5uU8bg69SaL48wA3WGz0ifxHuIvUP4g3j1Vq+YAw9XMmMMYXj2ZXWz2hczQwEbtUVo6gl62zTxsEDw9+jmxIiYBSzLzxQ6BL2Dwfp9Lgw2fNxLn0ztqS9DRS/QgyPYhIXtI12uDIgVsPlG9PyeY1xjBx8578EE8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708658313; c=relaxed/simple; bh=8XxRUSLP1i2H4pP7Ur/AnG+3Ro+HeevnzAIaMxKdsxo=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=nZlw7Fa95KPbSDvScf2kNW+3lBl6B9lcoDcgaNa/VxFDJQRct9AmpUO6anjYkhs0pUFlJP+nTurw0jD7qvmBR9m881ZKcUfxzxIvvIYjIyG5H03J/z9iyCmTrwv1uDLmgKtHRR0EA2yx8PEAfGNWfAsz30/OyIzNIG4BP7b/2m0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=YUQR4YnH; arc=none smtp.client-ip=209.85.128.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YUQR4YnH" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-412903facc9so2913615e9.1 for ; Thu, 22 Feb 2024 19:18:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708658309; x=1709263109; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=w4syVdYZ4bavYVFDZfPF7YqPDiBAXmbzeINYHl0d0os=; b=YUQR4YnHKm8xoHfxsv6IFPD6gip8MasQYM6cnPdHkCcFOs5+tnResO9epR5lYm64Wp POKR0gT2ZqznT0Q1b1DFhzCBm0Pv2hye/RQ7RCJswQ1JCqG+6gw3K239OFslxzqAMvWW EA5wboUtqhsju6nOVLsbUm5jjY/K+S/Zpqv26KjoFiiKcZviPqBvgW8rVftEgChYOwfU UQot0DjDmdYFBBDPDqIvFvRhTZ3R6dIqhvYMlINbjBFJORZ6zFv1jgukbWMZPpL+FnHY lEKEam+WUf3rFAN7anXXcMILMnFIFB780moBj55LiGXRV/vWy120Us9P5I0XBuG4WmAo FlrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708658309; x=1709263109; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=w4syVdYZ4bavYVFDZfPF7YqPDiBAXmbzeINYHl0d0os=; b=ilJKePIaBjhmRW/FQb2muzcZRobUW9FvJ5Hv9gIt/VXbue5hbLSRG2m62A/gTdQNhW +zoU1+sR5bvjyDigW5/cnMeRGUfbvpwpPD0TVXKMyuxw+KwNrF9skEyG+Z9gsiYf50wJ fgzV07C73yyN9hSPgUI/QQHBvbr5sv2s9ETxiK0O7MDmzFFpylSv9yXhhFsGa1B0pazI BiDRm8jfKUUZumZrbdwOg6uMN2FNJn30Zb+2gVaRhajgZi8haHR/bZcLKCWjlUDsQ0gz E9UpUkMhoBzuRPRAdHUA6Y8BWMS2WLe98zccVOkP8LKUlynymkjDhWDYkzN+Ze1Yr/1T 3zBw== X-Gm-Message-State: AOJu0Yw/XSuCfpu8JIXGNBTA/96AcFZs4ote+AXURKHICcRmyPSiPhaG GyXwv7U+tyZEJnJzUkJb9UB7EQAou78zUxSscZY/dMn+iAU4iMeBb3fjUWhK X-Google-Smtp-Source: AGHT+IFwXSGpzGz/pvC7frTv1/W7no/6rboejejnAP/EFBUFscuhyr6gQevqqEZTBfzBA9mCjl0Uqg== X-Received: by 2002:a05:600c:4fd2:b0:412:7880:3da8 with SMTP id o18-20020a05600c4fd200b0041278803da8mr408277wmq.16.1708658308983; Thu, 22 Feb 2024 19:18:28 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id u16-20020a05600c211000b004126732390asm574926wml.37.2024.02.22.19.18.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 19:18:28 -0800 (PST) Message-ID: <99c0d3e0742c1a7e0f7608707402a772ec112716.1708658300.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 23 Feb 2024 03:18:11 +0000 Subject: [PATCH v2 07/16] dir: create untracked_cache_invalidate_trimmed_path() Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Patrick Steinhardt , Jeff Hostetler , Jeff Hostetler , Jeff Hostetler From: Jeff Hostetler From: Jeff Hostetler Create a wrapper function for untracked_cache_invalidate_path() that silently trims a trailing slash, if present, before calling the wrapped function. The untracked cache expects to be called with a pathname that does not contain a trailing slash. This can make it inconvenient for callers that have a directory path. Lets hide this complexity. This will be used by a later commit in the FSMonitor code which may receive directory pathnames from an FSEvent. Signed-off-by: Jeff Hostetler --- dir.c | 20 ++++++++++++++++++++ dir.h | 7 +++++++ 2 files changed, 27 insertions(+) diff --git a/dir.c b/dir.c index ac699542302..1157f3e43fa 100644 --- a/dir.c +++ b/dir.c @@ -3918,6 +3918,26 @@ void untracked_cache_invalidate_path(struct index_state *istate, path, strlen(path)); } +void untracked_cache_invalidate_trimmed_path(struct index_state *istate, + const char *path, + int safe_path) +{ + size_t len = strlen(path); + + if (!len) + return; /* should not happen */ + + if (path[len - 1] != '/') { + untracked_cache_invalidate_path(istate, path, safe_path); + } else { + struct strbuf tmp = STRBUF_INIT; + + strbuf_add(&tmp, path, len - 1); + untracked_cache_invalidate_path(istate, tmp.buf, safe_path); + strbuf_release(&tmp); + } +} + void untracked_cache_remove_from_index(struct index_state *istate, const char *path) { diff --git a/dir.h b/dir.h index 98aa85fcc0e..45a7b9ec5f2 100644 --- a/dir.h +++ b/dir.h @@ -576,6 +576,13 @@ int cmp_dir_entry(const void *p1, const void *p2); int check_dir_entry_contains(const struct dir_entry *out, const struct dir_entry *in); void untracked_cache_invalidate_path(struct index_state *, const char *, int safe_path); +/* + * Invalidate the untracked-cache for this path, but first strip + * off a trailing slash, if present. + */ +void untracked_cache_invalidate_trimmed_path(struct index_state *, + const char *path, + int safe_path); void untracked_cache_remove_from_index(struct index_state *, const char *); void untracked_cache_add_to_index(struct index_state *, const char *); From patchwork Fri Feb 23 03:18:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Hostetler X-Patchwork-Id: 13568523 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D8A6310A3B for ; Fri, 23 Feb 2024 03:18:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708658313; cv=none; b=YEbQuajNyAp8sFuzB0cKUdKO9HKew9/dDLqXVZpyYr4aNUgklpSNNp16n7KwfoDludwoRPdhnnMf8b/zBKbS4Hxf5akCNKcYO02n5HmFbj+I9jr88dUHA4c7JNWn5K3Bb0wtj+WS8nU9B9HWWY3AzhqwOGWbgxivrRGVIflyrJc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708658313; c=relaxed/simple; bh=DnjbJn5SgHmuTQJljNZYrS5EkVANHvKGjY/CNPBUE9A=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=DIfmH5Uj90j8811cnXys/1dIUqAPErA+T5dhArAJal2zxmgdTWx5evv1uqPo/7A/FnRzHXed4I5/qqJ+rbgfaSQSTjMJzl9Gx1/NXe/ZWmsuP0O7ziiVU5TKdr+MRhOhCXe7rdIQkxzAS+oMSU4wuP0ae/FzYcoImViOHEiP+es= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kc0UiMAN; arc=none smtp.client-ip=209.85.128.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kc0UiMAN" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-412748b183aso3021625e9.1 for ; Thu, 22 Feb 2024 19:18:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708658309; x=1709263109; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=fi0NPEODrtkk3ddoQg9K0JweYxe+PjhAUviQ4zCBQzw=; b=kc0UiMANtPDcCqRSQaR5Xl++vblhOIVyYJhv7TKptycqOAU0/QGqn2vVwTlK4oCizt k+omUdUPMknOUYw26+30w4wzj5zFPdlLf94UJCjWvWd27VdNiegipk4wwFZRqsvxwyJW 5NUUrkdw8Ri/thL8fGW9TPbjMHOxIXfIYDLJVGGAJIoBMFUsadubzVAuD0qgybBbSBPV GGQ+5dqKJRdFNjxOthgrszFLXuaXvD6cezg4YJA3lrJ+q/9lfMoqQcSwfrXn+J927RU8 RU/ZjdM/A28XEiX+ByamMZv/0nwgMKnaYjkuAAgrT7pqKWomSJq1Pk5vYmBkla3z/Jrq Xh3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708658309; x=1709263109; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fi0NPEODrtkk3ddoQg9K0JweYxe+PjhAUviQ4zCBQzw=; b=oK/rdVN0lKLUbpGbdswwpo8E26yHN++nqlEMOFzwRn8b5UoeQa3QuABSNe0OkiYTqi nJssHlCAMls0c6K/gZQ8D1pFTuS2k1N5F0dOz8nskOSZVrcO1fHqMUs33hfkVUyqDOGJ Qmiv5UYhFuP1iOG1l2UmT0YXeUoyfKbte00wWXeDQT+VHOi3BReCu3KkG8HeY6vBxOWk pw7OwEiAko+coRlqhZcMO8B/Hkk5VdDUsLUgd3PAsQbK4x2AQfpuF8FR3g5O4S5GFo1t 1C2p77aV7yZ2Ccyri98CUV5TQMDvaaOtHVhLETn2ZzA5EFGnQ/DaSKKO+h9Rc9o0rGUF r2lg== X-Gm-Message-State: AOJu0YzyRBADRRGtBcFqFyDjAcGC23Qc/l81XtGMsrtwM5AVo28pEYBx 9qldn4lq9X7o+WZCwjQK0Yd+dTR6emT+Bl9dGY49XHrnyC0C9XPC0+2hsQ+T X-Google-Smtp-Source: AGHT+IGTyZ4HiSeB3R6qFn63LRoQ+93By3e4jdF9F4d9wcEmkuw8aA8nD64B1l2y/VlCE/sa9Q5n+w== X-Received: by 2002:a05:600c:190e:b0:412:5e41:6f35 with SMTP id j14-20020a05600c190e00b004125e416f35mr264729wmq.10.1708658309677; Thu, 22 Feb 2024 19:18:29 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 26-20020a05600c029a00b004128e903b2csm571359wmk.39.2024.02.22.19.18.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 19:18:29 -0800 (PST) Message-ID: In-Reply-To: References: Date: Fri, 23 Feb 2024 03:18:12 +0000 Subject: [PATCH v2 08/16] fsmonitor: refactor untracked-cache invalidation Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Patrick Steinhardt , Jeff Hostetler , Jeff Hostetler , Jeff Hostetler From: Jeff Hostetler From: Jeff Hostetler Update fsmonitor_refresh_callback() to use the new untracked_cache_invalidate_trimmed_path() to invalidate the cache using the observed pathname without needing to modify the caller's buffer. Previously, we modified the caller's buffer when the observed pathname contained a trailing slash (and did not restore it). This wasn't a problem for the single use-case caller, but felt dirty nontheless. In a later commit we will want to invalidate case-corrected versions of the pathname (using possibly borrowed pathnames from the name-hash or dir-name-hash) and we may not want to keep the tradition of altering the passed-in pathname. Signed-off-by: Jeff Hostetler --- fsmonitor.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/fsmonitor.c b/fsmonitor.c index 364198d258f..2787f7ca5d1 100644 --- a/fsmonitor.c +++ b/fsmonitor.c @@ -271,21 +271,16 @@ static void fsmonitor_refresh_callback(struct index_state *istate, char *name) if (name[len - 1] == '/') { handle_path_with_trailing_slash(istate, name, pos); - - /* - * We need to remove the traling "/" from the path - * for the untracked cache. - */ - name[len - 1] = '\0'; } else { handle_path_without_trailing_slash(istate, name, pos); } /* * Mark the untracked cache dirty even if it wasn't found in the index - * as it could be a new untracked file. + * as it could be a new untracked file. (Let the untracked cache + * layer silently deal with any trailing slash.) */ - untracked_cache_invalidate_path(istate, name, 0); + untracked_cache_invalidate_trimmed_path(istate, name, 0); } /* From patchwork Fri Feb 23 03:18:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Hostetler X-Patchwork-Id: 13568524 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1F896111B6 for ; Fri, 23 Feb 2024 03:18:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708658314; cv=none; b=NM4lqHkUkwmDwziW0HkVBkG30qhqIKmFpmc6iHTGrZteOesgR0ywUK107lM7vO2DLuDn60nMEv8JMGmPLLuaU97Zq7unVAzofF9BvwKAU60sJRxNxlrQge9RfwXT5/3TU7yAzxqO0nNFjhPOO07qr5bx3u535nK+dNkRJVotwHM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708658314; c=relaxed/simple; bh=sUlvd8QxFgxP6Yjnn7Jtk/vpZchrcbfCg8YI4jN7Yk0=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=rGUI+cEcSR6scl917J0+S2u/K8zgZ3msnMEG8nj0ZmRrxmS/h9UoSe0qhS94P2lQS2swUQ95ZTfrlzfuy6qLoqu5jghPHIuFI2mGc2uYCAA4JuJKFqM66lCOZBgRU7YXRw1SC1bhgDoV/ZoOvKOsMLgImkN+LiIDkwcrVk1i2Mg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=llnCwke2; arc=none smtp.client-ip=209.85.128.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="llnCwke2" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-412949fd224so229185e9.1 for ; Thu, 22 Feb 2024 19:18:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708658311; x=1709263111; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=G4Jcgvy7Olro7z6RpSrzXJuYbzSeAvtk6dx39T9KAYI=; b=llnCwke2wkmemHoPWYbwruv29jMNckyt0I7PS9yFm+JxT1twgllFRapMBh4V+KmhWB XRBwXp8LlTD0uH2p+oR1hWmNnXAso2kjQTvFVs5m8zYIJdY8i7HYFTnGFoDXpXc/4lf/ iy41EHjOYMVcu5zMMNtmuOpj+9Y4VAseP8ZZG/gCxvwOtAa9encGOTyr5azWuXKsbdEI Mvx96Z1MeKTp6gm0t1HAN8GNGFndEbud8q8RFoJoaqPl362yaNiG3FcOblzXcqw6vob6 qlxuEe9XGgTvawY4MiaLdioizIyWTpEfmyf/YzSum+2QKbUP9Zk6LOgkohMXAJSc3Wxa JQlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708658311; x=1709263111; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=G4Jcgvy7Olro7z6RpSrzXJuYbzSeAvtk6dx39T9KAYI=; b=FNMVyHmkPyztwzKBMLsMIWvkMQg1M8mq9zE34DxxBP3aH1IYBey62XfpAWAAADC1gq MfZG63isheQ5yBtnGEKYUFG1mBly23HqMzFzMd/myQ8W6B2XnHdq3vhzI3SaIe9wPMbd U9HZ+zs2wIICdgPL/OF2jp6vnHTaTOhStG2bPg+mm3lylVc+sHJ/a9Efoyc92JgtPQqf 66hbtT/DjqvLQSBKmeEQM6dBLI5mhcvJNuEEXlGnRXePzDMA3kSxHAeYH+XFfp+/vcOZ yK+aHz6miNDlQm3M0KL5xeIa3b/46G+HrmvJRT6vZXs60mQKm1zuInQOQ3Csmp8H1oA2 WNWw== X-Gm-Message-State: AOJu0YwUFtHl4sFt8I8h8dcCqqIlyyyLMnBRKgkQzSTrkt1zbo/+k3so dA+3HkQPjIzhxdDNS52giH9gmglBc0qAe/JIS67xRUMIIfd7ncN3GUBInQTE X-Google-Smtp-Source: AGHT+IFZcBhxLw7rsmaefai+b33hye6wnP3BxeQ4aplJqvFfYc9tmcABIxdzIEhWI5gom2Pl3SGkUQ== X-Received: by 2002:a05:600c:46c9:b0:412:8cc3:bf67 with SMTP id q9-20020a05600c46c900b004128cc3bf67mr2888024wmo.8.1708658310849; Thu, 22 Feb 2024 19:18:30 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id h16-20020a05600c351000b0041294d015fbsm184377wmq.40.2024.02.22.19.18.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 19:18:30 -0800 (PST) Message-ID: In-Reply-To: References: Date: Fri, 23 Feb 2024 03:18:13 +0000 Subject: [PATCH v2 09/16] fsmonitor: move untracked invalidation into helper functions Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Patrick Steinhardt , Jeff Hostetler , Jeff Hostetler , Jeff Hostetler From: Jeff Hostetler From: Jeff Hostetler Move the call to invalidate the untracked cache for the FSEvent pathname into the two helper functions. In a later commit in this series, we will call these helpers from other contexts and it safer to include the UC invalidation in the helper than to remember to also add it to each helper call-site. Signed-off-by: Jeff Hostetler --- fsmonitor.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/fsmonitor.c b/fsmonitor.c index 2787f7ca5d1..2f58ee2fe5a 100644 --- a/fsmonitor.c +++ b/fsmonitor.c @@ -188,6 +188,16 @@ static void handle_path_without_trailing_slash( { int i; + /* + * Mark the untracked cache dirty for this path (regardless of + * whether or not we find an exact match for it in the index). + * Since the path is unqualified (no trailing slash hint in the + * FSEvent), it may refer to a file or directory. So we should + * not assume one or the other and should always let the untracked + * cache decide what needs to invalidated. + */ + untracked_cache_invalidate_trimmed_path(istate, name, 0); + if (pos >= 0) { /* * We have an exact match for this path and can just @@ -249,6 +259,15 @@ static void handle_path_with_trailing_slash( { int i; + /* + * Mark the untracked cache dirty for this directory path + * (regardless of whether or not we find an exact match for it + * in the index or find it to be proper prefix of one or more + * files in the index), since the FSEvent is hinting that + * there may be changes on or within the directory. + */ + untracked_cache_invalidate_trimmed_path(istate, name, 0); + if (pos < 0) pos = -pos - 1; @@ -274,13 +293,6 @@ static void fsmonitor_refresh_callback(struct index_state *istate, char *name) } else { handle_path_without_trailing_slash(istate, name, pos); } - - /* - * Mark the untracked cache dirty even if it wasn't found in the index - * as it could be a new untracked file. (Let the untracked cache - * layer silently deal with any trailing slash.) - */ - untracked_cache_invalidate_trimmed_path(istate, name, 0); } /* From patchwork Fri Feb 23 03:18:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Hostetler X-Patchwork-Id: 13568525 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B76AE1170A for ; Fri, 23 Feb 2024 03:18:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708658315; cv=none; b=IiWzlV9NzBsEN8glKwRupAqO+3iUtDuyJCUfr2eT/HTF10t3Cz1bAmdtiyGW0YWhfx2SY2halJ2yVCkHI9V6jGZLrFvzAZGYUAvgJ3fNqNOo1gswzIL9gqz5vs5ctwNlU5w1dsgvqMxrM3dw2BFMiAEDJFX3M6Sl/jsZHnreO7U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708658315; c=relaxed/simple; bh=FO2b0yim3Nlg5M5KqxmDX/ArS0hbUoaoFBZF9hZLt/8=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=jZB+IUjyTPmOasVBuo1HXqiCYL1QdtGDkIv4VOW3ftlELxoxvk8zjGNk5Ih/UtR+HnxssV8fo0dP+9TdDyTcHrEA65RDhy3ap0ZbaDyVEMeyBhMdks9YbE1/Z9eHY6oP2DfzcUu2xVZHVWb8KqZPuyQR7fjlRsQwlmI8PH08QkM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Dgx4wWgF; arc=none smtp.client-ip=209.85.128.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Dgx4wWgF" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-412698ac6f9so9262125e9.0 for ; Thu, 22 Feb 2024 19:18:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708658312; x=1709263112; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=p28naUfyzbNrl0Bq490tpwa3bMingF0uwBZIP3yLO8E=; b=Dgx4wWgF7BejsW7hMwU9A0MN/jAdSS5cKpRycLImBnsbfEcNUzgJ+YWnMCHcKiKJUn PD0kjiIZxcGcswWyMSBy/Ye/DSiDG43aD/6OPH2DCNEl4mwJPapCVDO5qp/CEzOkDRj7 lqzXxfZtV40Iqf5tJHzjvWGx5cexwweMFw29VKMBoc3QTfC6aCptg2dgM62H77sjjZih fZDHoh9y03H23XEokauyN3NHOFwbCPncqAyvEz04JAyAPMQkfgqjHHg3x3+YA80gSzvq ZY3n8z1vU/m32DQu+TMuD0kLLa3yHY0sG0td15Se8egRYoCAhECFljWC+VEK1CzQx9Cv bdfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708658312; x=1709263112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=p28naUfyzbNrl0Bq490tpwa3bMingF0uwBZIP3yLO8E=; b=rpEh8z6kl4ZMBQoQDnklPbu2wO2xbWtV9lh+AviVAGU4BOmBB/sNnp0HGzHQTRB+sU W5URtGk/A1FC6YfaIFxQkM7oVtmSjKB8sm6xShqwUmqEsrAsj7l8Urn0hdwTmLn01+xn 6MmRnUtEQTiOrTB7ae+SnXxwGnzdpUGP5tFRBFDfcG46/jjRU3ytTGMBQjv+sKbtYwTq ZcnN+vkDQUKlFOW8KAb0WDld+b+oo12BZzQO62lkilb1uw211QwKxqjlWpg84V/pb7+g VKYH87YAwjIzi/JMOtLOoCMOpGlocjb9AU4P8t3KAtQEfAE0KVSzhlZDh8El3crxtxPt uU6Q== X-Gm-Message-State: AOJu0YyI+GUrP/u8Y70LqxgdkMHfvTc5B1KW74l6HfBg0l5XktqtgNu8 XfYUiMgd0UgSo6MpnKGBcAeQYNZlnKaUHar8evIuV1V90UWdldaf8zrc7Ry9 X-Google-Smtp-Source: AGHT+IHD0XPrvJsa6XzU5Ruj1d/5DKZ5apfuS8o4pOxfxvv2kaNc8aKOnTm1wMUoVWdtwxHp11c4uA== X-Received: by 2002:a05:600c:4706:b0:412:5652:138f with SMTP id v6-20020a05600c470600b004125652138fmr569305wmo.16.1708658311970; Thu, 22 Feb 2024 19:18:31 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id z18-20020a1c4c12000000b004120537210esm573903wmf.46.2024.02.22.19.18.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 19:18:31 -0800 (PST) Message-ID: <623c6f06e21c04c55576d1146944b5ff6be66429.1708658300.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 23 Feb 2024 03:18:14 +0000 Subject: [PATCH v2 10/16] fsmonitor: return invalidated cache-entry count on directory event Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Patrick Steinhardt , Jeff Hostetler , Jeff Hostetler , Jeff Hostetler From: Jeff Hostetler From: Jeff Hostetler Teach the refresh callback helper function for directory FSEvents to return the number of cache-entries that were invalidated in response to a directory event. This will be used in a later commit to help determine if the observed pathname in the FSEvent was a (possibly) case-incorrect directory prefix (on a case-insensitive filesystem) of one or more actual cache-entries. If there exists at least one case-insensitive prefix match, then we can assume that the directory is a (case-incorrect) prefix of at least one tracked item rather than a completely unknown/untracked file or directory. Signed-off-by: Jeff Hostetler --- fsmonitor.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/fsmonitor.c b/fsmonitor.c index 2f58ee2fe5a..9424bd17230 100644 --- a/fsmonitor.c +++ b/fsmonitor.c @@ -253,11 +253,20 @@ static void handle_path_without_trailing_slash( * same way and just invalidate the cache-entry and the untracked * cache (and in this case, the forward cache-entry scan won't find * anything and it doesn't hurt to let it run). + * + * Return the number of cache-entries that we invalidated. We will + * use this later to determine if we need to attempt a second + * case-insensitive search on case-insensitive file systems. That is, + * if the search using the observed-case in the FSEvent yields any + * results, we assume the prefix is case-correct. If there are no + * matches, we still don't know if the observed path is simply + * untracked or case-incorrect. */ -static void handle_path_with_trailing_slash( +static size_t handle_path_with_trailing_slash( struct index_state *istate, const char *name, int pos) { int i; + size_t nr_in_cone = 0; /* * Mark the untracked cache dirty for this directory path @@ -276,7 +285,10 @@ static void handle_path_with_trailing_slash( if (!starts_with(istate->cache[i]->name, name)) break; istate->cache[i]->ce_flags &= ~CE_FSMONITOR_VALID; + nr_in_cone++; } + + return nr_in_cone; } static void fsmonitor_refresh_callback(struct index_state *istate, char *name) From patchwork Fri Feb 23 03:18:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Hostetler X-Patchwork-Id: 13568526 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A6EFD11C89 for ; Fri, 23 Feb 2024 03:18:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708658316; cv=none; b=Eev46iOfILjmanQSe98p/2hdNrXg+3Nyh3sZrfMpy4R6lPd25RgsRv+RMzOPxEwgHe4/AK3DueJF4o9m5KCdlC9ruaAV+Jj4cXj56MkDcyGFaB1ieVaItVWTTTAc+PjnxvXT/Go9JfX07T/ohSuNY10QjjvhG6MLZteIT0bZbkI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708658316; c=relaxed/simple; bh=+RJFxPxyhNAoSRYSOr0W3UbtUKn46L4I2/i53cfAsK8=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=aR3xtdRee/5T+f9koe6+IC0J8Gw7E0dww1hSpPMqi12oUH/I2pTlYd1lH9ioIGxaJ/mC2DmcGXTzCYjqd9XqckU+ZvDE26Q+zQbvxJegAmQPos71LGhpEp1dUpc1n+9M8ZfQUlRFJejWTCNO6eDBiuO89RQy+l4HWr/VTpsv89I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=dna8jsTm; arc=none smtp.client-ip=209.85.128.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dna8jsTm" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-412949fd224so229295e9.1 for ; Thu, 22 Feb 2024 19:18:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708658312; x=1709263112; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=fqstBc0E6ZD2vwPCXf6WhhzYXHYFVGnSD4Cm9vEbGNo=; b=dna8jsTmCW9mmyAqOkhWZmgZHg3t4QFpFaUhwES1cqd8VEwfJzUKPpBxHviEp1UnfD PAU0EgiEJSuib7SX7ZBkqBLl4vTjw9WuEdsPqDQDaNLQD5Pg3ZmlgHr8DmectZUsZRLo hOEp3BbKIdS4Aw3ROJZ0dx7Y6vdAPDkBwhItCed9k05xyEOyKCuzHE9pXak2ULLZiDQi 2L9vfNfsBij1QZrb8PfcFv4OW319QkDHwirOfz+FgBIqFswRZfUPxk1NhnJ/J51RmHa/ 9zdtIRhT5rU+OKz9ONJtK7AaLGi/GjCFJtY2fZULfdDu2GgCXGoKTGx0vo3S9qJ6IXxa Vz0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708658312; x=1709263112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fqstBc0E6ZD2vwPCXf6WhhzYXHYFVGnSD4Cm9vEbGNo=; b=gshrK8WKNEUO5kf9ckFX3C19bIpNjURlya8vhb9qoxjzrC99LQEdIT7021iP99vaD0 SJcDrvvayB6WgieXPV/Rsyy++QnjK82EkADrxZ96fYEv8oooTKXnrnUwKkZa/FMndgsA x0aJoO+fqIUa/Q0S+AbwDs1eGAWF+pZNb3S/5JX9ORBYFolWUFA5gFWgOeQh7nsH4MKT 2byV8myqhPeNkRI6kbwjFlYv3sAUJe5BMFa0KnxxZoZuXENDp10Qpj3TwFTNdY+2c45J hE1Ke/Rd8JIrguTEA6Qx+jAVT7rC7SlX/6yjLFA0lnHLev+YZ2xfGd3A2FIY8+DBjHLa N8Ug== X-Gm-Message-State: AOJu0YwzRlNYElxil393YKjH1yw6oJAO8OlI8nv4TExtoUWm0DGUlfH1 ecfUDRFdI0Qr16xBOx9smCbUx1bl6YMtHc9yYjiBve5inBK2wMClxcpFIk8+ X-Google-Smtp-Source: AGHT+IF5c7Ic+92jBdMsgnPl0xRxPXML4pvPbZyK6YDF1VXEyAOQsszWa5Zc3E89ApuW9uyyETyQSw== X-Received: by 2002:a05:600c:a3a4:b0:412:8cfb:745c with SMTP id hn36-20020a05600ca3a400b004128cfb745cmr626031wmb.6.1708658312639; Thu, 22 Feb 2024 19:18:32 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id k33-20020a05600c1ca100b00411d0b58056sm593600wms.5.2024.02.22.19.18.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 19:18:32 -0800 (PST) Message-ID: <1853f77d3331f7736139f686ac2efee6d68f9207.1708658300.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 23 Feb 2024 03:18:15 +0000 Subject: [PATCH v2 11/16] fsmonitor: remove custom loop from non-directory path handler Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Patrick Steinhardt , Jeff Hostetler , Jeff Hostetler , Jeff Hostetler From: Jeff Hostetler From: Jeff Hostetler Refactor the code that handles refresh events for pathnames that do not contain a trailing slash. Instead of using a custom loop to try to scan the index and detect if the FSEvent named a file or might be a directory prefix, use the recently created helper function to do that. Also update the comments to describe what and why we are doing this. On platforms that DO NOT annotate FS events with a trailing slash, if we fail to find an exact match for the pathname in the index, we do not know if the pathname represents a directory or simply an untracked file. Pretend that the pathname is a directory and try again before assuming it is an untracked file. Signed-off-by: Jeff Hostetler --- fsmonitor.c | 55 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/fsmonitor.c b/fsmonitor.c index 9424bd17230..a51c17cda70 100644 --- a/fsmonitor.c +++ b/fsmonitor.c @@ -183,11 +183,23 @@ static int query_fsmonitor_hook(struct repository *r, return result; } +static size_t handle_path_with_trailing_slash( + struct index_state *istate, const char *name, int pos); + +/* + * The daemon sent an observed pathname without a trailing slash. + * (This is the normal case.) We do not know if it is a tracked or + * untracked file, a sparse-directory, or a populated directory (on a + * platform such as Windows where FSEvents are not qualified). + * + * The pathname contains the observed case reported by the FS. We + * do not know it is case-correct or -incorrect. + * + * Assume it is case-correct and try an exact match. + */ static void handle_path_without_trailing_slash( struct index_state *istate, const char *name, int pos) { - int i; - /* * Mark the untracked cache dirty for this path (regardless of * whether or not we find an exact match for it in the index). @@ -200,33 +212,28 @@ static void handle_path_without_trailing_slash( if (pos >= 0) { /* - * We have an exact match for this path and can just - * invalidate it. + * An exact match on a tracked file. We assume that we + * do not need to scan forward for a sparse-directory + * cache-entry with the same pathname, nor for a cone + * at that directory. (That is, assume no D/F conflicts.) */ istate->cache[pos]->ce_flags &= ~CE_FSMONITOR_VALID; } else { + struct strbuf work_path = STRBUF_INIT; + /* - * The path is not a tracked file -or- it is a - * directory event on a platform that cannot - * distinguish between file and directory events in - * the event handler, such as Windows. - * - * Scan as if it is a directory and invalidate the - * cone under it. (But remember to ignore items - * between "name" and "name/", such as "name-" and - * "name.". + * The negative "pos" gives us the suggested insertion + * point for the pathname (without the trailing slash). + * We need to see if there is a directory with that + * prefix, but there can be lots of pathnames between + * "foo" and "foo/" like "foo-" or "foo-bar", so we + * don't want to do our own scan. */ - int len = strlen(name); - pos = -pos - 1; - - for (i = pos; i < istate->cache_nr; i++) { - if (!starts_with(istate->cache[i]->name, name)) - break; - if ((unsigned char)istate->cache[i]->name[len] > '/') - break; - if (istate->cache[i]->name[len] == '/') - istate->cache[i]->ce_flags &= ~CE_FSMONITOR_VALID; - } + strbuf_add(&work_path, name, strlen(name)); + strbuf_addch(&work_path, '/'); + pos = index_name_pos(istate, work_path.buf, work_path.len); + handle_path_with_trailing_slash(istate, work_path.buf, pos); + strbuf_release(&work_path); } } From patchwork Fri Feb 23 03:18:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Hostetler X-Patchwork-Id: 13568528 Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6A731125BB for ; Fri, 23 Feb 2024 03:18:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708658319; cv=none; b=RSO4w84ellHVzjSFEvPIt/SeBF6yL28rAl7tHUcWsMVuWRpcpVZHpo4g/J/AhIuMDUIYt7RrAJocgfGaa57jqHQd2T07XQSc8YdKaR7ku4rpKu38PIPkIUHX/PqWHSwvkFYDLevwomkn9HRb4hRA49IytTDfipabzGOGHF/ZlRc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708658319; c=relaxed/simple; bh=wenlDgWd6xp5kLI74cnxWSVlMSL4epGy890Z23C+Vfw=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=ZKGJpZlHvjsc3y2xwkA417+Uva04mlAzJYE1CaxMOVAijFtdP4RUde9muuJpXDAcM6WCq+UDu7L92VIGoW35E95cQUeFR8tTpSTMzBthUatmGy6p5cC3GGM1yTULTltVrUk6TPr76Z6SsGCbGUaP0F8AfF2qcTeW+6WllyYXh8w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Y2FtFMzA; arc=none smtp.client-ip=209.85.208.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Y2FtFMzA" Received: by mail-lj1-f169.google.com with SMTP id 38308e7fff4ca-2d0a4e1789cso5499581fa.3 for ; Thu, 22 Feb 2024 19:18:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708658314; x=1709263114; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=v4vxl+e4kjsc1pnVlVusgP+oJtIwbeNpM+m4Xm3V/q4=; b=Y2FtFMzAGT+gv7yP3/kWhznA9uC9Z/p9FRKyG/7G6X1uq7L6JoQ7wSYvMJv5zdIBYx HnfsaHbcGNxdzZfpfd/daxFAb1TWcCsU5rIlMMK/EABp6dImF2nFeXHr+2qfc8Xi09VJ fJnpDRr5m7Ew28VJ0xo4WBFUNmAhUIbbo54QQrSzsoOHIFSKtUIZBKft8cdQvuy82QQf Y92FklfnQ7Twcuyk0neOilBBSDHP4quVNd22OaQpuVpwanClrpgWFnHblyKuL1t3UTHP Wv48ZbAkTed97MKTlN4JCbehOjuvP4o1EQQJGmyxBvUm0xCnknZFJdpvQmOnok9iwp2E wHPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708658314; x=1709263114; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=v4vxl+e4kjsc1pnVlVusgP+oJtIwbeNpM+m4Xm3V/q4=; b=Il/uDcMHIdOikrQDHs4hW8tXVM6pBpqbNvlQ6YqExJYcdPegO7cc7qCApx1fQo6RQ+ Tdax2ClEy7iD5a0TO4HLP2iq3yDw+5hX6QvareUiyOND47CR4BcoJLGFB7wASdJect5U frxaB8vo6X1Qqkk6CeW3vRkxLwqdPogjhv+M97E0de8V/VvHvPXaGW0RiIKR0V8mGFtF PJ43cjFrSvbKKBq2gfx9L5+lbzkuh2AiLj8Ek0z+iX0g1nZzMXCUaOEEdumivKFUK3v/ qGAlbmpDTT7oIpwhS/iX8/5hBmji2W63iw3VrDW3Oo5b3wXpwvMmjWomaj5rhaJKMXDl rULQ== X-Gm-Message-State: AOJu0Yz6uQd8U8rEGKH3PMx5JY226g1a7bgekxhBVaKhxZW7k0blw+3r mHNtrYjg1x6BZ15Vd+GE3NRi+ZoPEsv62Fh8bIsJIlcqwwHCx00wfmHXTGnx X-Google-Smtp-Source: AGHT+IF4tmrYQnPmS0OTre6Cs7KFIO3M6p4nYz5tLQ1YnZBGkLgqnTz2tgBheDNIDVpgZ8IxbRl5Qg== X-Received: by 2002:a05:651c:1547:b0:2d2:2c31:3370 with SMTP id y7-20020a05651c154700b002d22c313370mr588980ljp.1.1708658313861; Thu, 22 Feb 2024 19:18:33 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id y2-20020a05600c20c200b004126a6ee498sm580657wmm.12.2024.02.22.19.18.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 19:18:33 -0800 (PST) Message-ID: In-Reply-To: References: Date: Fri, 23 Feb 2024 03:18:16 +0000 Subject: [PATCH v2 12/16] fsmonitor: return invalided cache-entry count on non-directory event Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Patrick Steinhardt , Jeff Hostetler , Jeff Hostetler , Jeff Hostetler From: Jeff Hostetler From: Jeff Hostetler Teah the refresh callback helper function for unqualified FSEvents (pathnames without a trailing slash) to return the number of cache-entries that were invalided in response to the event. This will be used in a later commit to help determine if the observed pathname was (possibly) case-incorrect when (on a case-insensitive file system). Signed-off-by: Jeff Hostetler --- fsmonitor.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/fsmonitor.c b/fsmonitor.c index a51c17cda70..c16ed5d8758 100644 --- a/fsmonitor.c +++ b/fsmonitor.c @@ -196,8 +196,10 @@ static size_t handle_path_with_trailing_slash( * do not know it is case-correct or -incorrect. * * Assume it is case-correct and try an exact match. + * + * Return the number of cache-entries that we invalidated. */ -static void handle_path_without_trailing_slash( +static size_t handle_path_without_trailing_slash( struct index_state *istate, const char *name, int pos) { /* @@ -218,7 +220,9 @@ static void handle_path_without_trailing_slash( * at that directory. (That is, assume no D/F conflicts.) */ istate->cache[pos]->ce_flags &= ~CE_FSMONITOR_VALID; + return 1; } else { + size_t nr_in_cone; struct strbuf work_path = STRBUF_INIT; /* @@ -232,8 +236,10 @@ static void handle_path_without_trailing_slash( strbuf_add(&work_path, name, strlen(name)); strbuf_addch(&work_path, '/'); pos = index_name_pos(istate, work_path.buf, work_path.len); - handle_path_with_trailing_slash(istate, work_path.buf, pos); + nr_in_cone = handle_path_with_trailing_slash( + istate, work_path.buf, pos); strbuf_release(&work_path); + return nr_in_cone; } } From patchwork Fri Feb 23 03:18:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Hostetler X-Patchwork-Id: 13568527 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AA484125C3 for ; Fri, 23 Feb 2024 03:18:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708658318; cv=none; b=rvUqh75AZDDp+FO9a9TSETCqJjmYoPRtKnTbQEY/2l80C8CmnWfgDV1FRkiqg+zdZKS+tBUxjRkK6duQRCSJhI90gVUytcul+zg0yr+tJsuTpree+z7r5lovXEHJHo34dvYbwhoBf+DDE+WzVvnzWbaXjVOmRxgpZiQ/Quciwdk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708658318; c=relaxed/simple; bh=5Lgbhcoa1/4GEjM3CIAFFdfrePzVAkkf5qUOn7ky13U=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=CLknXMq+yaOyZY77dMyc4idpYvwPmCnfkgxagwCPH8JIHjtj/5DluIyJSHypzG3r42+U27b0HqBgOyjruqKqS6tTmfNYk4CLDyFPz+V8eDMBmK4wn/6ibPOMbMoEWNrXcHSi6GDslxeiofiIQnc3gQKjGVedPDlFJhrcbjUTN0k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Q26/Ai+l; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Q26/Ai+l" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-41276a43dc3so2999145e9.0 for ; Thu, 22 Feb 2024 19:18:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708658315; x=1709263115; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=J06St+xabqDt0N/pFzzEVUlB6jdopGfNE6G3xY7sB7U=; b=Q26/Ai+lEv4Pn63BsmFJb6oKUHuFHOaj4hmMw0RrQc26m7kKJAkFKnTfH1gHbaK/B+ mHICd7Bx9V0HIu6d6sjHIZpnDZ4ONekXO5Jy1umouHZ4ozdzdBtVsO4cN86ZiP99RHMt teb+Hhld8QaCHoxX3HvJkQT+8W/wv7rhswt775NHi8QARW/2/BEkKAZDXL1anYp9G9HF XNe9en6ZFZuRVyrpUcVbvg9oAFKOnmZ7u4Bv99P2cOuFrFa6qWfhiK+dJHW1uPQuabsv KxGmDGLtKqYMz3DixLqVlzO9TJs67Nt5KkksI+EVy5/JDknEIk92sRMHvr+UhqMi8L5h HHGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708658315; x=1709263115; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=J06St+xabqDt0N/pFzzEVUlB6jdopGfNE6G3xY7sB7U=; b=JcCgseQqgmvr1sEG2tr1+dAdyIluMUq3FRhG5nzXPgZr4PQbOkY9fQ4t9y95/lx8dG 7owoURRL4AX++uedaeVrn2tfUrrMWgqsElsbRl6Qy8xgCbvHIJ367lk+LYz2YHsEyx0k NQ0r08rZn/LmZQrrFq1y/jQFYFgfm9Rj+03Otd+GTGlB2geHeJVHJz2ZgrFH4Y8uCjAo 0xJqReSMQR9C4EaRePzSya0jCBJHxb/DLObGdIdhdQM2StAlzwuxtNB8SuXqbzxsHYt7 75xplHO/tLkAmL/jqFav6RfPjr7DGn4jhjsjXU6MaLO442evfFQSRYEfOVdjr26/Tqt4 aPOg== X-Gm-Message-State: AOJu0YwaYI51GcgMUOT7B3vOf0zHvIY2pBJB4+IHsCoC0Wa6t3P6MsTu cNX406TduoS1mjiXS+hK5oeuQSh8CdGecHu8D5RPIER7SUR/mO9O7OMlefVD X-Google-Smtp-Source: AGHT+IFPJytXS/CWek43jy51fgrfI0lyMkdIMGSaJpyzwnNM5uu+D+daGJJuIewLcu2++EDKTov3Gg== X-Received: by 2002:a5d:6288:0:b0:33d:9ee9:3c15 with SMTP id k8-20020a5d6288000000b0033d9ee93c15mr528927wru.1.1708658315018; Thu, 22 Feb 2024 19:18:35 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id y6-20020adfe6c6000000b0033d06dfcf84sm979858wrm.100.2024.02.22.19.18.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 19:18:34 -0800 (PST) Message-ID: <58b36673e151ad15eb44c9ca1c03cfef51657d11.1708658300.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 23 Feb 2024 03:18:17 +0000 Subject: [PATCH v2 13/16] fsmonitor: trace the new invalidated cache-entry count Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Patrick Steinhardt , Jeff Hostetler , Jeff Hostetler , Jeff Hostetler From: Jeff Hostetler From: Jeff Hostetler Consolidate the directory/non-directory calls to the refresh handler code. Log the resulting count of invalidated cache-entries. The nr_in_cone value will be used in a later commit to decide if we also need to try to do case-insensitive lookups. Signed-off-by: Jeff Hostetler --- fsmonitor.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/fsmonitor.c b/fsmonitor.c index c16ed5d8758..739ddbf7aca 100644 --- a/fsmonitor.c +++ b/fsmonitor.c @@ -308,16 +308,21 @@ static void fsmonitor_refresh_callback(struct index_state *istate, char *name) { int len = strlen(name); int pos = index_name_pos(istate, name, len); + size_t nr_in_cone; trace_printf_key(&trace_fsmonitor, "fsmonitor_refresh_callback '%s' (pos %d)", name, pos); - if (name[len - 1] == '/') { - handle_path_with_trailing_slash(istate, name, pos); - } else { - handle_path_without_trailing_slash(istate, name, pos); - } + if (name[len - 1] == '/') + nr_in_cone = handle_path_with_trailing_slash(istate, name, pos); + else + nr_in_cone = handle_path_without_trailing_slash(istate, name, pos); + + if (nr_in_cone) + trace_printf_key(&trace_fsmonitor, + "fsmonitor_refresh_callback CNT: %d", + (int)nr_in_cone); } /* From patchwork Fri Feb 23 03:18:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Hostetler X-Patchwork-Id: 13568529 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E40DBC8CE for ; Fri, 23 Feb 2024 03:18:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708658319; cv=none; b=F7+PBetU5k54DhtAAcVEf24Otxfow8T+D8FwejXvk7yEUz49rtOeeSeJAjJm6bUM9pxTzMI0hSz1YZLy8PdTt9AM3RTCgrXNvv+ZvVyurb7V8WUi4yG9QeXJYWwDJOmeNa4RnHPo8/3lusi3NozNcxbJjvLohzX6ZbKVH5dJZzM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708658319; c=relaxed/simple; bh=xwwjxYlk0GoqT68YQSxD4qNy63+zETfjSYr+zKyQqEQ=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=ccM93YHni/7VtiPZ4bNdAPDiZdW3IOqy6ppecceKbl6dGpOb6+KgpzDUdU6ksL8/MSBYq1JevcT0bbJOWGM0IZ+/H6/HhWf1qxLZogSn7ma2rTMJvskLrKrq6vD2101ELxT+mKjXiP4Y83vMn/6LteSsbDFHv5GbOOdxMsXgqSY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=WVxzQ+W1; arc=none smtp.client-ip=209.85.128.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WVxzQ+W1" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-40fd72f7125so3135255e9.1 for ; Thu, 22 Feb 2024 19:18:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708658316; x=1709263116; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=+NdkiaalWQSUju4Cy2JLcnEWt1y46LCzKnjE2/QmSec=; b=WVxzQ+W1FDeb0T5MbUILgwYFyMzsaIVvdSU/qIhgzbGGQU6Xk3aEhaLa73ZNadhsHV WqxfrzB2dfpoWG7dWWrbm/+J+B6G8Z4GwlBYwa9167Lnq8D+EIbh+hthvYnEQncut0sL acJGbofmePAyAYsrS5oK3b36aPWmLE2P8O0tCRGWnvj7O9i2GeRW7ve4NwlRR+U0c1/D TgKdL9+QDqOwfqV1JqZdhzS/JTAXqu1P/r/wyhkcvRYfljd+UD4fponhA3cQKN2TL5js Td4Z9AbueL4t+REySXuyXlwiCgyUlArLYx6CnMoTSCdDHhoNguL9Me5Qd/GrRsi8+rrG Mn7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708658316; x=1709263116; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+NdkiaalWQSUju4Cy2JLcnEWt1y46LCzKnjE2/QmSec=; b=dnu4uECv2Bj6N7NzQPyXPsbyEeOwXcjNNH19PyHsZLRDVldH8aITaxpZv3HcOMiKo5 lpXFnMNsZfye7ZpMIkcCpNgsJ1KbEuRAaYmI+hSgWCKmwU0O0AEpra+rPEARJlCUI5sw XN09EcVSVpTYj7HlfbqYd05cANWuCY8vTy+/mqcY2ctc14N6xIoOcPe39blspCNjL9/l ym/EbXZVNH13UmVrtn/RrggPMa5tEUGco1SEka1zXkVf0e64JMmNOPGV5MjR6t9W63X+ 6PVy3yZSFttC4FIIsuQ9BBSDRtbeoGeQQv3d4zxKXnXEW2D+XD6v9wBMv2LeXPZ9CT+l ypNQ== X-Gm-Message-State: AOJu0YwZh37vi1EhDbHEr3+fy+ZJfbof6VOdFZXWittsE98QJhP3ToqP gQqDqgaiN8REii9Q99U6n3HRYExgM4R0pktmrWdzqVygFNRg6dGO78U5A0Oa X-Google-Smtp-Source: AGHT+IHGjSpIGoz16qnVOygXufwG8702yXucFmYgMAxmlXWKpsbgA8tX2hIdQDQdvmOGU5LaQVj0EQ== X-Received: by 2002:a05:600c:a39e:b0:412:8c43:98ef with SMTP id hn30-20020a05600ca39e00b004128c4398efmr348728wmb.21.1708658315680; Thu, 22 Feb 2024 19:18:35 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id fc19-20020a05600c525300b0041285ffec13sm578415wmb.41.2024.02.22.19.18.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 19:18:35 -0800 (PST) Message-ID: <288f3f4e54e98a68d72e97125b1520605c138c3c.1708658300.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 23 Feb 2024 03:18:18 +0000 Subject: [PATCH v2 14/16] fsmonitor: support case-insensitive events Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Patrick Steinhardt , Jeff Hostetler , Jeff Hostetler , Jeff Hostetler From: Jeff Hostetler From: Jeff Hostetler Teach fsmonitor_refresh_callback() to handle case-insensitive lookups if case-sensitive lookups fail on case-insensitive systems. This can cause 'git status' to report stale status for files if there are case issues/errors in the worktree. The FSMonitor daemon sends FSEvents using the observed spelling of each pathname. On case-insensitive file systems this may be different than the expected case spelling. The existing code uses index_name_pos() to find the cache-entry for the pathname in the FSEvent and clear the CE_FSMONITOR_VALID bit so that the worktree scan/index refresh will revisit and revalidate the path. On a case-insensitive file system, the exact match lookup may fail to find the associated cache-entry. This causes status to think that the cached CE flags are correct and skip over the file. Update event handling to optionally use the name-hash and dir-name-hash if necessary. Signed-off-by: Jeff Hostetler --- fsmonitor.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/fsmonitor.c b/fsmonitor.c index 739ddbf7aca..ac638a61c00 100644 --- a/fsmonitor.c +++ b/fsmonitor.c @@ -5,6 +5,7 @@ #include "ewah/ewok.h" #include "fsmonitor.h" #include "fsmonitor-ipc.h" +#include "name-hash.h" #include "run-command.h" #include "strbuf.h" #include "trace2.h" @@ -186,6 +187,102 @@ static int query_fsmonitor_hook(struct repository *r, static size_t handle_path_with_trailing_slash( struct index_state *istate, const char *name, int pos); +/* + * Use the name-hash to do a case-insensitive cache-entry lookup with + * the pathname and invalidate the cache-entry. + * + * Returns the number of cache-entries that we invalidated. + */ +static size_t handle_using_name_hash_icase( + struct index_state *istate, const char *name) +{ + struct cache_entry *ce = NULL; + + ce = index_file_exists(istate, name, strlen(name), 1); + if (!ce) + return 0; + + /* + * A case-insensitive search in the name-hash using the + * observed pathname found a cache-entry, so the observed path + * is case-incorrect. Invalidate the cache-entry and use the + * correct spelling from the cache-entry to invalidate the + * untracked-cache. Since we now have sparse-directories in + * the index, the observed pathname may represent a regular + * file or a sparse-index directory. + * + * Note that we should not have seen FSEvents for a + * sparse-index directory, but we handle it just in case. + * + * Either way, we know that there are not any cache-entries for + * children inside the cone of the directory, so we don't need to + * do the usual scan. + */ + trace_printf_key(&trace_fsmonitor, + "fsmonitor_refresh_callback MAP: '%s' '%s'", + name, ce->name); + + untracked_cache_invalidate_trimmed_path(istate, ce->name, 0); + + ce->ce_flags &= ~CE_FSMONITOR_VALID; + return 1; +} + +/* + * Use the dir-name-hash to find the correct-case spelling of the + * directory. Use the canonical spelling to invalidate all of the + * cache-entries within the matching cone. + * + * Returns the number of cache-entries that we invalidated. + */ +static size_t handle_using_dir_name_hash_icase( + struct index_state *istate, const char *name) +{ + struct strbuf canonical_path = STRBUF_INIT; + int pos; + size_t len = strlen(name); + size_t nr_in_cone; + + if (name[len - 1] == '/') + len--; + + if (!index_dir_find(istate, name, len, &canonical_path)) + return 0; /* name is untracked */ + + if (!memcmp(name, canonical_path.buf, canonical_path.len)) { + strbuf_release(&canonical_path); + /* + * NEEDSWORK: Our caller already tried an exact match + * and failed to find one. They called us to do an + * ICASE match, so we should never get an exact match, + * so we could promote this to a BUG() here if we + * wanted to. It doesn't hurt anything to just return + * 0 and go on becaus we should never get here. Or we + * could just get rid of the memcmp() and this "if" + * clause completely. + */ + return 0; /* should not happen */ + } + + trace_printf_key(&trace_fsmonitor, + "fsmonitor_refresh_callback MAP: '%s' '%s'", + name, canonical_path.buf); + + /* + * The dir-name-hash only tells us the corrected spelling of + * the prefix. We have to use this canonical path to do a + * lookup in the cache-entry array so that we repeat the + * original search using the case-corrected spelling. + */ + strbuf_addch(&canonical_path, '/'); + pos = index_name_pos(istate, canonical_path.buf, + canonical_path.len); + nr_in_cone = handle_path_with_trailing_slash( + istate, canonical_path.buf, pos); + strbuf_release(&canonical_path); + return nr_in_cone; +} + /* * The daemon sent an observed pathname without a trailing slash. * (This is the normal case.) We do not know if it is a tracked or @@ -319,6 +416,19 @@ static void fsmonitor_refresh_callback(struct index_state *istate, char *name) else nr_in_cone = handle_path_without_trailing_slash(istate, name, pos); + /* + * If we did not find an exact match for this pathname or any + * cache-entries with this directory prefix and we're on a + * case-insensitive file system, try again using the name-hash + * and dir-name-hash. + */ + if (!nr_in_cone && ignore_case) { + nr_in_cone = handle_using_name_hash_icase(istate, name); + if (!nr_in_cone) + nr_in_cone = handle_using_dir_name_hash_icase( + istate, name); + } + if (nr_in_cone) trace_printf_key(&trace_fsmonitor, "fsmonitor_refresh_callback CNT: %d", From patchwork Fri Feb 23 03:18:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Hostetler X-Patchwork-Id: 13568530 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 80D27D26B for ; Fri, 23 Feb 2024 03:18:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708658320; cv=none; b=W0F6gpp3oVnulv3Bi5D8niz3NFKCuoNvUC9xxMD9VZ/C4HmDC9ZTFgzhZXrnNNz9wNOvwTDKdv7gC71Ir+ShtEd3RMbtS9A9+CucoGPx0iaLlVpEB7oonIU8AsU+6rpOBXYu7MIVwfHfjQEDXCl9UF76SEEgeeUa8k8fz95DhB4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708658320; c=relaxed/simple; bh=89YU0+PdNITDh+80ewZPlvSxBw/G6dgqRHGSTQpT9LI=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=VCVYSGfg+PqyXEcUc9lfMu2bjPRpRYE3EGKYpZdbepSpy4dglVcy7o63u4oJesx3ILTZqN9YUbpfnxwCDi6aRLQHnfisemI13WI3R4rh37zM7clYzspMkGUY7cRhfIITGaaf1O7t+RDlzpaTHEp7ksXwBz2oXHa4DUH9KoOKG/8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=W1gWKDZ5; arc=none smtp.client-ip=209.85.128.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="W1gWKDZ5" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-4129015c31eso2843785e9.2 for ; Thu, 22 Feb 2024 19:18:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708658317; x=1709263117; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=YQ7D8m7FRmDmzSp4UQ4i0bLa6tugBVKmqCDi28v96ow=; b=W1gWKDZ5DhZ90ZT4N/UI5nvx8kO+Kt1qU1GrMOuAdL3TBT19Nfy2Hi1py8XGs4OVuk 3KzftkZGPvxgXMdlnettgVQxFUs7j+1A8jIyfrRt6ostfOZV7gUomlbxvAbzsydvG7Ur SxERzTHKrDycwocH7Ay1H0aGcXGOGF/3Whs4NAaPhPWpE+09Sk9gHWZxXTQPsL5rBOPZ QA1c1xb7u8VHHuKsP9dnhbDIwVUCbCZK8KpKdYMVGACZ0lnozaoDbBZY2G1p4Vfuyb3O 3twVbGMq7BPScJJx4ftcSNx+V/wBot0FBkmBR3NziTKupBhvXYljg1MITMS/4HbAtI3w /xtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708658317; x=1709263117; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YQ7D8m7FRmDmzSp4UQ4i0bLa6tugBVKmqCDi28v96ow=; b=kpO236RHap2zyJDmphXJnMW1XuVW5Q5KZjqIQ+2nqtjlT/expWIAiq1kTEAR4+miyN xTDP3Sh6+ysBEuFBitghBotCYLA02EFDOurF3lKBp1sF48isBxxV3sSJMjunW5HSpyk6 2/NxwKP5VK+Uy4hKiS1iCtW5oeHApv+1294YUASz12DsGpX3RSw5dY+mVyWEOUm6B0AF aKIa810JKS546v4EK2tkLpK2z5Z35lIRogFV4+6AU8lUqmGvyDpUeTzkrB1OCupq8esK lIMeBKay0RK2kiIukUjtflQ1OoqdjnkyrKQXgSCZdAlU9d5uYjScQPVfcEKyf4LXGRVU 427w== X-Gm-Message-State: AOJu0Yy6iRmuf1o4I+Hj5pg8BwccovpOBLaFGwYNilO+nLAYwQxj2/2j M1fg0zgiyBzh2ZwzpeBZCNZasaapPk3oS7Mg7gM3H+sV94Dc8GhrTnme/c+v X-Google-Smtp-Source: AGHT+IEMLtIIpWgBLTgpazGpozheaGdJx8iqUTZsD1CBepKAF/2IYgkc4iyvjnJNVu3sdP6SwTc+aw== X-Received: by 2002:a05:600c:2e43:b0:412:8f5c:cd08 with SMTP id q3-20020a05600c2e4300b004128f5ccd08mr339640wmf.22.1708658316849; Thu, 22 Feb 2024 19:18:36 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id c23-20020a7bc857000000b004128f1ace2asm579478wml.19.2024.02.22.19.18.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 19:18:36 -0800 (PST) Message-ID: <3a20065dbf80eabfc62c0bdebc16df0b5a4c7b02.1708658300.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 23 Feb 2024 03:18:19 +0000 Subject: [PATCH v2 15/16] fsmonitor: refactor bit invalidation in refresh callback Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Patrick Steinhardt , Jeff Hostetler , Jeff Hostetler , Jeff Hostetler From: Jeff Hostetler From: Jeff Hostetler Refactor code in the fsmonitor_refresh_callback() call chain dealing with invalidating the CE_FSMONITOR_VALID bit and add a trace message. During the refresh, we clear the CE_FSMONITOR_VALID bit in response to data from the FSMonitor daemon (so that a later phase will lstat() and verify the true state of the file). Create a new function to clear the bit and add some unique tracing for it to help debug edge cases. This is similar to the existing `mark_fsmonitor_invalid()` function, but we don't need the extra stuff that it does. Signed-off-by: Jeff Hostetler --- fsmonitor.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/fsmonitor.c b/fsmonitor.c index ac638a61c00..0667a8c297c 100644 --- a/fsmonitor.c +++ b/fsmonitor.c @@ -187,6 +187,20 @@ static int query_fsmonitor_hook(struct repository *r, static size_t handle_path_with_trailing_slash( struct index_state *istate, const char *name, int pos); +/* + * Invalidate the FSM bit on this CE. This is like mark_fsmonitor_invalid() + * but we've already handled the untracked-cache and I want a different + * trace message. + */ +static void invalidate_ce_fsm(struct cache_entry *ce) +{ + if (ce->ce_flags & CE_FSMONITOR_VALID) + trace_printf_key(&trace_fsmonitor, + "fsmonitor_refresh_callback INV: '%s'", + ce->name); + ce->ce_flags &= ~CE_FSMONITOR_VALID; +} + /* * Use the name-hash to do a case-insensitive cache-entry lookup with * the pathname and invalidate the cache-entry. @@ -224,7 +238,7 @@ static size_t handle_using_name_hash_icase( untracked_cache_invalidate_trimmed_path(istate, ce->name, 0); - ce->ce_flags &= ~CE_FSMONITOR_VALID; + invalidate_ce_fsm(ce); return 1; } @@ -316,7 +330,7 @@ static size_t handle_path_without_trailing_slash( * cache-entry with the same pathname, nor for a cone * at that directory. (That is, assume no D/F conflicts.) */ - istate->cache[pos]->ce_flags &= ~CE_FSMONITOR_VALID; + invalidate_ce_fsm(istate->cache[pos]); return 1; } else { size_t nr_in_cone; @@ -394,7 +408,7 @@ static size_t handle_path_with_trailing_slash( for (i = pos; i < istate->cache_nr; i++) { if (!starts_with(istate->cache[i]->name, name)) break; - istate->cache[i]->ce_flags &= ~CE_FSMONITOR_VALID; + invalidate_ce_fsm(istate->cache[i]); nr_in_cone++; } From patchwork Fri Feb 23 03:18:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Hostetler X-Patchwork-Id: 13568531 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E379212B6F for ; Fri, 23 Feb 2024 03:18:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708658321; cv=none; b=ruuGKyge1d6ExMl5LyOMq4DND3TtdbhNj3Mwi+VCfCsKJtI1qCmXhmIRaowYDPCWrC5Z7cszYmNfBP3gn0v32Upkh7iy6wXcleGJmLpjpgFKQoHfRGKbCLznvomyhLrKuEqOJsv4AbwXgHqBwwHG8i15t9loVEY+r9V7gvMufx4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708658321; c=relaxed/simple; bh=gITuhz03qFDco93TuWaDax7YUxmrZqVlPLqSq64UCaE=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=JV0e0nj8gd2DFyzYV07akOsR5S96d9LEALichr0vSFyQvQWLUXmaQjDHOvZdLrPasKvWZRMmdVv+EgSfrLHR+pgd5YQ5fh8P0lKvXO9C7x8kCIyRlKE7dLvDay1pUbEpKfekeCtcheuK3PUMeP3N2dtXxc2xp/n4Ql140OKIG1Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=DWhsDhNh; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DWhsDhNh" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-41293dec05cso513085e9.1 for ; Thu, 22 Feb 2024 19:18:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708658318; x=1709263118; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=C3BT76YdmHwSNScO97hUhhT9sG4uVF3slVVWP5cUEQU=; b=DWhsDhNhYfp3ybrW9IuoyTV3eapfyAJQ+M4P7ovLEIr6ukVK6TScU9MvkEoSbtQC7F K+tq4Ze0fRvfpg1AZFrZoNe/EmOdb6vf5+hfSxj70fFUEWnpTGJhz3zPxHB4aTub/zNQ ZhrBf5YcfnCJhyv8enmr1Qlk7BXU8+7prSKLRuNsR6g3ZFo2NLgv5GBs2DgJ8YlLz49J cWVunsolROyMRoUw28pWH2Ne6FUIYJ0B1eiKl1V1LvqOgDitWv7Cwl0cVUlHgo5F7bdn RPi1EEtUdwl4miIjOximGH7ML8Zu/4t37tmCL+CVwhOL3kpyuql8CZXmxFx/wJZTwZis 01Vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708658318; x=1709263118; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=C3BT76YdmHwSNScO97hUhhT9sG4uVF3slVVWP5cUEQU=; b=LXE1dUQ4k9sxFIXR545suT2s40DKR1NxEOmXUxkwp12edwUyWfXgpyLxgG7Jmg/tA0 Ei23XjfjIcTv4hypLCDHQSi6lj1NjnsocjQgYMB4rOnEegPFxLOOgsPuLMYAdm17AW+3 RdVoY9QThDLOOMjc5xHvawLmhkKFt/HADdpXTMy+KkSXkcttZm/Y1fOtCJkA88Kt8ueO MBPuZtU0fi8ksglnacKHHYm6r/nfLUudSyBuQ+gtdcfxI/ZP5Ab5D8E9SRL1C82uoyxl T9QKeurOIAtaKcRpjEOE/uOE9Fy+gfI8BzikvwLBuHsd1lTgf381+1O9C+I1MzIC6rxQ U2Cw== X-Gm-Message-State: AOJu0Yxdzp83gb+7CYOWwoDhcjdfDkGs54japuqYRABjR9U8GV2+kiaZ 3RGsLUAE07YC6sbe484q6WX3hLK2UNhp4+9tVVvwD2BNm7ic+WSo7UWT0Ct3 X-Google-Smtp-Source: AGHT+IFZIBtFBYLBBlpsofbKHUQeymW3+susOgx457ixXkPjoUoUr+8x3vzotEONzDLRX8jvZ7Zvdg== X-Received: by 2002:a05:600c:3051:b0:412:78da:8abe with SMTP id n17-20020a05600c305100b0041278da8abemr336497wmh.30.1708658317530; Thu, 22 Feb 2024 19:18:37 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id u16-20020a05600c211000b004126732390asm575229wml.37.2024.02.22.19.18.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 19:18:37 -0800 (PST) Message-ID: <467d3c1fe2ca86d5ba8dff7e4c6b1f5cc9c5806c.1708658300.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 23 Feb 2024 03:18:20 +0000 Subject: [PATCH v2 16/16] t7527: update case-insenstive fsmonitor test Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Patrick Steinhardt , Jeff Hostetler , Jeff Hostetler , Jeff Hostetler From: Jeff Hostetler From: Jeff Hostetler Now that the FSMonitor client has been updated to better handle events on case-insenstive file systems, update the two tests that demonstrated the bug and remove the temporary SKIPME prereq. Signed-off-by: Jeff Hostetler --- t/t7527-builtin-fsmonitor.sh | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/t/t7527-builtin-fsmonitor.sh b/t/t7527-builtin-fsmonitor.sh index 4acb547819c..939521a0fac 100755 --- a/t/t7527-builtin-fsmonitor.sh +++ b/t/t7527-builtin-fsmonitor.sh @@ -1051,7 +1051,7 @@ test_expect_success 'split-index and FSMonitor work well together' ' # # The setup is a little contrived. # -test_expect_success SKIPME,CASE_INSENSITIVE_FS 'fsmonitor subdir case wrong on disk' ' +test_expect_success CASE_INSENSITIVE_FS 'fsmonitor subdir case wrong on disk' ' test_when_finished "stop_daemon_delete_repo subdir_case_wrong" && git init subdir_case_wrong && @@ -1116,19 +1116,20 @@ test_expect_success SKIPME,CASE_INSENSITIVE_FS 'fsmonitor subdir case wrong on d grep -q "dir1/DIR2/dir3/file3.*pos -3" "$PWD/subdir_case_wrong.log1" && + # Also verify that we get a mapping event to correct the case. + grep -q "MAP:.*dir1/DIR2/dir3/file3.*dir1/dir2/dir3/file3" \ + "$PWD/subdir_case_wrong.log1" && + # The refresh-callbacks should have caused "git status" to clear # the CE_FSMONITOR_VALID bit on each of those files and caused # the worktree scan to visit them and mark them as modified. grep -q " M AAA" "$PWD/subdir_case_wrong.out" && grep -q " M zzz" "$PWD/subdir_case_wrong.out" && - # However, with the fsmonitor client bug, the "(pos -3)" causes - # the client to not update the bit and never rescan the file - # and therefore not report it as dirty. - ! grep -q " M dir1/dir2/dir3/file3" "$PWD/subdir_case_wrong.out" + grep -q " M dir1/dir2/dir3/file3" "$PWD/subdir_case_wrong.out" ' -test_expect_success SKIPME,CASE_INSENSITIVE_FS 'fsmonitor file case wrong on disk' ' +test_expect_success CASE_INSENSITIVE_FS 'fsmonitor file case wrong on disk' ' test_when_finished "stop_daemon_delete_repo file_case_wrong" && git init file_case_wrong && @@ -1246,12 +1247,14 @@ test_expect_success SKIPME,CASE_INSENSITIVE_FS 'fsmonitor file case wrong on dis grep -q "fsmonitor_refresh_callback.*FILE-3-A.*pos -3" "$PWD/file_case_wrong-try3.log" && grep -q "fsmonitor_refresh_callback.*file-4-a.*pos -9" "$PWD/file_case_wrong-try3.log" && - # Status should say these files are modified, but with the case - # bug, the "pos -3" cause the client to not update the FSM bit - # and never cause the file to be rescanned and therefore to not - # report it dirty. - ! grep -q " M dir1/dir2/dir3/file-3-a" "$PWD/file_case_wrong-try3.out" && - ! grep -q " M dir1/dir2/dir4/FILE-4-A" "$PWD/file_case_wrong-try3.out" + # Also verify that we get a mapping event to correct the case. + grep -q "fsmonitor_refresh_callback MAP:.*dir1/dir2/dir3/FILE-3-A.*dir1/dir2/dir3/file-3-a" \ + "$PWD/file_case_wrong-try3.log" && + grep -q "fsmonitor_refresh_callback MAP:.*dir1/dir2/dir4/file-4-a.*dir1/dir2/dir4/FILE-4-A" \ + "$PWD/file_case_wrong-try3.log" && + + grep -q " M dir1/dir2/dir3/file-3-a" "$PWD/file_case_wrong-try3.out" && + grep -q " M dir1/dir2/dir4/FILE-4-A" "$PWD/file_case_wrong-try3.out" ' test_done