From patchwork Mon Feb 26 21:39: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: 13572940 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (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 5471412C7F6 for ; Mon, 26 Feb 2024 21:39:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708983572; cv=none; b=qoRVpUQ+vGUK2lCBcxgd/+C01EaRHnj4ZgL+44LtAhw2qewu8uF9VA7Y8iEB2Op8SEm/09tb6mH8oWxvSgozD60NkdEWxKZoD3lLXZFkoX9ep+3BHXkM0Vcd+DVpwGA31bUTgkUkO33Caa391MuO4z2O5jxTGo6uSgADF/AtfB4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708983572; c=relaxed/simple; bh=FKmDwszd8j4PtKBkMGfED1fxwvx/9tAnkZfU3CzKlD4=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=I7KAcm7HQzn3RJDK0olOLL6bupzxYn9S6yDWwT2cw/BL/0WSN73BKYMe5VLMtOzrmEPx9mLa8YnO6djasDJxUzfIpzwWadzhgve4txEtMZEE6QZRi6+ItXhclJMgtP7JETvC32TIC3QzGiffFmfT8egZfhXnkLYj6Wci41SQuP8= 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=KwOP0l7h; arc=none smtp.client-ip=209.85.128.53 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="KwOP0l7h" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-41296dce264so24644735e9.3 for ; Mon, 26 Feb 2024 13:39:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708983568; x=1709588368; 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=ojRn63jU9XfSAQzkLgCCW9dMjb3fFbMEE1XrppnOcnE=; b=KwOP0l7hEkKpy/w4U68bFK8zkWfsEs4yIMfLNLnisYegkoasjq+V1AEIHWE4SCbDON axg0bn8QCj2d035DrrRL8XjYlSu/VCmrXnCrOeJLhrPBanIEDbycB2hsFOp2MEXfNQKc /X+GKPwf7OaHITENDqHxW9ZmFq8Q8HcAJlYinlRPkw/Fu8YAMI5xcjw2IbBk3lT3ha3s 1PPbs4eDiFksfKhDjavqySUVOPOO7TUO7T6Uq34FFMEb0T8eIDb5kboHpx3zo/kII/K6 lgafUwxrNoCTVPCmXMJg5Gwli6K6hfozUWzcU2eytqE9n8qR7YESbfbdsw6lhwtsyQXv ro7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708983568; x=1709588368; 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=ojRn63jU9XfSAQzkLgCCW9dMjb3fFbMEE1XrppnOcnE=; b=q8ud2aZ0SeQNQJGjgP0hVwDw5Kz9EduOE5Qh3R2fTJSFmbYlOA9hk4CWfq00X3Bflb 3CCzhBoEJ5pE2KZ4L4AjfltSZOcjYJUEG/zaNhXnluCLZVXcGjta/E9fpZv7WAYmXXgi NmyQXWPVyA8MhqzJksiA9J2pQb+PujVWnYsc9EYRrqPanXskAV0F/boYAMfLUdlWRvD0 xlUxCAiJ9DSPOTEJtF+d9jd+AdubhUS0Bt/MNC61tyMN6WIZYl34O/rcErk0WjrNRl5Z 80QtG96fKx1qII8uZ3lIH/ZvijQMPZU7Ij6wtobKHHTrL0jctSlHf5nbv+tO2YHzo4Eg +mEg== X-Gm-Message-State: AOJu0YwEJVkpM9kwvjohJlI5r5MXHylt3pW9Gm5GWPrKkqVFOoqzC80D TzJ5cxPasAZd5dMgyvWAKf2dslzY2Vxzi7MKcZJI0+rac9qLx7g+qhO6duWc X-Google-Smtp-Source: AGHT+IF8YPFB2qyjQcpRD8aVBBevsIRXhxwXj9/Pzto4fXa3cxmbMRs39GITPWM8IRhRkGxBkQFmOQ== X-Received: by 2002:a05:6000:1046:b0:33d:9232:5aed with SMTP id c6-20020a056000104600b0033d92325aedmr5301638wrx.52.1708983567914; Mon, 26 Feb 2024 13:39:27 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id v17-20020adfe291000000b0033d56aa4f45sm9144298wri.112.2024.02.26.13.39.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 13:39:27 -0800 (PST) Message-ID: <64ae07aaeaa2f9e91d153ddd1aacefb62188456f.1708983566.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 26 Feb 2024 21:39:12 +0000 Subject: [PATCH v3 01/14] 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 , Torsten =?utf-8?q?B=C3=B6gershausen?= , Jeff Hostetler , Jeff Hostetler From: Jeff Hostetler From: Jeff Hostetler index_dir_exists() returns a boolean to indicate if there is a case-insensitive match in the directory name-hash, but does not provide the caller with the exact spelling of that match. Create index_dir_find() to do the case-insensitive search *and* optionally return the spelling of the matched directory prefix in a provided strbuf. To avoid code duplication, convert index_dir_exists() to be a trivial wrapper around the new index_dir_find(). 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 Mon Feb 26 21:39: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: 13572941 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.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 7D5F112F593 for ; Mon, 26 Feb 2024 21:39:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708983573; cv=none; b=ck8uAmUriQJiaBdbbS06Hy80RIUTgcHcTzYRmKCB3lJ8GPbTdH6NBhmAUEoFobXHstLtHDAzl/l6JpuD0fBjM4b+20Mq4+jTaskez0seSiFyD7Rh3SfnpeA25/Gv86Ndu7D0groN9bj5+ypbF3MCYLd9SO4wypC+vRAAJ5AVneE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708983573; c=relaxed/simple; bh=nSwiu9C2TkFSPA8C5FcPusdsYl8w9MfsDx4Fmxlo5jM=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=Fb3aIl9j2nFQ+vwGxqOwNrF7TRWBEEDwFt8Z45fWA552wtuQXnn/0nec0wgtNMvII06lQRz1nLfh/mE0fiIszCrmzGzpvwbNoNLLrT2gtIx0qkgIL9a1FCt2FQooqyJ4o5nQOVaC9DtGa3WU2soPghVA8trpipG6qgVbZ9ei6f8= 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=eN+2RkpD; arc=none smtp.client-ip=209.85.221.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="eN+2RkpD" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-33d32f74833so2011736f8f.3 for ; Mon, 26 Feb 2024 13:39:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708983569; x=1709588369; 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=I58tPhYQAa1LkvGYtGxlHhIgjd9118Ra9WIKa+8o7TM=; b=eN+2RkpD4rNYR84kHVlnkrAxL2yjx1qVy71q0cCerGAkwx5/eXaFZprBuMvPCG63H3 489Q5bRhC6oK8m6Ax4njqLzFonHpt/dXjJyiizqwNdnTlnM4Kc5LPruxUM7/AdKnbXFV zWFyBYXfzjvD20qA6wrgzcngFKxzcpEUzuhvoSty5aqjUyMOHi9MNtTy6g1KyqdqpnSP D9NUURgiPi6ZGwbv7ZCzzxzmyMU0m7DwlBYbHaOg7RsFgkKo6wyRv/PEYyZVUPV42y+a mHnvtBrNjYTPwjspfAFsEMVeHTgW5x3KdvumcObI2gZ7teeSwe1+bLCCTxCCHzZeyBkJ Rhrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708983569; x=1709588369; 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=I58tPhYQAa1LkvGYtGxlHhIgjd9118Ra9WIKa+8o7TM=; b=Zi+scScFdDWV6X+JT7xbRSwnQGMy8txNaoMqCCgYSUtBajdfcUXArZnTLBo5GrhRee n8Ih/SSq/aQILrR0U9YryINHfqwQl5XwCKqkX+AZCSBQWf0Rwj2YsoroservtCmh0i2V HXytZ0WU5Z4JnhtZhNkIqJEZOm9EsAiQihHpw4ISQdJXR+J96dq71U7kCQ/99Ctnbflv T38ODOvWFMusEEZu+JffHXOhCyOvhlg/IPABTKCljrW4ZuWasX1NHeYWvho1SYsjI8UN EP+C2VNd55TvmChbFuY+QaaBrgwAszhI6kQuzj7BCLoiRs0EdxR9mEgA5TFRI2uIwCTm 33pw== X-Gm-Message-State: AOJu0YzSXC1i86QPKMY26E/76XyTNEa5af71BoTXhRXaK3PL7BiziC/9 1a84+jbeCxIMfsFIAWkSscp7GS00r76qKe1EX+JLCIMTfsukVU+uAALskIew X-Google-Smtp-Source: AGHT+IFsYXJloYtBnGsZHExxXo49MgLicSCnHeQXqe5MybOm2fBG4R5/M8TkIA++Ji+/WFoqcUfcWg== X-Received: by 2002:adf:fc8f:0:b0:33d:509a:7b7c with SMTP id g15-20020adffc8f000000b0033d509a7b7cmr5516256wrr.39.1708983569509; Mon, 26 Feb 2024 13:39:29 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id bo14-20020a056000068e00b0033d6bc17d0esm9750442wrb.74.2024.02.26.13.39.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 13:39:28 -0800 (PST) Message-ID: In-Reply-To: References: Date: Mon, 26 Feb 2024 21:39:13 +0000 Subject: [PATCH v3 02/14] 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 , Torsten =?utf-8?q?B=C3=B6gershausen?= , 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..830f2d9de33 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_failure 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" && + + # Expect Breakage: with the case confusion, the "(pos -3)" causes + # the client to not clear the CE_FSMONITOR_VALID bit and therefore + # status will not rescan the file and therefore not report it as dirty. + grep -q " M dir1/dir2/dir3/file3" "$PWD/subdir_case_wrong.out" +' + +test_expect_failure 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" && + + # Expect Breakage: with the case confusion, the "(pos-3)" and + # "(pos -9)" causes the client to not clear the CE_FSMONITOR_VALID + # bit and therefore status will not rescan the files and therefore + # not report them as 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 Mon Feb 26 21:39: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: 13572942 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 4F5EE130E3E for ; Mon, 26 Feb 2024 21:39:32 +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=1708983574; cv=none; b=jQ04f104J96tFlT7lGzG2uHT+srl7NJzyWqdAe46eFUQeKsVv1ha8ylEnIrOpwBUXjDO8daM9uRV4U+Z941WbGB01CrUqH5A+Y2Jv9Z0lYHRPgMVPdiRk91snBuOrtm29phoxvWowPfcUmrOAKPS50LIinDUWnkgO9f/ksZL7p8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708983574; c=relaxed/simple; bh=erNCQFjvIiC2NHLYEteWfRNdfyr0Xh9cfM3eyTbANwk=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=fXGsNMn3pyiE0MolftSN8daDFz6Fc2d0Sdk32pd50J3b2tvkHvOH5nwsOtZ1tP7fYEoqqkG2Lb38AB50XCU5RcPuNUr7JWpVFAu8Rlm53PJ+qrdGdXN1skZlffudKgpD8xw5uL6EO9Yu8NLz6sX0fptJACwDVxDREMGjULXVcbE= 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=b/XXyk/k; 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="b/XXyk/k" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-412a9ea61adso3264295e9.0 for ; Mon, 26 Feb 2024 13:39:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708983570; x=1709588370; 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=b/XXyk/kjzYvkNvFaDgTFpVjPjngBelRKAWRexuMYI+Zs+oLp0Yk1oHm9fw6rkoZem W707xS8BNI9boY5/TegrU/7aXHNMyrcUUITyy+CKbOMzh3ZSfRijhEV/5ZVXLrwbvBly r2LQMtATFwLdikIHSCpd0EBNFHaZ0CszFKRYIMZXQov1vV+4t0wY+c3H49eewV5lRP5b zWx0kUaRIKQ+wFxcrXkdfnFM5j3WZW1HR4IfOZLE7Dsr/ZKmHyZ74yu8cInSrJ8RBDMm uHQFZytpx67JTAm3mw98a4DmL4WXo2ElMJGPke/e8ROAaN5BaqgYI3iGySME9AI/r1qk 78qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708983570; x=1709588370; 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=hVhN1KGaHYiSDJeU/rexmbih1j99uGkdQBYYoGu0aCM/217uSgcuBy3X3m4El0qvjm FiPJCdbrw6CjyL8BvaNhG/9WIId4xda5OTok5tDtSPz9LNmDi9rKQL4/xBTnBbjqvVAs sIeZHLuxFEE8WpZIReFG/fjvMCTuCmBGz4sxe5SELx6i2zmwUkGXcPXjTmXRHfwArNOG RlXL6ukEbygysGj2BMVAkg6wcxgQSON2W9OggCCIQST/YkgUFHrk2S5mCxCRiRw9iEMh Q0wZEm2Knes1v8CBtJW/2z0LgDHuS7e2/6nX/yjmxDDJNC2u6SVEHM5E0gkz50L70bf6 h7yg== X-Gm-Message-State: AOJu0Ywi4ALGywKsnc777C33pQZBBo6vcKNH0i+6IGe0G7QRz2ikV0Es 7AL/7UnF0YMsY0qmzCFa60A84TGnWrTJP4FBwRFyOk5gwiYwi/P47+TV/CGS X-Google-Smtp-Source: AGHT+IEc2cte3mYGrHrdmuMs10MyGvrVAl5I567ZrOl2cSETUuczKUxFM7+WEI6qKjjI0yytbZNqmA== X-Received: by 2002:a05:600c:4708:b0:412:a333:1d36 with SMTP id v8-20020a05600c470800b00412a3331d36mr3344151wmo.32.1708983570330; Mon, 26 Feb 2024 13:39:30 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id z15-20020a05600c220f00b004126e26f756sm12998089wml.43.2024.02.26.13.39.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 13:39:29 -0800 (PST) Message-ID: <518cb4dd5df0c71ef43078129fbf78a8b232a749.1708983566.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 26 Feb 2024 21:39:14 +0000 Subject: [PATCH v3 03/14] 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 , Torsten =?utf-8?q?B=C3=B6gershausen?= , 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 Mon Feb 26 21:39: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: 13572943 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.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 15DEE131E21 for ; Mon, 26 Feb 2024 21:39:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708983574; cv=none; b=nhNRFCVV21JRX068umeuN+iS+9l9DKuW69QeoS/iXOP2FpKLtH/DPc46QHcfBJaKvwDTGw9aYG1BqeNlCBD92HvQ1OF4LyiZUX8KlcimEOCnCTG4vUdJI5DYh/aEwA868tq18ir07I4eOCP80fkqvXDgdblkagLSRAvzI/VdBtU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708983574; c=relaxed/simple; bh=yUFjxGXoa9Iu5ABIv8e5hSygDvEud2XumKI6i0VwrCo=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=HCFZ0dCyEWKxT3p+decVOgN6CCcFCji6nalrlBOOsBMv8OCFTjVrNhESrEeSRaiXAdqiwQ311lKCUs2U7R4bSxLUgSpG8aq42Oo7X20j9Ur+U+PJodyc61w9tN08DUmdpDRIe2NcaMI0jwRn7N9kU+GqSFatt2vsbWEGOHq8yMM= 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=VsCjPl/X; arc=none smtp.client-ip=209.85.221.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="VsCjPl/X" Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-33d26da3e15so1996859f8f.1 for ; Mon, 26 Feb 2024 13:39:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708983571; x=1709588371; 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=VsCjPl/XcWQCzm7Ud/Kf0UKmSJn4qH0vBFJg3g/b6hMOnxhp9QsTWhudD5EsjyIrUD cB9p0yRt+GX+GWbrrgbkFzbbDcflGSZtUpsQKPNkFDcTqa+aX45zOdkKIoAiS02vTqok a7qKnhbRLZNLN3RtENKTs2DqUo3C+yQy06hpD0VqGDJTX1dMMtU+WBv+SQe4E9Uy/6in X1gAS/IsTb8CQBm4m9qXXkN6YZ7DhG3MTl/PxGK1aKdbz81si5rGIoe66F9N4lp94hj1 7YVXZ5kyHo2Ui6f0x583ngKAozkReDfEPjlky3JWY1c1ZGrFy5Jn3NmGp5b1Vh2zIHFk I/UA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708983571; x=1709588371; 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=voOGz9nJBSXidxYYw10wnSn/cIN8lN38tKG6kzhsc6xCbrWl636zeXFrtqO79n3j8r CQzeBh1rhAywPGCRVs6f1Qc9D1d1ws9/z3Q+anxpLDCvW2+/obcYHijhexqIuCCktqQz 0Cx9laHqiiuyH2cNROYUv70Z+D3OKO4hCUjWkhs2fFT4UBSvD/JgxjLnWzxDDXD8O6cU 1JeC3smPdL2rT2xn3bGO9oZ+Vp1FRHqeZSuQ7VFkR/VqFtE8904WI3WCh9qKEFExmE2X UEogCoZQMwfL3wIWZsRoNpNYv/GtMDlLol3EB1TBb3426bqSkMlxLrrO3PUz9gD9aVRK wiBg== X-Gm-Message-State: AOJu0YzNPDmRwJwJZ0uepjzcZCa5YLYA9lF9/8OJKK+y1R/9eqXsn1lP PCGzpkqvYbmD3Vnqz48xRfiblq552TPtcXa3Jglpk8v1OfTP+e8e+RmOaqTK X-Google-Smtp-Source: AGHT+IGiEwRoBhnHyqPO92BoPaYH4erKvdOEPZXoqSZSH6myQlDH1nEyGIdv3J5OVskaMkEjSKxVMg== X-Received: by 2002:a5d:6d82:0:b0:33d:c0c3:fe08 with SMTP id l2-20020a5d6d82000000b0033dc0c3fe08mr7698983wrs.0.1708983571163; Mon, 26 Feb 2024 13:39:31 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id bn23-20020a056000061700b0033d1f25b798sm9512878wrb.82.2024.02.26.13.39.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 13:39:30 -0800 (PST) Message-ID: <9a4b5bf990bcddb2707207b7a523f0b9945d84a0.1708983566.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 26 Feb 2024 21:39:15 +0000 Subject: [PATCH v3 04/14] 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 , Torsten =?utf-8?q?B=C3=B6gershausen?= , 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 Mon Feb 26 21:39: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: 13572944 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.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 BA8FC131E3A for ; Mon, 26 Feb 2024 21:39:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708983575; cv=none; b=jCevzkZQiYEPf1OH8KZn8ACi81d8M9jzfbqHQP4gHfhTz/FafhDxiGkQbdiPCKSI5/Wak+WO33Tuzyq1aEV5TO4YLxeWxKtjGImgF7tSMS1W0QYViTgY+y98LFF6w6aHKcNoc3WBHCiRoLzotqAPgoaaQTVYOkQxv1V+8MlSBU0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708983575; c=relaxed/simple; bh=vLaZBMjrvVg999vONXdYrb0Ew9pRcJ3/fnEw03SQqT0=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=pBd/dOxPyIY7K9048pd/hH7EmYtVCoAqxlBdkU/w8I5M9VmHEf6Zy2h5Yg/JGeF5hYdVJjI8GX+cw3IAE9GGWbG9ONzzpo70zPJ2E8tARqzYH/8WNU5LNqdZgbWTPNv38AmMH6vJLhRizDJomwmS9uOf94jTC6tj2HowUEH60As= 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=AXoCSEJx; arc=none smtp.client-ip=209.85.221.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="AXoCSEJx" Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-33d754746c3so2436144f8f.1 for ; Mon, 26 Feb 2024 13:39:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708983572; x=1709588372; 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=Rg+rmbAbdVTzdJr+bM0adr1ATCJ2MMLlOmTLVcUc8eA=; b=AXoCSEJx5QGb1cXPUYQTByJIkCNQOM6dFlb+Y7j6MhSAjF+r4VdL4c31AX2l6teJ/b koN4cBLOix0CZ9JTqLGfQbB999hlR/XAaxt7TV2KvMhtvrB0mU9XBMOiOpYBePoM2esG r8VkrGUMvDAygeOFOK9BbpnMDNUublSv5adeVOF5MSSHewf5u/IXfJRPeo+XFbjuu3zd BcJOvHRpSib9i1kGWksY7b+Z3ieT515COQtJaCvn1R7S0Egw69q65MU1mmyqepGhI1YM DeWpe/CVyDJ66eoLc1O6duhDZoCczWgcbRpGJkbAJEj9oM+rTiRzULdFeqCtq0xK2XZh AaDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708983572; x=1709588372; 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=Rg+rmbAbdVTzdJr+bM0adr1ATCJ2MMLlOmTLVcUc8eA=; b=skAc2MShZEbA7tfrwPToFFCvORo1wyC5UMl/lBx7qd3rgUqgk2bxtreX0/SISDyx0k 1RnwwbOcY/B5B4UbnjjG8FMdw7zCrz0chnitux4+3ADGYVkmcJTGV20HfCI5po4KX0zm SRYfSARaf7h8NPKnXKbkMErXHeT5TETj8XR074v194q0hWJlhbJcZ/58emjxjZoJQyvr 9iraaSneC6akDlhPw11ph7V8AgWbvbcEbzFXMwbdGnUH0jNCVpLri2C4YciPTXeJuu3P biGjlw92xAEUbXHZDQn/9pZP6c/op67SMAoqi5xzcXlpHP3OvzmF6zixDGn4l30f1IM8 bA/A== X-Gm-Message-State: AOJu0YzEFVJQyfpbV6kbuVGe27+QmBiFXKmljnMgYmPo4MTXcezxZFw7 0kMF/x+9YzjFBW77JU2Kx8wNc+gz5WP5oE18Iq/EPUajiMyFHUNHALUOu8Hs X-Google-Smtp-Source: AGHT+IF0pu2yM/dVNyzx6lgYAN86AZIMUQ8ffrVciAGVs5V4/ibL/zDq0IQHajdHeQHGu7KHi5t9bA== X-Received: by 2002:adf:f78d:0:b0:33d:1656:21fa with SMTP id q13-20020adff78d000000b0033d165621famr6844761wrp.24.1708983571864; Mon, 26 Feb 2024 13:39:31 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id bs23-20020a056000071700b0033d5f5571b4sm9471196wrb.44.2024.02.26.13.39.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 13:39:31 -0800 (PST) Message-ID: <348b9b0c94e23d82f1df69b0b24b70d6cfb48a19.1708983566.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 26 Feb 2024 21:39:16 +0000 Subject: [PATCH v3 05/14] 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 , Torsten =?utf-8?q?B=C3=B6gershausen?= , Jeff Hostetler , Jeff Hostetler From: Jeff Hostetler From: Jeff Hostetler Move the code that handles 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 Mon Feb 26 21:39: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: 13572945 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 5A04C131E57 for ; Mon, 26 Feb 2024 21:39: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=1708983576; cv=none; b=A4HiWU2B5WDDRMAAh1K8WdClRAJWjITJnSxWB8CqT43CcZR5L9rvUbqtmOabhVAGVfcElQ6IwMVvbLv8COgGtFFlOx0XHPn/5TJl7ILsWaGw3sOA2ou6Xgz7Z2Jh4xg5kFeHkoeVTlnIG6EJxOEeS1nS1YclkOlKiNy9jCbeIbQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708983576; c=relaxed/simple; bh=pUzGHm4St4fqmQCNCQNAfBEF8BWjY/h1Tbq3KDHzyW4=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=kl4xNGiIEEL7gI5EbDLhPGuWkTYP7CVImpmuq6n8UKPA88PN/vPyw/7PjOlIVrjQNeds1Fq6VMMCmodhVak+CEjutwlrTJVNIilLHhVwcs2a+jvx/ZuoTOo7TjUfBF1kGyOonOStMJ88z+V3W7ygz/oAXWn0t52/INYRfs4B4VQ= 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=ErT8IMh2; 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="ErT8IMh2" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-40fd72f7125so28882145e9.1 for ; Mon, 26 Feb 2024 13:39:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708983572; x=1709588372; 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=txFVTpVywcZhgtkGGUVkhR9t/l/lhIwbfkCUpw21Y/U=; b=ErT8IMh2kgp8qAVUtxjs23iSZAB5AnNm+xgj5z8moCd+HCQQqmuL5tRw5QOgyHiE3O dmDm1P0mYvMMQ1dXqWM+E+F/1YysIuDeHTh5XBxRak71OP54qElMuRKB9kUD1tp1bBI7 uCK8Ns67cFZfGgu5F64KUIgqUKvSoXs+U5xfWoo1ip5oAiXC1vwLkAOcSJBi6ifLrlXZ vTVH3cfKr5WX4kJ/P5uqYpxg9IXLv94P+hyagD+D4+Iy2zrEyfMQmSL987HYkihM69bh A8ABqrIEVPlpqumzbCR0F3XXChAIY1RB8mBoYhAyk92Xe/n5O64H+Z+zwY0R4KlWx242 n5QA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708983572; x=1709588372; 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=txFVTpVywcZhgtkGGUVkhR9t/l/lhIwbfkCUpw21Y/U=; b=gLG4vQ7D7Dqgk4LQTt8qzTpOnSe8MwsvjsYkPYT4P9FKOY5W2mb6eKDfqEFGScOPiN jOfl0dNpylCL7fQX1F3OFXaaKOsJsQawPL7NRoxWmmyRhdr3sC6Bk84kJELixT8RLjd4 1bDqkeEnA3vgzGsfFn1L/l1KkBEOYvCj8Fn7OicZpkS0T03VX2lNV2pND98b6bT97XIS k0NIPndh99h0aajSh+KQqcreOGRiwQGOUPxQY31PNxvmJNcQDUGFmt3DtqhCG/nbnxSm CI8QizIj/NpNqskU6gQ2a3KVFN0spD6HOv2Zy22CUv0/ODcZq0v8m3AFm7qxqEeNVVGB xRmA== X-Gm-Message-State: AOJu0YzorocLvmoQVVQ7Q5yEexnGfmo6YaQoZWsntqyXfKJX6o9ADTHM xUCcLf5aww7/dF+msbYyOxtnfqYu/0mAwJg9bBtfDfXvLkEyo7zeYKE0t6ho X-Google-Smtp-Source: AGHT+IEiEjJVVkUpxGpj34azxnkeZPqgAjPGmzaAvEoO8MMyp9sS29tvrfqehoe/VipyHcOVgRgPmQ== X-Received: by 2002:a05:600c:4e86:b0:412:a20a:7d91 with SMTP id f6-20020a05600c4e8600b00412a20a7d91mr3838282wmq.8.1708983572552; Mon, 26 Feb 2024 13:39:32 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id t17-20020a05600c451100b00412a2060d5esm6374803wmo.23.2024.02.26.13.39.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 13:39:32 -0800 (PST) Message-ID: In-Reply-To: References: Date: Mon, 26 Feb 2024 21:39:17 +0000 Subject: [PATCH v3 06/14] 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 , Torsten =?utf-8?q?B=C3=B6gershausen?= , 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..20ebe4cba26 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) + BUG("untracked_cache_invalidate_trimmed_path given zero length path"); + + 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 Mon Feb 26 21:39: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: 13572946 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 2BD6012F593 for ; Mon, 26 Feb 2024 21:39:34 +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=1708983576; cv=none; b=sBOVz4kWmNjC7DulmXMb3jr01ZBttZPHxt469tFcUbqRQiJQ9d0jxLUXs9FWxZ03Y9GEd2b+4JA+YoYtRW0UjPe1wQTV6zh27oyiCLCo28mlS9VU9XkMAGN55n0SYKb06cExvHbWDkClihqGTmRgwaebQATJPyJXy0E5L1sS3eU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708983576; c=relaxed/simple; bh=DnjbJn5SgHmuTQJljNZYrS5EkVANHvKGjY/CNPBUE9A=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=VLSntsG6yupN+90XwrClEsV33M4IJEBGCfztUmS0V+Tax7Q61MB4ZD4BkXUo23BlpVA7GVBC+jblebbDQJLCpwI/rhAbvJgRYESV2Fjml0Sw8Kg3otY4IvkIm/99G6HUBG5gKfO2vWnzihJRLXyZPWt9EozDjBL2aGXAevuXuLM= 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=Xz/gsmjm; 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="Xz/gsmjm" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-41241f64c6bso28225455e9.0 for ; Mon, 26 Feb 2024 13:39:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708983573; x=1709588373; 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=Xz/gsmjmDJPfdgQlBXxpAXXJ/Cr7d5BldFo/rnrxhIgdDAItUFoFDBvEiiD0UKn6C7 HoFNDCXoU4dWjjrnTgiO9M56DnX6ElLANcfnKSB8mAUMJucmQlKvstfNMKN82lQXjLZG tII260VN1XFd0RM2mX091slrCWQ2NMC/etTy4dzikwibBZXIoWsQys6ONZDKw8TRbKsN gHZsLQSJI4bcX5KtBYN9c7jtEAHDrfVNpqh8fqmhM1n2+t20J/nYDKlURw/FhCzN857g N18mfs0He0dn+hA4FsbutTPnNASMs+V6oMbXZrVVdPvHIlQmszKbt99JriJrJ+i4bkFr vGKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708983573; x=1709588373; 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=VETQfPNMu3cyOiHxCX2q9yMptVolZ4GKW2cvtMsYzVzxWAIN9AVw9GGz/i59a2mjV6 LTiS+mIqwKgfeHd7GKbHSVlWOhpNQEC6YBK8MQB8dPypLE8SNBBj6OwmCFHkbJypqJGf 9dr/ktAoMHYPTFiOCK95DkSFQnldO00u8nQJn3Yu6lDltx2xxUVxm/f/xbDpyu+sac7f +3LNUUdwYq9uR9TukOZgvYJjW/GIFLWqCkd3HPWX/Uygysu6x+88istDKgew2fJs/Nqx LJYENxz12i3o51KyH91MJzie3/aDnx3PFgCoLlvueg0MRyzQcK5uc8zDnrfilFrG4Zj2 FTjw== X-Gm-Message-State: AOJu0Yx5PJMSs5EYgBZa9EFN0p1+IOVcw5q3glweLTwjC/wmxijSok+m zVHgrg7vldiPiIch/HXevj5b0TDLNVUgWNwswoDhJ4RCCCbAenZeE/FRpjY0 X-Google-Smtp-Source: AGHT+IG2HhPO+ZITPlqFRMAzSsDngEHFT4IxW3uryHaY00FJkkBwKFN2bcEuqJtKJw5f5JThY2XudQ== X-Received: by 2002:a05:600c:3145:b0:412:7941:e3df with SMTP id h5-20020a05600c314500b004127941e3dfmr6224435wmo.4.1708983573445; Mon, 26 Feb 2024 13:39:33 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id t17-20020a05600c451100b00412a2060d5esm6374823wmo.23.2024.02.26.13.39.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 13:39:32 -0800 (PST) Message-ID: <2a43c6cbe0dd5e3d343cb40ec040b7269379e5a4.1708983566.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 26 Feb 2024 21:39:18 +0000 Subject: [PATCH v3 07/14] 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 , Torsten =?utf-8?q?B=C3=B6gershausen?= , 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 Mon Feb 26 21:39: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: 13572947 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (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 DD6D813247F for ; Mon, 26 Feb 2024 21:39:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708983577; cv=none; b=DdkB6bxZAxC/EPBTeUkYx9wsfkXrVaVxcZeneijkwmmCNUtA2nhPt+YEacoHbOVpTjuvz2t32QfBqvFdCPct1Rl33bEQyQhRVrdGN+ak1Q026ypShnCAwAWhoQUyDmndZzzCfaFp8QbcVNhUPeWLF2mhEiNAue9VPTX4ybsakcU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708983577; c=relaxed/simple; bh=TLO66AmtwOfz78Qj2Kmaqv4Xx+maiMtu19gsi7os7ok=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=XN8vgn/sw+kdny36aYyUAzzd83bRMJN6FCPT7o04jfdJDJgKDsCyjEsOceEkpLfRP3CJVP4WfAFMJuL+wCBOlRx66tZKpr32fTp+oLRBtdNidBBlF15X6LNOa4dsPwJWwfg9Txb8difQw1CSIc5iXpmNCLkn1cizKILpALw3Zj0= 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=TcwlE4gT; arc=none smtp.client-ip=209.85.128.50 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="TcwlE4gT" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-412a882bd4eso7092185e9.1 for ; Mon, 26 Feb 2024 13:39:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708983574; x=1709588374; 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=cs333r5DxvVPPz6UqCmXUFq4KneCc8JolM5Vs8rcq5A=; b=TcwlE4gT1g6hMOG6xwLVJP54JMeMDI9aNVjkhuYLTe3hZo+sP/GYS4i6bTdDAY5mso mZt/9antCqUaxCa7/PWj+C4mhJhrcQlyERZMmcdaD59ZYXy9OI2wiVzTobbX9EZSNVJU CS2wXOIheBKJxQjNJNVwVySf43tXHs1JO5pKWXljMt0Q7CESeko6v4AnLZYyHMZkKnrY 6fNb4ZdzHVhelBSh0VMsrIk94jH3KsB9+Vo0ZIjylc3SvMhDtA91RjsD19tmJXVKfDzj 6i0k0sdsLe0j8NWC4yXxBb1QC/hY0h8CmJoq/7X5SyJcND3zs0SiL/WU76xEIki3nBc7 Spqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708983574; x=1709588374; 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=cs333r5DxvVPPz6UqCmXUFq4KneCc8JolM5Vs8rcq5A=; b=shI4QRboPjOL+wSaeNOkZo1bfWkTXuWhDoJrJJS3pmhVbUAKuUmqMjD63BEEQVt7dA mtQ7LuYOIwr+9KFthmYn09NonGjnTVGTjtHFLfNrnLz2qIGFR3tbgpchneBVleZOevgO Ag1SYP9oBAdgBhgXY9s+IY+IFCRRwGLk5h0JC5MRY+IEadIpbg2QRENAG9sQ23o49/q/ oZIK7lHhO2OzuuwTCeOSMlAly0wyZINS0XTfOIshkh01kQ4lgz3BiUYU+qryBv2vOvzu zGvt87ddVhukR2bISvHui5BqKy/9DslH/JWGcV03/PyTNQBtkisbiGxWYQu9RPUtE2Eg G7jQ== X-Gm-Message-State: AOJu0YxiLeyj3cJmFm3MLKIrRS8xrdI/qcuoD+xkTB62enr7DGNZD391 ffjZk+tNIctty1l7JlHYJ9cuYjVbbkrNrSc5l1uHO6bi+TkqSrcYxV9ZTx+T X-Google-Smtp-Source: AGHT+IFtGrk8Wx7sctBhX5atSg4Cpk2IYUoVCJHmLRUuTHBzabMNAQjn8+JGLN6M36Bd19fW6rqQIA== X-Received: by 2002:a05:600c:35d1:b0:412:a927:a646 with SMTP id r17-20020a05600c35d100b00412a927a646mr1285957wmq.24.1708983574125; Mon, 26 Feb 2024 13:39:34 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 10-20020a05600c028a00b004122aba0008sm9221155wmk.11.2024.02.26.13.39.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 13:39:33 -0800 (PST) Message-ID: <6e87ea6deafdb5f26e66925c5869d78c967af2dc.1708983566.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 26 Feb 2024 21:39:19 +0000 Subject: [PATCH v3 08/14] fsmonitor: move untracked-cache 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 , Torsten =?utf-8?q?B=C3=B6gershausen?= , 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 helpers than to remember to also add it to each helper call-site. This has the side-effect of invalidating the UC *before* we invalidate the ce_flags in the cache-entry. These activities are independent and do not affect each other. Also, by doing the UC work first, we can avoid worrying about "early returns" or the need for the usual "goto the end" in each of the handler functions. 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 Mon Feb 26 21:39: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: 13572948 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 49FB0132C06 for ; Mon, 26 Feb 2024 21:39:36 +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=1708983578; cv=none; b=XqVKDml2kH0rsGtpkV34ynlQV6+6fAufy8aiGh/pGbpJwcMNN7m3xE6/58AocGRVHFl172AqMaRlzMgjT55nxrqUpSuHU5T4lpBFRSEngiWWfxx9YbUaGQtIprD5pP7MZvdhlq+d7o9/QOlYXSYbwtoCcpQc8byC9r8GZkdqDfk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708983578; c=relaxed/simple; bh=FO2b0yim3Nlg5M5KqxmDX/ArS0hbUoaoFBZF9hZLt/8=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=LB7pVmthShuAgyE7dQYHXSe/DzZoJLaTr9GiidXdU3pqCk+y50er+i7h6wtI2ApcxN5Vvf9GW4abFgbIzGUqb43fda4Js9Kjo4+8AwqF6ADhZxm7eh2y9eu1yhSpAKoTvy78SDzTiLLmFmcaQB/RvA80uxnQpTgpo6Iy/jkzVjQ= 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=Lrd2n9rw; 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="Lrd2n9rw" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-412a4055897so12906165e9.3 for ; Mon, 26 Feb 2024 13:39:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708983575; x=1709588375; 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=Lrd2n9rwkNRPg1go67AW6VYr7owB8nVuoIFnxz+TvK98mgOK/JDVZXoixiEH6oWvfW qWASRXfV1mjfA4ClOmGj1dwMSQrTutuafm2xABI2QE2Gp+kPVBnYjwbF4BoNT/GrOCNQ LrhIyzx0dcaNOn02KyZU6QAm73YkYiTf8g8rRl6bvTIlVx6zb5X/h4rtPJ674X8qNHIv Z9BAZO75oisuZvwVFdegMFFmlmj08Dhcif4v7FaCuCUENuquB59gixnm4E2/n3WmyadM ALgM769kN7UAMBJzzIUrgjYlbl8pEAOFQRWubiw83mgsRoilMmCoXZAZ1KczI39s++0D D1lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708983575; x=1709588375; 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=akJhmuPKFLpfyYw6MP10GxjxE1BRqBNWvvvR0jv5OIlNFv3oyLXP+hzBudbq9StmNk dJqs14ZqizupmVB4sz/TYSV7T3aKjlBJKA/u2rOvAqpNE+USCAxagjLpRTq/bW+vmznx TaPNfFnYgNUUivOt/j5ssXkvqvpwsZHsqFNDNfSE+3S8HXlnoj/UTYVVQ3761o+D3fRz 5c9TupgcCChQaDE9Rtk4f8+BYa0GUmt3F0FLyXzTOmrhJ2Y3TyCQ8JS0uGEPHEjXqbZg 2aVJ3cwna+186/kiceLo+UgzDqkGE3Asy5IPbtvPQU56FkVc1kizBGU0h9tWHmUuL1+s BRyw== X-Gm-Message-State: AOJu0YxUTgemaAB25YecHaMe3v2zbM8GjSeWOOc9F5NeNhhkSEtGROpD o0ZrvB98GeMRn4rdXmQBpN6EUJU5DDMVfC6ri8YQHRZTwNR6bWPtXEULY4+I X-Google-Smtp-Source: AGHT+IFUfh5wxMnW00XpYU1pSffcpVuhy0/0zlCxonEkXcIAWQ8ZqFjIO4vx8vPNgxpHqsWQ74YdOw== X-Received: by 2002:a05:600c:2e04:b0:410:a039:ed5d with SMTP id o4-20020a05600c2e0400b00410a039ed5dmr7366878wmf.33.1708983574837; Mon, 26 Feb 2024 13:39:34 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id l15-20020a05600c1d0f00b00412a31d2e2asm5946163wms.32.2024.02.26.13.39.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 13:39:34 -0800 (PST) Message-ID: <5fea8b9476e6bf0e0635e886364f0d718deac97c.1708983566.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 26 Feb 2024 21:39:20 +0000 Subject: [PATCH v3 09/14] 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 , Torsten =?utf-8?q?B=C3=B6gershausen?= , 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 Mon Feb 26 21:39:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Hostetler X-Patchwork-Id: 13572949 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (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 CE75D132C12 for ; Mon, 26 Feb 2024 21:39:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708983579; cv=none; b=RGQ/9+C2eq6hnUN/M8BYBmGQ3xcCkR7G/Yn7CFLeAQkhlZ1hCUztZX9WXOYJM6Oa5Or75M4TQpKM1BENui/IxNe8t6iYmXls1THx47gdaRZoz0/A7IQECqASlmGmfq7/5jELjL0Aie3TH7NQwbl3u3ICdG572AFzZ+MUwpqzdQs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708983579; c=relaxed/simple; bh=+RJFxPxyhNAoSRYSOr0W3UbtUKn46L4I2/i53cfAsK8=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=rX39f++M5Rgdc+n4XH8XcejQjlSHeMlgO6HngzZr6zEjecr4p0x8Fe3R3tiPTkM0HrmSBJIz+d2J0FDXnt/KCBPnq+Drsg7TzQ6z+0P2DqK1Wl46E/s+Gs4vAzAblMYh97PxKSq4aRxo1b9355ApKVYJK7jMtKc4yqcb4Y75EOE= 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=Of0hoxWp; arc=none smtp.client-ip=209.85.128.52 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="Of0hoxWp" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-4129ed6f514so15183405e9.1 for ; Mon, 26 Feb 2024 13:39:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708983576; x=1709588376; 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=Of0hoxWpkoQqLH5N/rt5yqatPDfxBaE8bdgN4IexCho98WjIAYofhiPs/z/FpI2RBs avMRp/fJWhC757Fc+B7jhpsdnzXxTz3F3/ZJ4OtgMMOCWDD9Ye+Nzd01zy/5U1nXA0Op aPtTJkHl/xRG7Hr9zGbIpoxm5eDw3a7hmouVUfWJRgZvMmGDjwjl4is+Vue0Y5VrlCGb Wfl0Y3CxveWD9re3CoKCsDZfQAtSi6mQpIrgHfIF94g10pPRi4HP9faWUrJ2k2g8P+Ka 8JpbAKmTMt8NeD+/uceDy2ifMEt/Vefaj/08dPlzp3YJ7BzswfvWog7v3z7jE3HNJnp6 DlEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708983576; x=1709588376; 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=LrnkjmgXIgwnGXMcz08DJogF/3s6QsOX8JXhDqf2f2Q72OhHy63+w3+l8tDeeCQYqd pEsuXsB1JKquCtXrMvx0XRJQwQC8nRmy6I+N6BUlpDC+zmblA3wr25ksCF+n9wKP8G6c wtMdWzA5r0DkiT5H7ji74HsoYp4NgImUMxzGacLjcD7KRMpJW7jniUXH5+XL1PhkKdUB z4FByHjpf45IgMXfbuEYvUInf64kObX90dVHCqQQf13mjn7A9DOJ5QELm3fwdJiSM0a3 lljdQveHrchfdYK/RcddyL00gUdjiDvnZgkqLMP/Kvt5pTyeACSBOwRxROilHUMEh9fa Y48Q== X-Gm-Message-State: AOJu0YwwpYyI00SFlamBXCfysD0vvaR+BtQeebS10EmxKWB1cMij9aDD iabC7zLD5v/IMBDcgaudSx4fY2GUHfbbsJid2IR46VwxsCqhlEoDIbnJIClP X-Google-Smtp-Source: AGHT+IHxAQ9+OjS8exZ24gICmOhZqd9VFXn7283yoZGa0niLK6PbO6/zA/QJ3HFfrJ296UIChkLM9w== X-Received: by 2002:a05:600c:468f:b0:412:6404:45d2 with SMTP id p15-20020a05600c468f00b00412640445d2mr6179062wmo.28.1708983576003; Mon, 26 Feb 2024 13:39:36 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id i11-20020a05600c354b00b00412aae76435sm431040wmq.8.2024.02.26.13.39.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 13:39:35 -0800 (PST) Message-ID: <3fa7536cf8039c4e9324d9ea6d2b0e9ae4bbb10b.1708983566.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 26 Feb 2024 21:39:21 +0000 Subject: [PATCH v3 10/14] 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 , Torsten =?utf-8?q?B=C3=B6gershausen?= , 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 Mon Feb 26 21:39:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Hostetler X-Patchwork-Id: 13572950 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (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 B86C7132C24 for ; Mon, 26 Feb 2024 21:39:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708983580; cv=none; b=cXEokF9bY6Bo71pEj65U3UAJml5H7lhVPlODBz7gYIG0q0ZmCqkXP8GATpPbggqVJP9G5IB5woWAFatdLKLVFgX4klbd8cGIHUEk0BAxl/w62OVtbgx25c/i1UX+AgcVcuEjsXgN69hN6cR1CIouGzue6ZfdiXmYZyK4AbIlJJM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708983580; c=relaxed/simple; bh=vqm4G/xjIG6sSMGS8RrYC2EUdXZeDpDy+p41OkIjzo4=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=LkfxFmysGsbtXZJuCfthhxCV60tRAr+BxcyLmCjv+spln2Y0Fki3WTVXvAMW1WTif7qS3czKxCdLYKSrSMimKSjJjbCxsc9FuDRyAz/7uO6haGsP8gb0IRlIA86VTQOh4SQOJ9v8pZqv1yChZ5qZ3ynE57l/h5rmOfcuyklJ/hI= 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=XSYzlL7V; arc=none smtp.client-ip=209.85.128.50 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="XSYzlL7V" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-412a9f5f797so3341985e9.3 for ; Mon, 26 Feb 2024 13:39:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708983577; x=1709588377; 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=gvR0LWAdDaI2P27IRzGTNNd7zrRvg64gWm3EaqhZ+Ak=; b=XSYzlL7VgtSkDplPpNezGxobkW+BWR1yx7tZiO6UbnBtfyBy2KvcxyeDy+mtDRpjwl dI0pwGPbRiLDciGo2s+knUfM3sjy1rFofsQ/wR7U1qYl9cy4jKSOCgsWVc7DuvvZSjH5 7vFUwjlozsqdwSCn0WL0Mw4TFM0vtJ2BoKCnusGyjEQFLvZ0F9Z5gK5xaEvrV83CTTDs kplma2B26U6Mfdve5koeAglCSUsLu2+AWzLYhhrSgnmGFOXwvWcvByoILhtnklD1aXvm BufQMEyeD2zas64hiD2ILKIU+aoRK/70n2OHpxEKt0cvmj/RtEU8S93ErQUPSrupqFCu WwWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708983577; x=1709588377; 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=gvR0LWAdDaI2P27IRzGTNNd7zrRvg64gWm3EaqhZ+Ak=; b=BdT+2NID3f78omvijR7rceeQYo0TY36ExcdpoKFBxgI+WHv8jSJM4zs+mwVTZRWuZS w5wANu9CXyUsFtTkyOXakAaxIjW6oosQQUvl77Ux4iDRWz4M0n2ZfGzjq39mXef0qaSt 4f9u4DoCWOHtsL95S27AtCyRm/GgrmnVBtwthTTu4qQEcvbnkOGgBlPv0D0Rsp2GR9Ym vGRfnYICnd1wqhX475JmBY2LKRK2rnp8pflqdGeUAB895VYkSwqJCqWKycNU1KOFkPtS jekdsiwGEyfv4gmBRk6jPHZPRa60t1Ga4buAVGhZB2FHmambL52wSno+8bc32EnpieAO Q+5A== X-Gm-Message-State: AOJu0YwLK4lj1XyEAZ2PfABHxH987W0mjBXITCN9sei4U+VLgQ7LH5/9 eakiBcStqZh2CDSgTNPmkP6GvrL2w9LoXUfrtBPoo9SgLXX3oV1AmOFOu7iE X-Google-Smtp-Source: AGHT+IHDSw3ej0RmLwJOCCJVZLDzm2K/slPnGOQ0zjlmcVuXn0zYgU3y/LLoZEmslcHCsYw/wlsEXA== X-Received: by 2002:a05:600c:1394:b0:410:c25d:37e9 with SMTP id u20-20020a05600c139400b00410c25d37e9mr5965290wmf.16.1708983576778; Mon, 26 Feb 2024 13:39:36 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id jd17-20020a05600c68d100b004129335947fsm13092423wmb.8.2024.02.26.13.39.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 13:39:36 -0800 (PST) Message-ID: <53f73c1515d0f64bf13f0b30e9039dedbf441f2c.1708983566.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 26 Feb 2024 21:39:22 +0000 Subject: [PATCH v3 11/14] 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 , Torsten =?utf-8?q?B=C3=B6gershausen?= , Jeff Hostetler , Jeff Hostetler From: Jeff Hostetler From: Jeff Hostetler Teach 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 Mon Feb 26 21:39:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Hostetler X-Patchwork-Id: 13572951 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 6FF0B131754 for ; Mon, 26 Feb 2024 21:39:39 +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=1708983581; cv=none; b=WwJUFntXDS0AmPxXRR9W8Lgpi9UNiiAML07loxtfcWGqtG8AUfx+0hc38IOyepEe1hMvJJ/cK8/+VFOMplDm+nfxgiIFI5ZUL+C8j+fNeTPhQJZpNBIq44THvc5bOD8u3ItPhBUJoZnlAhjH4Flnw92Jl0F5idCRl8sXX4BLpFQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708983581; c=relaxed/simple; bh=5Lgbhcoa1/4GEjM3CIAFFdfrePzVAkkf5qUOn7ky13U=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=rGCbuXeeoL/Bdqu5VIX2xlJKloRav7xUPi56kKW8NAAuI2HLOZWgYTq/1sD7yYH9KamJNE0aJhlyrdSIWuhMpoqz4A3+62yw39nkEVQl/5y40Q7tem1u7X4qKbbx+I7J3n2s57fwQI4qQwfMChKEu36RfTQ6PRn+ZVB8QfGRNww= 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=JKxiTSY6; 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="JKxiTSY6" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-412a9457b2eso4937515e9.1 for ; Mon, 26 Feb 2024 13:39:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708983577; x=1709588377; 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=JKxiTSY60uezTeSA1B/lh8QmIn0cfYI02cBelJDO3KpEooDV33+PMT45kj8hHo9eTa nZ4LWa4tCR9QHwVB8T4uqh7xY+KWbsFT+9Kg7hJmItdCAmmTYOFl3lGnJd/kiYZEJm6Q OPtvHdy4/TdrysTaTDyE+49HjeQe4yuXLwc/GS3bJ/F+020KCjGtvI7Ru4Qousnl6zX6 g1OnkWjm2zu43xQn2FRbAhz90bFS/pgUihbem3mX5STIzzYRD+xIaGYKZoszwGcYp/Jo 2gkCbLfxb0uR2HwhnEg+tdOQVYmXxFTS3uJ1NftnMQ+eJwhrgX0FNXMvhcCvD9E/5c1T uk1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708983577; x=1709588377; 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=uRn+7CzZpraYKV6YWj1ZkqadPLAgo83515bHeJpEMxlsGJ3PORPOPDbUwUYTLtOHoC cBPttsZNjXgT6gAmem867VJ1AzdduXoEb8qSbg1JJYobwX/bXnN4SNuHTSVRVEyUItwT 0+P+ag52ypSdCp8hRgKRRbWsv0DTYCGOVKS7aIYocEIvpZq6qmhhSiMLKjV18R4Dbc8y RFvdBr7so4UarelkkG8VndAENPdSCqbXoKyNuWhanP45+Ok/QIZ2kKzlq21nDe1EaBZm 2xzB9ETK5tzbsrAB26xAf3lt3XSNF0ipU7k+b5r89Z/zjFJiwCvaJcNFsFWA2DDqQPrP YsOQ== X-Gm-Message-State: AOJu0YxKOyg3EyGmrebKZK5HLf/5xjviX91Ig098YMtQaCV+XzBhr5oi pX44OibEtoQAYWTNdHd2DPxDFYNzDilS0jfm9/dEDNu3eo0wV1arxKNw7Q/C X-Google-Smtp-Source: AGHT+IFxbJC2jR49/XGZFZJlLRDbaIi7urUPaO0hkcsoAbSvST3haqqpuupITOcqhwk1gQAC84wT4g== X-Received: by 2002:a05:600c:1c94:b0:412:a7d2:de8c with SMTP id k20-20020a05600c1c9400b00412a7d2de8cmr2488679wms.4.1708983577293; Mon, 26 Feb 2024 13:39:37 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id dq2-20020a0560000cc200b0033b483d1abcsm9310439wrb.53.2024.02.26.13.39.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 13:39:37 -0800 (PST) Message-ID: <0148319aea5cf32c454be9d1a0efc7934580d7a7.1708983566.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 26 Feb 2024 21:39:23 +0000 Subject: [PATCH v3 12/14] 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 , Torsten =?utf-8?q?B=C3=B6gershausen?= , 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 Mon Feb 26 21:39:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Hostetler X-Patchwork-Id: 13572952 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 7F32F133280 for ; Mon, 26 Feb 2024 21:39:40 +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=1708983582; cv=none; b=VOKOehjYD2lDbWRkoopfwpdMW76aUHlN306vClN0rEjVKsINodM4xf2cbvGlbK5Jrv33mU4TGfksOn12HyKZWGlsdZ2tufrSpIIJ0GGTWTEVa3PNpO/2C0QfAgCVYDHjqEViPYMvE/nl3acdTMzgO0bK2G1v81zVrMusPY5pKpo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708983582; c=relaxed/simple; bh=gRRNilQ4NfzviUPgUWCMC/cGQCPEDGiR5nSDcgst4XM=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=J9oNeCCqwf65JXSU4Q9LHSmjPv8wuv3nb/P1Ay3H4S980Q+9wX34K8sRA1fmbHHS68OwtfvFBlIno/jzkiHEkMqHFqedq61lSeyTkGXF6P82kjxQTh634BGZM+FvToBnQlufvtjN7gG3LsMCvXx65WZtarmx8wGkUiotD6BKwKk= 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=Rrsy+HOe; 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="Rrsy+HOe" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-412a9f5f797so3342285e9.3 for ; Mon, 26 Feb 2024 13:39:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708983578; x=1709588378; 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=9w5F+ig/Qh8/Pg1lF76hwLePYUCXgzP2kcrmcuAjXiI=; b=Rrsy+HOeX9B67S6zQNZXUccIzP5CFxOs0D88Xwq+tkPf4GiNOSof951ONMhV5TfY3M 6oVqY01T9FZHsOWUb5Isbezax3ytzczE7/C9Q7xOVsFKlrQv8jqTBRFb0vcHzP5yed1d ddRDO5rVa4RwKSxYFF4zh3LHvWcRs0gM8fpXG2nsSk4xWcK9H42XEX2k7r0tIZkgRVBI PmSQMDWv9jUbytbPgnK71FCoegLNJamalwsCDdClhb/iHC6Pprl5cebhFK8WiqWODRtd 8IlGW6hRaRVW6uDBcmEf+fQnEL/V4C0vITCmlLJ74II+0DKIHXTAruj9L719JY75HLEa lX+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708983578; x=1709588378; 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=9w5F+ig/Qh8/Pg1lF76hwLePYUCXgzP2kcrmcuAjXiI=; b=EEnGb1MzXQZAZ5JxrC2WRcoT575rrfw58Ve1i+iChicVKx171xlUProDsmtSBRqXuv YjarWodQz1qHiNp/VBl2745CaZ52cJSIGefA4/iVeLJgCKySvAU17nLW321w4CnOJThP akvcQyD0/xDKGaNux7aZhKpNP0DI7oYsKrllI8lPxjhed2FSnW5sqgk4/Nl/VTASwTyt vc1yBHHzxHS9WF92iVlF1r7KRltjDa2DjnPUk9vyvo58iV46+UmC6uqm4jv1Sw809qqf i3035wJDEfIHOC6f23CoZQ7FAPvX4M6PngeAA5Xl4jwk/xsJxSOS3dskVKrP9DkY7NpE 1UFQ== X-Gm-Message-State: AOJu0YwjD7S98N0f/z2oeSLNsTxGZUD4NEQfKnKefTFtwnPDhtXlqjYg IvpUXQjGVh0c/EcHcY1XZ6U5snR6nySxTi2nYBzZid2weq5ew9Fx9HBiMG1y X-Google-Smtp-Source: AGHT+IHMRhEISQux+omUlh5Z0FPmgHM8dUF5CIClTQeBkSw7GNiQ/g+u0JgL7jR8qwffj4qkTmVYjQ== X-Received: by 2002:a05:600c:5114:b0:412:9830:a259 with SMTP id o20-20020a05600c511400b004129830a259mr6202151wms.25.1708983578382; Mon, 26 Feb 2024 13:39:38 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id u20-20020a05600c00d400b00410b0ce91b1sm13073746wmm.25.2024.02.26.13.39.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 13:39:37 -0800 (PST) Message-ID: <04867eccfcd89e4a905899f6ee5f595396a4a9ea.1708983566.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 26 Feb 2024 21:39:24 +0000 Subject: [PATCH v3 13/14] 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 , Torsten =?utf-8?q?B=C3=B6gershausen?= , 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 it also does untracked-cache invalidation and we've already handled that in the refresh-callback handlers, so but we don't need to repeat that. Signed-off-by: Jeff Hostetler --- fsmonitor.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/fsmonitor.c b/fsmonitor.c index 739ddbf7aca..3c87449be87 100644 --- a/fsmonitor.c +++ b/fsmonitor.c @@ -183,6 +183,22 @@ static int query_fsmonitor_hook(struct repository *r, return result; } +/* + * Invalidate the FSM bit on this CE. This is like mark_fsmonitor_invalid() + * but we've already handled the untracked-cache, so let's not repeat that + * work. This also lets us have a different trace message so that we can + * see everything that was done as part of the refresh-callback. + */ +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; + } +} + static size_t handle_path_with_trailing_slash( struct index_state *istate, const char *name, int pos); @@ -219,7 +235,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; @@ -297,7 +313,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 Mon Feb 26 21:39:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Hostetler X-Patchwork-Id: 13572953 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.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 E5284132C24 for ; Mon, 26 Feb 2024 21:39:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708983583; cv=none; b=aaf3NjQ5qSsPP0gtTzm9ynMtgBtaUfiJP0DI9YmB8HPVLTIz35YJ0wE0VaLv6Cw6k0Kcuonvb1r1n8EsVhZMEax71J5qkjPCHq5wscFak8/y5KLsFPsmV8MFRsmN+4OniqLOOhUZkcVoD1jhP2EdvsKxt5n9PGKv2LbEivraONs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708983583; c=relaxed/simple; bh=LmURq/fYc3o5iG3U/tc+DgQkLzHIhlECUf1ER4VnfOY=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=LHrv0Jnso0PHIWcEpZkZ5SLvmaAaiLJsUWR9lyjdnGZr3hWIajgGAygzz2i7pcfep4dzL3HOd69QWb2rOuVuRjJtwSxBgqO6ftoqTJihMkE7CQ5sGI4RAIw7KL/JTgiZs+BjSO7f+y4Vr/3iQ2bz8N/4QmcZ2klH2SVU/ZWAFXQ= 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=FvBth2Rw; arc=none smtp.client-ip=209.85.221.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="FvBth2Rw" Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-33d6fe64a9bso2803982f8f.0 for ; Mon, 26 Feb 2024 13:39:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708983579; x=1709588379; 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=94by6VO7UCaTrwpJRPiFK1jluEdf+nYi5L2eeKTkkLo=; b=FvBth2RwP0NLyFZp2ozjzuFHAYtbmcrMMPVj2QX90/2fVNxkFOk4Spb8XqfdS0PVyd /YlMSs/1W/dT6Ql/sXjHOwZhqhJr51YUp61ASelkV3z/3Dc7oylF7Hbpg8eNj2ofMT+k MuPVg68/jpan1j1mRQhrxNzQ4XekwdZy/jO2aaNgWgFDrKr+8/axaJWBGcwglEN+w04k JREzFwfaOd2ZzuhdCuPlf3QzxuTH8m4YHulSEPEoR+YZBhgqffcuqaiMVUqD3aekL0HX vkLs2iKnmhWTUTYm5F9Ctohj8G81bTBxnxLVCMe/L6hEUk6jlpRqyWgq0rzn8fPVxuhz rMMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708983579; x=1709588379; 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=94by6VO7UCaTrwpJRPiFK1jluEdf+nYi5L2eeKTkkLo=; b=RWN5mhZtLagNvSAhAFM43ItoiIDyjhFDUOpvBWxwC2lrZAyLdVGG1Mrl4jveYSy2Le ov5Ey1MZZbYDOs5gWXSgwRoxiAS4g9qvjNuRdA0xMjS4zpPRrtmoZoKEmN/fW6EU+LAc MKgfEGKdbU6lfgubtdJf6F1UvV+Gb81plKq6byTgWmNtvfjrBrJdxfb7YsgQeT+tE6iH NQKTEa3P6DsziHAmTbF/Vf5cqPfvAcfgGCFrj3VGcbOQUG6TxohLMT7ZebPjwzzStMR/ 3G8kP0NYiJLlW2UHncL/+NyeLF0cnTFvePrKSY1C9Q3hD/nN0WhuW4IjU1adpB4py0SA 00fA== X-Gm-Message-State: AOJu0YwoGJsZ9Aug0ReB0ARMfUTP+0UA8DWgkZn7/F+y9e7im2W6xpwO hioof/YqBUGpmEkvQmzpEX6XJ/7Iz3vM+IpCqe3uUMwH3uOjgh77SAkcyBNK X-Google-Smtp-Source: AGHT+IGeRCpzUcBcfxGrH1hAc2iRBQc+m/fNQ9cNS/hKo8yBgYdOmC+F7YHpoernm9mwRM8EisGUfw== X-Received: by 2002:adf:ea81:0:b0:33d:74f2:820e with SMTP id s1-20020adfea81000000b0033d74f2820emr6662868wrm.30.1708983579534; Mon, 26 Feb 2024 13:39:39 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id ck19-20020a5d5e93000000b0033db9383e70sm9502014wrb.81.2024.02.26.13.39.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 13:39:38 -0800 (PST) Message-ID: In-Reply-To: References: Date: Mon, 26 Feb 2024 21:39:25 +0000 Subject: [PATCH v3 14/14] 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 , Torsten =?utf-8?q?B=C3=B6gershausen?= , 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. Also update t7527 to convert the "test_expect_failure" to "_success" now that we have fixed the bug. Signed-off-by: Jeff Hostetler --- fsmonitor.c | 121 +++++++++++++++++++++++++++++++++++ t/t7527-builtin-fsmonitor.sh | 26 +++++--- 2 files changed, 137 insertions(+), 10 deletions(-) diff --git a/fsmonitor.c b/fsmonitor.c index 3c87449be87..2b17d60bbbe 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" @@ -202,6 +203,113 @@ static void invalidate_ce_fsm(struct cache_entry *ce) 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); + + /* + * NEEDSWORK: We used the name-hash to find the correct + * case-spelling of the pathname in the cache-entry[], so + * technically this is a tracked file or a sparse-directory. + * It should not have any entries in the untracked-cache, so + * we should not need to use the case-corrected spelling to + * invalidate the the untracked-cache. So we may not need to + * do this. For now, I'm going to be conservative and always + * do it; we can revisit this later. + */ + untracked_cache_invalidate_trimmed_path(istate, ce->name, 0); + + invalidate_ce_fsm(ce); + 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 because we should never get here. Or we + * could just get rid of the memcmp() and this "if" + * clause completely. + */ + BUG("handle_using_dir_name_hash_icase(%s) did not exact match", + name); + } + + 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 @@ -335,6 +443,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", diff --git a/t/t7527-builtin-fsmonitor.sh b/t/t7527-builtin-fsmonitor.sh index 830f2d9de33..730f3c7f810 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_failure 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,19 @@ test_expect_failure CASE_INSENSITIVE_FS 'fsmonitor subdir case wrong on disk' ' grep -q "dir1/DIR2/dir3/file3.*pos -3" "$PWD/subdir_case_wrong.log1" && + # 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" && - - # Expect Breakage: with the case confusion, the "(pos -3)" causes - # the client to not clear the CE_FSMONITOR_VALID bit and therefore - # status will not rescan the file and therefore not report it as dirty. grep -q " M dir1/dir2/dir3/file3" "$PWD/subdir_case_wrong.out" ' -test_expect_failure 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 && @@ -1242,14 +1242,20 @@ test_expect_failure CASE_INSENSITIVE_FS 'fsmonitor file case wrong on disk' ' 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" && + + # 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" && + # 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" && - # Expect Breakage: with the case confusion, the "(pos-3)" and - # "(pos -9)" causes the client to not clear the CE_FSMONITOR_VALID - # bit and therefore status will not rescan the files and therefore - # not report them as dirty. + # 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 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" '