From patchwork Tue Feb 13 20:52:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Hostetler X-Patchwork-Id: 13555656 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 3F1CF612EC for ; Tue, 13 Feb 2024 20:52:25 +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=1707857546; cv=none; b=nPEhRxd6YEA2JGkjdsj46KFSPqIDUSnexA24TSif5W6sY5/J8ZyHj5Ai0pPbzuLtbcXZAUMpOASvXZfEKEowvUZnpeGuyDgn0kpSt7Cnh7c7FtiQegy8NbgW+XG3D6R8jt+lUa4v8fOPvWzAXwzFzLBIAJOin1N5VPen1u8o+qc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707857546; c=relaxed/simple; bh=EUc5rgoq4yi8o5yD46T49ngtB9a6K3EdLV7gMQcfuEc=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=G6xLmfmDCMBF4tBqSqILp2nXE6t//j/gDiS+sOzdLlbM5rhOQvmcClWiMuQM4LmBpOXCVdKOs4Ia5ASap7x/q6l/pSJraDTFCbpc0w9W4q9pQzyStGKsbIaJ+TFt3mtb+nWNvGfNCxgLNSek3irq+a8ug8mBZVchh9I2hSCmiW8= 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=m0dbxaAT; 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="m0dbxaAT" Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-33b2960ff60so73148f8f.1 for ; Tue, 13 Feb 2024 12:52:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707857543; x=1708462343; 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=0v57pdx67w0xZeq4XL1V/YbQqa+hYrAiuY6uDw3GUhs=; b=m0dbxaATQw7SZwzdXxUocdwc09ePc/aGPKWnlbVgfE8YO5SwAE5rc5QYXVfBFiAn2z oXKwe0GjZWCXArqGvsdzjx1a+KqOC9Ke/VaNkDzHzhOIVRNNH54xH/TNiuG/l1JSdD8P zf6tyX9gK4je1LmlIFEdvIhLZBApNLM0aHxuuL/nX5qbi3nxiAD8h536BaWmBJvhAlA9 Cmb60B02qUHcunRQxKN8tRJfgezeYDU2uIQXOCzQL+8ugvm/Q/khkT+wyopjrZ8kZxE5 yAVEx0ya+3PuY4IpfbngiTSBz4v23kKX3j/MXnd9TqBveDYHUjEXW/7FR9P5oTs5KwLa LWPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707857543; x=1708462343; 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=0v57pdx67w0xZeq4XL1V/YbQqa+hYrAiuY6uDw3GUhs=; b=TF+cwXCP8wwkuvGtznPY2DxUMssLCASshuMUojTuYIPvhy7Cn1jvu0BAOOPdtIrcP0 Orz0FExfC+6mX+R0Z0OZtBi5oqcmSY2K1Qs6AIIlmFkeeX7wCTCVTH9dsCey/7Xk8AHt VZo3eeFSr3Kv3fAnQWc5dQiPuou9bh9kRigxBvnM+GqgA2cdi40XMU3zZk+nsuG6LE4B PKwHdEOFJudJZuwhGap4XNh3LGTgPAoOexcu7432KJQSZRuZN3frWSJN0cMssUa5XCGP c/9vg239cIZIOWIC3WLCpSJHJfo/k9yUZ1Mo9+lBwqWw6kDGdBhqM8jPS1Aqy/tKFjDw iQeQ== X-Gm-Message-State: AOJu0YyEaxQPkFg9IzUXg4sJr1zPNcRaRjCwKDxfTL98HuowLIx45SL1 Qhtm+fPmy9+dHQiH5CmNxRn2FKl4GtfLeUE6IItRSpor6wEmlIXIbDdQKWwL X-Google-Smtp-Source: AGHT+IGmD1GTgZS0dCHh+vmQAV2STg7GYGXEo4ffszzBRW8ASfMbRPLrPFjCL5+NGNzXuqk5UAb8Ow== X-Received: by 2002:a5d:45d0:0:b0:33c:d852:8e55 with SMTP id b16-20020a5d45d0000000b0033cd8528e55mr2126wrs.1.1707857543212; Tue, 13 Feb 2024 12:52:23 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id s8-20020adfecc8000000b0033b671f079dsm10344367wro.115.2024.02.13.12.52.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 12:52:23 -0800 (PST) Message-ID: <6f81e2e30609c70d4dcdbe9d4f11c4f6b5173c77.1707857541.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 13 Feb 2024 20:52:10 +0000 Subject: [PATCH 01/12] sparse-index: pass string length to index_file_exists() 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: Jeff Hostetler , Jeff Hostetler From: Jeff Hostetler From: Jeff Hostetler The call to index_file_exists() in the loop in expand_to_path() passes the wrong string length. Let's fix that. The loop in expand_to_path() searches the name-hash for each sub-directory prefix in the provided pathname. That is, by searching for "dir1/" then "dir1/dir2/" then "dir1/dir2/dir3/" and so on until it finds a cache-entry representing a sparse directory. The code creates "strbuf path_mutable" to contain the working pathname and modifies the buffer in-place by temporarily replacing the character following each successive "/" with NUL for the duration of the call to index_file_exists(). It does not update the strbuf.len during this substitution. Pass the patched length of the prefix path instead. Signed-off-by: Jeff Hostetler --- sparse-index.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sparse-index.c b/sparse-index.c index 3578feb2837..e48e40cae71 100644 --- a/sparse-index.c +++ b/sparse-index.c @@ -579,8 +579,9 @@ void expand_to_path(struct index_state *istate, replace++; temp = *replace; *replace = '\0'; + substr_len = replace - path_mutable.buf; if (index_file_exists(istate, path_mutable.buf, - path_mutable.len, icase)) { + substr_len, icase)) { /* * We found a parent directory in the name-hash * hashtable, because only sparse directory entries @@ -593,7 +594,6 @@ void expand_to_path(struct index_state *istate, } *replace = temp; - substr_len = replace - path_mutable.buf; } cleanup: From patchwork Tue Feb 13 20:52:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Hostetler X-Patchwork-Id: 13555657 Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2D99661664 for ; Tue, 13 Feb 2024 20:52:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707857548; cv=none; b=UvBFel2zxEFhI4TTgSu9kaAAER4An+asgwqP433uGs3glmwcm/l4nsobg3PoeBxD888hm+dB312R+jrfzcVCZe2cntGLpzdb5yyYDjk7RXFZsnSmfDzSJwa177r6nbfFbwtT/ep9S+cnBwVCdRYRcOScxu6Bfg5OB7PUTZafe9M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707857548; c=relaxed/simple; bh=IR8eqPDa/F5VetSJPo06qDYzDIC2LWswTrMTPwfxyFc=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=dTO6dTHSL7fZVbI+d0sOOksYTm+yNdgE3qADxdEy+QorFWZTlyn6xDN7QVKqb8Dk8N+ChrgQRPtPizz+Q6mWzMxtQYoXa3ft5Pxp2nJcRmskGoDHAHNCagxQFDZHoGk8LEQCHfebQz5gj4fkQNmZ2YXIajNCK+eaXGkjR5dAULs= 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=JikCt7La; arc=none smtp.client-ip=209.85.208.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JikCt7La" Received: by mail-lj1-f177.google.com with SMTP id 38308e7fff4ca-2d0c7e6b240so65756401fa.0 for ; Tue, 13 Feb 2024 12:52:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707857544; x=1708462344; 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=8FfJ8OLbW0SLI3KnEqx8Hdgwz9ENLAvM+QmJC0JSTDs=; b=JikCt7LaFFxXYL6RYjyV5zRmVthsMe2I1bIlHPr3bmFWNYS77rvmLw5ZwqA7uvTswm zUkCT1Qm8OGC97Lk5gZy7toQph6Mvjc/5ELOhPoxonyFQnz6Pqp2YSjQVa6FWi0oE29Q KLYYiR8wXX843LONkHwPBgQjrHFV8xMqGwfXtjTV9XT9TvEEG1DoHex30z2SCicSXfFr n0g1Np4EMZDDHO1DhSDXxTXkRu5xazarFc1wl1TeTONqhREdOOT2B2gXK8sJsJpY/0Om POhjoEYvQNG8sCfLB8Oy4+PWyNOSqYB1T1eoNhvp41YqDzSkJokVdzrTqvuESK6iVvUP a81Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707857544; x=1708462344; 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=8FfJ8OLbW0SLI3KnEqx8Hdgwz9ENLAvM+QmJC0JSTDs=; b=RMM2c8He9XsrsizuvxLOVlyxP7uSzR5ndgyCTkJj5DjD9F0BTRz1TjVcDxjglmAC0e EwAHBJkl0YZx8ELrct/kSqgcUDLkWd54iAq8gSUTx9+K5AtcZIOIrJwCIxEPSj9ZOn4V Fw4dRZ89jAiLYCdOK8xztrcSk328y674PlZVyQ3YHqOB8ppsytbg+TMj6bQsuVvIXdQY bmzG7DyFwGB6fQCvYcZTcaD2LDg6IVDaN1/QrOcLpmQVI6BM4FkluYogznZfB3WIrvSF NsbLCTQby/ko0keDGKIaL4Xi9NK6EjNKlDXs8QDGKXTIGRqu6W+iOm7wuQ2NPex3lgc8 Q/Vg== X-Gm-Message-State: AOJu0YwxJAzK1sPBlFqzeNY8gr+gCFPYCGOS6v+BBY6JIZEhlnjG86U/ bk3OV34zqaMJU2SGGJsl+Iv8PAK9zzYYlQEXVpWeOa+yMmZG1e5BVuDERDzi X-Google-Smtp-Source: AGHT+IG8/wsXwGlfdOXMvwcrA2it7RBLwZ38CE857dXTpg7DDIGlNCclLAd7HU5YCx1gfo3Ntk7ycw== X-Received: by 2002:a2e:8e2f:0:b0:2d0:de6f:c697 with SMTP id r15-20020a2e8e2f000000b002d0de6fc697mr462739ljk.13.1707857544103; Tue, 13 Feb 2024 12:52:24 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id dn7-20020a05600c654700b00411b7c91470sm2961404wmb.12.2024.02.13.12.52.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 12:52:23 -0800 (PST) Message-ID: <3464545fe3feceb08408618c77a70cc95745bfe9.1707857541.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 13 Feb 2024 20:52:11 +0000 Subject: [PATCH 02/12] name-hash: add index_dir_exists2() 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: Jeff Hostetler , Jeff Hostetler From: Jeff Hostetler From: Jeff Hostetler Create a new version of index_dir_exists() to return the canonical spelling of the matched directory prefix. The existing index_dir_exists() returns a boolean to indicate if there is a case-insensitive match in the directory name-hash, but it doesn't tell the caller the exact spelling of that match. The new version also copies the matched spelling to a provided strbuf. This lets the caller, for example, then call index_name_pos() with the correct case to search the cache-entry array for the real insertion position. Signed-off-by: Jeff Hostetler --- name-hash.c | 16 ++++++++++++++++ name-hash.h | 2 ++ 2 files changed, 18 insertions(+) diff --git a/name-hash.c b/name-hash.c index 251f036eef6..d735c81acb3 100644 --- a/name-hash.c +++ b/name-hash.c @@ -694,6 +694,22 @@ int index_dir_exists(struct index_state *istate, const char *name, int namelen) dir = find_dir_entry(istate, name, namelen); return dir && dir->nr; } +int index_dir_exists2(struct index_state *istate, const char *name, int namelen, + struct strbuf *canonical_path) +{ + struct dir_entry *dir; + + strbuf_init(canonical_path, namelen+1); + + lazy_init_name_hash(istate); + expand_to_path(istate, name, namelen, 0); + dir = find_dir_entry(istate, name, namelen); + + if (dir && dir->nr) + strbuf_add(canonical_path, dir->name, dir->namelen); + + return dir && dir->nr; +} void adjust_dirname_case(struct index_state *istate, char *name) { diff --git a/name-hash.h b/name-hash.h index b1b4b0fb337..2fcac5c4870 100644 --- a/name-hash.h +++ b/name-hash.h @@ -5,6 +5,8 @@ struct cache_entry; struct index_state; int index_dir_exists(struct index_state *istate, const char *name, int namelen); +int index_dir_exists2(struct index_state *istate, const char *name, int namelen, + struct strbuf *canonical_path); 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 Tue Feb 13 20:52: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: 13555658 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.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 809C36166C for ; Tue, 13 Feb 2024 20:52:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707857549; cv=none; b=No101jjPmYa47icVTV3AVzkNkqZVDKh5UMvhnuo5SC2y5vATfDZhPbOXn4H8xGvZmAALXi1vwZSVkkEL9dn/gyaQcg0Oqo4Zy27HPlsZA/hEaSNpuYSvh+TGzPjMVVIGnbVNaUu6Gq5hCCj1nlxmXPIlfRKRSD1ZupCBt1cx00Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707857549; c=relaxed/simple; bh=S5phN8Hlc5vBvd0hrMsO7F2b3Nnsb4LiMxYSfGO/L9I=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=MX8daewC4YQMB+9x+FOHCYz6gDiNy3u9jNGW9MjWPGeBWYkQwq/PFxTqZ9Dny2Vgir6QOZ/WcKmmyxQ1Xxrv3wxa86lO5ehbDwW359dPihzO8WCu9N7i9HKxHGBqrAMEf/49lZoon5RTmMT9yYQMjq7U8rqxVaYDIZdKpSlVZkE= 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=G6jgVkaF; arc=none smtp.client-ip=209.85.221.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="G6jgVkaF" Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-33b28aadb28so2988358f8f.3 for ; Tue, 13 Feb 2024 12:52:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707857545; x=1708462345; 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=+Wy3UHChN83kaQEHB7S50UnwXtOlgoAl9Atri6eSrxM=; b=G6jgVkaFSxJKqsP2RsqKNpwEcccFvQ7j4noFdhlDjCMzVgBtCV67loXXot0E/Yvbuu VCi7QHYK5Oy9zWVv1lTaLc0sN+u1qN8mQPoklKrw3BubldQQktdlI8Om1SxXFxwHxrVt zStogBjC7/zOFysENuo7Ep9MVWKDs6RttKcq8agvUHjZyBtyd08Ao0Ge2gYLiZCojIi0 VbIEQkTERZj5TrJrKIrjpQHrXNfidwRqOFYzc3Sad/NLPDfh+I1v5RJK6A+9COSrwx5/ upYofPX/hp6ZrXsevO+T0G55h346fUJ3VDpwP6pbJv/cxXufNJNRzrEcBj+nxO3dqpj1 xwZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707857545; x=1708462345; 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=+Wy3UHChN83kaQEHB7S50UnwXtOlgoAl9Atri6eSrxM=; b=H6798mO6GbSe5j/lbIm3xw2aMuMJK+3EmWbx/2v9MTkz/FcZPcMHuGGJsWY29+ft28 LJ2XLa4w3ZahaQQkh5g4DWMkrXKubhglHwPuoXGdwJc7jkjoY0j+Vysyp6GMPmbXV1Rg +ssmnV0AwqPo/lJhJRPE+m3oo415Gf2a+5nlOc3ymhPwAGSXsWCRfBG2eXsEjwmK00FA h2wFxrFzy7bpSoNPsZD5YAPNGn/CuZMGza+hjKBrV4S4XI5dqMls0KEudMpHw0npS5Ob aHpstNDfGYImIbROJ2tDg6N/WoWY4DRR12c8dhDXx3+67CtTYAgWJGHkiOsFu1EZFW/V tCVQ== X-Gm-Message-State: AOJu0YzykPJBMR4X2Cs4kGiC6FJ7N0tO7Q50ad256Dc1FW8Ag1I6Rxkk H8l/Z1/3B6VMM+tkY6tsT+uq0xIA/2xlK8LAmOZB+mqYpXG28nXejcnIsfzV X-Google-Smtp-Source: AGHT+IGphAIsVLW8ZtlzHBNtPKzpLeI9iNhUq7eTgRylFJtirmEkKRBg9gycFkPgD+d+4YEGzfvm0g== X-Received: by 2002:adf:fe8d:0:b0:33b:39d6:666d with SMTP id l13-20020adffe8d000000b0033b39d6666dmr314576wrr.36.1707857544769; Tue, 13 Feb 2024 12:52:24 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id r2-20020a056000014200b0033b4acb999dsm10357510wrx.98.2024.02.13.12.52.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 12:52:24 -0800 (PST) Message-ID: <272d7805f474411bd30aee8a55f497d6689afb57.1707857541.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 13 Feb 2024 20:52:12 +0000 Subject: [PATCH 03/12] 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: 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 78503158fd6..5cd68b2ea82 100755 --- a/t/t7527-builtin-fsmonitor.sh +++ b/t/t7527-builtin-fsmonitor.sh @@ -1037,4 +1037,221 @@ test_expect_success 'split-index and FSMonitor work well together' ' ) ' +# The FSMonitor daemon reports the OBSERVED pathname of modified files +# and thus contains the OBSERVED spelling on case-insensitive file +# systems. The daemon does not (and should not) load the .git/index +# file and therefore does not know the expected case-spelling. Since +# it is possible for the user to create files/subdirectories with the +# incorrect case, a modified file event for a tracked will not have +# the EXPECTED case. This can cause `index_name_pos()` to incorrectly +# report that the file is untracked. This causes the client to fail to +# mark the file as possibly dirty (keeping the CE_FSMONITOR_VALID bit +# set) so that `git status` will avoid inspecting it and thus not +# present in the status output. +# +# The setup is a little contrived. +# +test_expect_success CASE_INSENSITIVE_FS 'fsmonitor subdir case wrong on disk' ' + test_when_finished "stop_daemon_delete_repo subdir_case_wrong" && + + git init subdir_case_wrong && + ( + cd subdir_case_wrong && + echo x >AAA && + echo x >BBB && + + mkdir dir1 && + echo x >dir1/file1 && + mkdir dir1/dir2 && + echo x >dir1/dir2/file2 && + mkdir dir1/dir2/dir3 && + echo x >dir1/dir2/dir3/file3 && + + echo x >yyy && + echo x >zzz && + git add . && + git commit -m "data" && + + # This will cause "dir1/" and everything under it + # to be deleted. + git sparse-checkout set --cone --sparse-index && + + # Create dir2 with the wrong case and then let Git + # repopulate dir3 -- it will not correct the spelling + # of dir2. + mkdir dir1 && + mkdir dir1/DIR2 && + git sparse-checkout add dir1/dir2/dir3 + ) && + + start_daemon -C subdir_case_wrong --tf "$PWD/subdir_case_wrong.trace" && + + # Enable FSMonitor in the client. Run enough commands for + # the .git/index to sync up with the daemon with everything + # marked clean. + git -C subdir_case_wrong config core.fsmonitor true && + git -C subdir_case_wrong update-index --fsmonitor && + git -C subdir_case_wrong status && + + # Make some files dirty so that FSMonitor gets FSEvents for + # each of them. + echo xx >>subdir_case_wrong/AAA && + echo xx >>subdir_case_wrong/dir1/DIR2/dir3/file3 && + echo xx >>subdir_case_wrong/zzz && + + GIT_TRACE_FSMONITOR="$PWD/subdir_case_wrong.log" \ + git -C subdir_case_wrong --no-optional-locks status --short \ + >"$PWD/subdir_case_wrong.out" && + + # "git status" should have gotten file events for each of + # the 3 files. + # + # "dir2" should be in the observed case on disk. + grep "fsmonitor_refresh_callback" \ + <"$PWD/subdir_case_wrong.log" \ + >"$PWD/subdir_case_wrong.log1" && + + grep -q "AAA.*pos 0" "$PWD/subdir_case_wrong.log1" && + grep -q "zzz.*pos 6" "$PWD/subdir_case_wrong.log1" && + + grep -q "dir1/DIR2/dir3/file3.*pos -3" "$PWD/subdir_case_wrong.log1" && + + # The refresh-callbacks should have caused "git status" to clear + # the CE_FSMONITOR_VALID bit on each of those files and caused + # the worktree scan to visit them and mark them as modified. + grep -q " M AAA" "$PWD/subdir_case_wrong.out" && + grep -q " M zzz" "$PWD/subdir_case_wrong.out" && + + # However, with the fsmonitor client bug, the "(pos -3)" causes + # the client to not update the bit and never rescan the file + # and therefore not report it as dirty. + ! grep -q " M dir1/dir2/dir3/file3" "$PWD/subdir_case_wrong.out" +' + +test_expect_success CASE_INSENSITIVE_FS 'fsmonitor file case wrong on disk' ' + test_when_finished "stop_daemon_delete_repo file_case_wrong" && + + git init file_case_wrong && + ( + cd file_case_wrong && + echo x >AAA && + echo x >BBB && + + mkdir dir1 && + mkdir dir1/dir2 && + mkdir dir1/dir2/dir3 && + echo x >dir1/dir2/dir3/FILE-3-B && + echo x >dir1/dir2/dir3/XXXX-3-X && + echo x >dir1/dir2/dir3/file-3-a && + echo x >dir1/dir2/dir3/yyyy-3-y && + mkdir dir1/dir2/dir4 && + echo x >dir1/dir2/dir4/FILE-4-A && + echo x >dir1/dir2/dir4/XXXX-4-X && + echo x >dir1/dir2/dir4/file-4-b && + echo x >dir1/dir2/dir4/yyyy-4-y && + + echo x >yyy && + echo x >zzz && + git add . && + git commit -m "data" + ) && + + start_daemon -C file_case_wrong --tf "$PWD/file_case_wrong.trace" && + + # Enable FSMonitor in the client. Run enough commands for + # the .git/index to sync up with the daemon with everything + # marked clean. + git -C file_case_wrong config core.fsmonitor true && + git -C file_case_wrong update-index --fsmonitor && + git -C file_case_wrong status && + + # Make some files dirty so that FSMonitor gets FSEvents for + # each of them. + echo xx >>file_case_wrong/AAA && + echo xx >>file_case_wrong/zzz && + + # Rename some files so that FSMonitor sees a create and delete + # FSEvent for each. (A simple "mv foo FOO" is not portable + # between macOS and Windows. It works on both platforms, but makes + # the test messy, since (1) one platform updates "ctime" on the + # moved file and one does not and (2) it causes a directory event + # on one platform and not on the other which causes additional + # scanning during "git status" which causes a "H" vs "h" discrepancy + # in "git ls-files -f".) So old-school it and move it out of the + # way and copy it to the case-incorrect name so that we get fresh + # "ctime" and "mtime" values. + + mv file_case_wrong/dir1/dir2/dir3/file-3-a file_case_wrong/dir1/dir2/dir3/ORIG && + cp file_case_wrong/dir1/dir2/dir3/ORIG file_case_wrong/dir1/dir2/dir3/FILE-3-A && + rm file_case_wrong/dir1/dir2/dir3/ORIG && + mv file_case_wrong/dir1/dir2/dir4/FILE-4-A file_case_wrong/dir1/dir2/dir4/ORIG && + cp file_case_wrong/dir1/dir2/dir4/ORIG file_case_wrong/dir1/dir2/dir4/file-4-a && + rm file_case_wrong/dir1/dir2/dir4/ORIG && + + # Run status enough times to fully sync. + # + # The first instance should get the create and delete FSEvents + # for each pair. Status should update the index with a new FSM + # token (so the next invocation will not see data for these + # events). + + GIT_TRACE_FSMONITOR="$PWD/file_case_wrong-try1.log" \ + git -C file_case_wrong status --short \ + >"$PWD/file_case_wrong-try1.out" && + grep -q "fsmonitor_refresh_callback.*FILE-3-A.*pos -3" "$PWD/file_case_wrong-try1.log" && + grep -q "fsmonitor_refresh_callback.*file-3-a.*pos 4" "$PWD/file_case_wrong-try1.log" && + grep -q "fsmonitor_refresh_callback.*FILE-4-A.*pos 6" "$PWD/file_case_wrong-try1.log" && + grep -q "fsmonitor_refresh_callback.*file-4-a.*pos -9" "$PWD/file_case_wrong-try1.log" && + + # FSM refresh will have invalidated the FSM bit and cause a regular + # (real) scan of these tracked files, so they should have "H" status. + # (We will not see a "h" status until the next refresh (on the next + # command).) + + git -C file_case_wrong ls-files -f >"$PWD/file_case_wrong-lsf1.out" && + grep -q "H dir1/dir2/dir3/file-3-a" "$PWD/file_case_wrong-lsf1.out" && + grep -q "H dir1/dir2/dir4/FILE-4-A" "$PWD/file_case_wrong-lsf1.out" && + + + # Try the status again. We assume that the above status command + # advanced the token so that the next one will not see those events. + + GIT_TRACE_FSMONITOR="$PWD/file_case_wrong-try2.log" \ + git -C file_case_wrong status --short \ + >"$PWD/file_case_wrong-try2.out" && + ! grep -q "fsmonitor_refresh_callback.*FILE-3-A.*pos" "$PWD/file_case_wrong-try2.log" && + ! grep -q "fsmonitor_refresh_callback.*file-3-a.*pos" "$PWD/file_case_wrong-try2.log" && + ! grep -q "fsmonitor_refresh_callback.*FILE-4-A.*pos" "$PWD/file_case_wrong-try2.log" && + ! grep -q "fsmonitor_refresh_callback.*file-4-a.*pos" "$PWD/file_case_wrong-try2.log" && + + # FSM refresh saw nothing, so it will mark all files as valid, + # so they should now have "h" status. + + git -C file_case_wrong ls-files -f >"$PWD/file_case_wrong-lsf2.out" && + grep -q "h dir1/dir2/dir3/file-3-a" "$PWD/file_case_wrong-lsf2.out" && + grep -q "h dir1/dir2/dir4/FILE-4-A" "$PWD/file_case_wrong-lsf2.out" && + + + # We now have files with clean content, but with case-incorrect + # file names. Modify them to see if status properly reports + # them. + + echo xx >>file_case_wrong/dir1/dir2/dir3/FILE-3-A && + echo xx >>file_case_wrong/dir1/dir2/dir4/file-4-a && + + GIT_TRACE_FSMONITOR="$PWD/file_case_wrong-try3.log" \ + git -C file_case_wrong --no-optional-locks status --short \ + >"$PWD/file_case_wrong-try3.out" && + # FSEvents are in observed case. + grep -q "fsmonitor_refresh_callback.*FILE-3-A.*pos -3" "$PWD/file_case_wrong-try3.log" && + grep -q "fsmonitor_refresh_callback.*file-4-a.*pos -9" "$PWD/file_case_wrong-try3.log" && + + # Status should say these files are modified, but with the case + # bug, the "pos -3" cause the client to not update the FSM bit + # and never cause the file to be rescanned and therefore to not + # report it dirty. + ! grep -q " M dir1/dir2/dir3/file-3-a" "$PWD/file_case_wrong-try3.out" && + ! grep -q " M dir1/dir2/dir4/FILE-4-A" "$PWD/file_case_wrong-try3.out" +' + test_done From patchwork Tue Feb 13 20:52: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: 13555659 Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D2615612EC for ; Tue, 13 Feb 2024 20:52:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707857550; cv=none; b=IQeMWS2pZE+yHNcIKyWlqQQ7Mxbd9D5z1VHL5bkxRLAvxI8bLJ6dFdikClnjLaI9QyWNJSpM0jBkZm3f81ur2Xg4WskLdzpayDybxDdL9YaW5+DtLBrspyhjdzZrbtCLByeWTPDXitT0EbecWLD7KUC943+v/+LStAelBbR0lxc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707857550; c=relaxed/simple; bh=0oR8UJB7BkvLV8+AVoLG7D8rlN5I6mw1FkftJDJPCO4=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=fOqy80eSaPbBw8t3/IPI+sa7Z9zMI0tEVsGEtVbTmj+78pAX1LF+81SNYSgpSiGryn6Ff9xbqt1NOGa4sM9W30l/kKzVSnZSuVzvo70xZ5RHOTWSkzJyeL/0AsAQnyKW1JAEmqL1Gh8scxhOg60wt0+xV4XYcqXoPTp8ayHNZPM= 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=D/0JGtz7; arc=none smtp.client-ip=209.85.208.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="D/0JGtz7" Received: by mail-lj1-f169.google.com with SMTP id 38308e7fff4ca-2d10ad20955so12048231fa.0 for ; Tue, 13 Feb 2024 12:52:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707857546; x=1708462346; 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=kmJzcER7dyAQ6IaPoa1NWpxspbx67eGtS47TAXW/aOk=; b=D/0JGtz7nEjKoWDBIK6nl1R1y6j2g+QBCYTR3x1qQMcKettS0lp+K02DCgPKqrKa1q Iccy6k/gGzNxwPSvGLWKPnmNNr+g8nVdIPxyQI4JEiPJM5iOHS/An0eg+llze8Ag89tj OUCHz/G6V5Kvb/RF2QKeuDWiTk1TgFBq3DB+lTLPDZLnqghMdkfFFy6p4Dw+ET3kzFjw F7vQlk289QhacZWMLyoPZkB9zMO5+uM04TCBq8cdJfuT5DloKlCRvOQ5H1ABKb01b01n LaxKpKiugLkKe1M1HadSOHUk5sfj5KcT/7B6xxutWQke8bMLF07jntVvXpC8k42x2Xtg 1Euw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707857546; x=1708462346; 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=kmJzcER7dyAQ6IaPoa1NWpxspbx67eGtS47TAXW/aOk=; b=D0CfQr/wrmCWF0M/67fzzY05ob+fPshr0FjnHs0g7oNX+etQyEdIhYxr1ZTSEJXFoa Z4ARibIdkklmj3rWkcLW3ptEiHJIdxHkUjDctypakFmjOiUTItsC4qpHmsxNnp47Svzy cFP+UqQcyhSGhWQiWH4mF94kTy8/MMPIjY/cVskEounmtTIxqhaWBXHLd0g6UimMCCwj yo6RXlLfGD3CKl5EPHqWtYUowjGikRP/1VuyziSuU06rREICKPizD3PyJKaVLoZkccuT Qa7rGJjT7STvvYo/W7mM+NsrSHQSjCdjqfz5Dhl9q69TpZHQGs6Qv9JIA/qgZ/tqFzGE vOvg== X-Gm-Message-State: AOJu0Ywh9e0HSb5gmzyGgKZi8AXOAcdZ9Ful9N9doXtoCEcZSWrmu66Q alzD/WwwJJlnOPAsxfwstF6gYUEk5zXcXVFA3Rt42kauQcmTH6Tj5VGMEFHt X-Google-Smtp-Source: AGHT+IGhYLNW+dJI6cbETArciNmQMmQCEQBwlZJgxdvLe+3uzXFxIXBpRf4BTSgnK7Fe933PuHAI0w== X-Received: by 2002:a05:651c:314:b0:2d0:b6c4:2180 with SMTP id a20-20020a05651c031400b002d0b6c42180mr416824ljp.53.1707857546424; Tue, 13 Feb 2024 12:52:26 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id js26-20020a05600c565a00b0040fe3147babsm12654923wmb.0.2024.02.13.12.52.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 12:52:25 -0800 (PST) Message-ID: <3fb8e0d0a7c0455cc7a5ba28c12736fd4bbbd44e.1707857541.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 13 Feb 2024 20:52:13 +0000 Subject: [PATCH 04/12] 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: Jeff Hostetler , Jeff Hostetler From: Jeff Hostetler From: Jeff Hostetler 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..b1ef01bf3cd 100644 --- a/fsmonitor.c +++ b/fsmonitor.c @@ -183,6 +183,35 @@ static int query_fsmonitor_hook(struct repository *r, return result; } +static void fsmonitor_refresh_callback_slash( + struct index_state *istate, const char *name, int len, 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; - } + fsmonitor_refresh_callback_slash(istate, name, len, pos); /* * We need to remove the traling "/" from the path From patchwork Tue Feb 13 20:52: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: 13555660 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (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 690BA6167A for ; Tue, 13 Feb 2024 20:52:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707857551; cv=none; b=kB6LFvtf1zAKCKByFWPi15j0caDbnnCk0oKK+EJU7Ljf3PG0Zvkpl8zptA+vLhMwgsK3yiM2erps7FXNitx+o9j6216Id/3hwCkHbHSG9TROq+7k1Z4gJeVIotkINg8bLP77Xeykc/pgPpKrG3uq0KckNDltnqClvAVoeL25JF0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707857551; c=relaxed/simple; bh=bi2xudFPH1xU2Ku1xgwGbJ29eP0POJlfpO7PAAL3koQ=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=ZrLJcOxm6zt6AazBrn+mypu7lWsEUmiyk+WmBo7UKKPz9niBaKoDIb7Mltxp1v7RS5Q54tkbpuCA1tK4rING5e8q/469KHE8JjVIYFnxoOKX2zeiUs6ENhisQfigycj21gSUB6Cbio2oQr8+j6/nMF7/U5IBvaujoZG+zdC+ukE= 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=BD7kXLOS; arc=none smtp.client-ip=209.85.221.43 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="BD7kXLOS" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-33cddf4b4b5so631044f8f.0 for ; Tue, 13 Feb 2024 12:52:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707857547; x=1708462347; 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=6klzPN9QiZfeeLoJvk9reIAEWsNTdN1aOH6ZB4dLCpk=; b=BD7kXLOSieysQXPVOuY9A2EtODhexJaP7/ExfMXQUMoUHxquBTL9Bha/S+7ot1tLHa TLLYF6OVFxi7Kf7oouZxYpgdkL98u/82F90DobTW9MEs8XrvzFEH6Ijp1E+e0M+St0ee hw71CUZfeX3bqNcxVWftPtOGchFiQVNyfqfx5C1Z0rCrk8cMSRe8qOG33N66LIpboIbS zj4JhMBg6tLh48KPRDkGUEK/yp5NozfChQ95hGIU1wD/TqjFUQpUOXyu9choryG2KkUi afG0m9UVpHxCZnksGmN9hj6LlyDXE3421yIAgjVAYfrXfpX1J6uKwhfseaGGMsmUdbCJ D83A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707857547; x=1708462347; 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=6klzPN9QiZfeeLoJvk9reIAEWsNTdN1aOH6ZB4dLCpk=; b=ZHCpVlI4yzlwiXOEL96tQWEfXT+mXrHNNmC1sJyi0Elg01sYW+0Vq9XI0chiYEbbg8 JbO2jH1EqL/wPQquW2JP8AEB30vpt9ArnXGkJoqyXjF79Syz9HqLW0D5o26rEd6duMu+ o12pHDYFlbXJeYRiCzz3S1bwgw6fJp6mT4y4WkQmBhkN5EiT8/zaU1PU11Vvc/y6Ry1B r908rG1rXfmUVZOAAXBuu28aHx2j8mLTiNeQxrL3nCAVFODr8EI/wr+pWPibxet6HY2H mp29cQxaRS9dPf/R1rx9JmzRaAv/sBog7wUrRoTxjuUszflNVcDfLx4M4ROWl9705qw1 y8EA== X-Gm-Message-State: AOJu0YzT1kgttsoG5Segi8BJxl/xebetcFEGH3wIBYmb3j42sf5uaH9z NHoGnFiGFyUNttqTQTihMKG/EisPOnPS1FkzR4kQc7Y5E6CzPlt7Elo0G2N9 X-Google-Smtp-Source: AGHT+IHaPniENavKJbFbp4uasKWQM8asn4y9yjsKStVtVKiP/jHMCEzO7pUkcI+MZSmBxbleJ/lT5Q== X-Received: by 2002:a5d:5143:0:b0:33b:457c:9b06 with SMTP id u3-20020a5d5143000000b0033b457c9b06mr340545wrt.28.1707857547391; Tue, 13 Feb 2024 12:52:27 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id v5-20020a05600c470500b0040fdf5e6d40sm12950237wmo.20.2024.02.13.12.52.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 12:52:26 -0800 (PST) Message-ID: <0896d4af907d71df29b0c4f5a27d24ea80b3c0e1.1707857541.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 13 Feb 2024 20:52:14 +0000 Subject: [PATCH 05/12] 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: Jeff Hostetler , Jeff Hostetler From: Jeff Hostetler From: Jeff Hostetler Signed-off-by: Jeff Hostetler --- fsmonitor.c | 66 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 28 deletions(-) diff --git a/fsmonitor.c b/fsmonitor.c index b1ef01bf3cd..614270fa5e8 100644 --- a/fsmonitor.c +++ b/fsmonitor.c @@ -183,6 +183,42 @@ static int query_fsmonitor_hook(struct repository *r, return result; } +static void fsmonitor_refresh_callback_unqualified( + struct index_state *istate, const char *name, int len, 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.". + */ + 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; + } + } +} + static void fsmonitor_refresh_callback_slash( struct index_state *istate, const char *name, int len, int pos) { @@ -214,7 +250,7 @@ static void fsmonitor_refresh_callback_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, @@ -229,34 +265,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; - } + fsmonitor_refresh_callback_unqualified(istate, name, len, pos); } /* From patchwork Tue Feb 13 20:52: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: 13555661 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 05D3861684 for ; Tue, 13 Feb 2024 20:52:29 +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=1707857551; cv=none; b=oGA7Y4LDC1Z/NwToeEkBECOJ2ruX6nYIicI2jwGUVW+0QxnmR0Yrx7hB17v9t61/ikAreHiYyjPl6wGoAYQ7Ptma1C1FMWblUEpf15XgrPrv5WdtaGe27jq/AoQtmh+NO2AVuO2Z19wIIC1srHUHXogN2HG+7zc49zy8HfFyn+M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707857551; c=relaxed/simple; bh=jgB3VL0aShC4tYrJuzj+QOGMT+Ag6jFrQX2enk1siBA=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=g6SoTFRa2rnT7L7lQD9NaeS4TDgwSFVL5a/bMCv5REGXZ5RcwX1WV2dcAgwo/2UaVP3ooxDRbJZkAw8ORg02YJ4OMM3cGtzFTMjJX+LzZQoMs9rVfbKrgDxDYX8EM2xHCSg94rOg6q+i1y95Ym9jHhUaXf3aCdEN9VjrLm+D4n8= 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=kM1rGIZS; 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="kM1rGIZS" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-411c3b299caso7519405e9.0 for ; Tue, 13 Feb 2024 12:52:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707857548; x=1708462348; 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=n+BhL80c8uewTd34a/xkpNgnLwIZgGYER9EumuNmNj0=; b=kM1rGIZSJNt/hHRu1pCnZLLBWx1Pv/pLCtRKKO8DeECpnEupeTCLhHp8dMV/Yrj2wF BX5XxyBPHfFU68trBvfDpVB9WykZR8wkvkt9upDyVp4mUr0likCVXcuDdk0J2lMUfwl2 WlJ9OGNtK07q4TEPVPgkgkqYE/mRD4yWU2ICMvKR2j2j1u3PEHLNWihW0d6SLxU7I/Bq EL5RwO+qsPylul9VO37ZCCVtGEL4k6+cbd0AmKGK8FdQzV9y4ALG4wCtfsDtK7XAkyjJ WBksw/fdshX7BYd2qt+S0sEmEL3zOY5uzve1k4DElM282w6rgVLs3yGWT1wIKJr1eIAs Ddgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707857548; x=1708462348; 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=n+BhL80c8uewTd34a/xkpNgnLwIZgGYER9EumuNmNj0=; b=tUY8j3sGQqC4MsWgT4zQ0Ala9bRNus8p2ArNj36h7tPUaHHQhglEvhRDZcSh/BXjiO cmK9TiRwBQZ5qGN/im8K0cSAgtxK4eazyAKRU5WClxCgj3/cTQUkx5/D4tYWBUCqQjcE 1t7kS9zWTn7ylcN1P8iw3wdzO0NdPDHj51Sgns89D+ue/lvVeg2BrQpod3s5nmNpURAW MmLaOtsJocCCAPZedl0g1xhpnUFwE7V2HmW5KaFAL+leFAgmTeocBBHR2Owi+n+M3WSx Rn6eCrKgygRsPKB0lzq6Jrw/oIOann8guNLSuKUCIaYf0ESQLICJv5mDY8VcUaPSh26M xhRQ== X-Gm-Message-State: AOJu0YxGgxppjSSWCp3ykZg6d4rniG1rPynHMc9MiJ63VwHPCPg2PNrg +S1qRK1BYwB1hxR+uVw63FUKXgC6nGviCs3uI3hPghsrRZixMmudeAk47xF8 X-Google-Smtp-Source: AGHT+IHJDQ6hX3DUe218WPM6nVi6O1zQNH7W9zme1VCS1/SbWN6yEKTXyC5qDkn2q3/6xDy3CF5buA== X-Received: by 2002:a05:600c:34c4:b0:40f:b01d:61a8 with SMTP id d4-20020a05600c34c400b0040fb01d61a8mr556086wmq.38.1707857548083; Tue, 13 Feb 2024 12:52:28 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id m10-20020adff38a000000b0033b0d2ba3a1sm10423650wro.63.2024.02.13.12.52.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 12:52:27 -0800 (PST) Message-ID: <5b6f8bd1fe7b6c742b25a5a1ed95b528f352215e.1707857541.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 13 Feb 2024 20:52:15 +0000 Subject: [PATCH 06/12] fsmonitor: clarify handling of directory events in 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: Jeff Hostetler , Jeff Hostetler From: Jeff Hostetler From: Jeff Hostetler Signed-off-by: Jeff Hostetler --- fsmonitor.c | 47 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/fsmonitor.c b/fsmonitor.c index 614270fa5e8..754fe20cfd0 100644 --- a/fsmonitor.c +++ b/fsmonitor.c @@ -219,24 +219,40 @@ static void fsmonitor_refresh_callback_unqualified( } } -static void fsmonitor_refresh_callback_slash( +/* + * 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). + * + * 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. + */ +static int fsmonitor_refresh_callback_slash( struct index_state *istate, const char *name, int len, int pos) { int i; + int nr_in_cone = 0; - /* - * 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; @@ -245,7 +261,10 @@ static void fsmonitor_refresh_callback_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 Tue Feb 13 20:52: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: 13555662 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 2ED576214C for ; Tue, 13 Feb 2024 20:52:30 +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=1707857553; cv=none; b=OqwNxrueCmJq46RkDrhkfd3aXvPEPuMR/IxnP+CmK39y4AIc0K+LA3/fHEDeWV3B6HYTZfJiZZJQU0IJkSbkOze1XMhtGQRMVhh4XTU+4Iqa3RDETFRMPfk1K4E0p7tSIWNxCBykxjjE7oWEjJ1wvBTJmIAHDouKDDXFXqz/FQU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707857553; c=relaxed/simple; bh=nKVqwyTqva0tbdDVV1iBiNAMNvjSnOzTkYM8zmRgppg=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=Qcv8z3XBIwAdV4V1BWdWS3MJcDGmvULc3K0I2iSva2AeKAiUycJfX0vjA8YEGcblpJSm/a+BGX+ZSzqVqIj8CAJEgfDfJUGDmCt2+RXHMS2lS6oCv03VEYT9+vjflhM3yaR4nw95lsdhCJtj5jCYwNqp+Tpr7OlQ6vXSPDSYMYY= 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=EsKRzrQV; 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="EsKRzrQV" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-411d76c9ce3so3301445e9.3 for ; Tue, 13 Feb 2024 12:52:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707857549; x=1708462349; 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=IZ1vbJBqwq2j4qrnDhXesWSb1fA2Xwy+5KVtWvrKu6w=; b=EsKRzrQVmjtTqODsv7o30IgxBPYATOqtCFi2/xzwlLZSVyeQDsZl9r7v8G6pCennof fm9AO/UVbGfIcCAH+pb+9rWH/D9JXIJ0L7KP2d9hvyL/ufUq6TmSvUCOyVCYZ7qED4pJ dO6kOKwUffYQj6TFpcEXAKTQhQSj6xzYA9lPlgcfDoiBvJdnxWtQOrq8iM0hLW8J7+bW zEEBTvZfL7VyNUKKiyTUN1vUq6xWod0Fvn0QRqD8GLbl8uz0f/O73/q8GoQ/oMkem+/O OfQmSjttL4llteZbzCh5DMeru9UdQtSn50IXXD5+++Nwilry67K6F3e1YreocTyYJC1X 2Tpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707857549; x=1708462349; 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=IZ1vbJBqwq2j4qrnDhXesWSb1fA2Xwy+5KVtWvrKu6w=; b=DkuaydY7jC/78b2yG4SOPbAS9oEQiagjUjimTzXgysSx/W61UWP/8a0rk8TJPEjpoA DuVfRg+bgX53DvqpNmVvhgCvNJ0L6udszqIaOwppFyN7v+gkKNjtBVPg7oqovZ3lT4rd YPbal7iwCmaq4yPPWleJCOxQBsT624jXoELID24XI1gOLKq1mU3tFV5TXAbx0G9FHbkS arw4xbMHxj9Uc7Lxxdj5+P4zQxNdcEeeROi0wlTvsdLlYfLezEovPEfHQHqd4EsIjccv 5n9nMlFEsIVd8x5lEIkPIFDLyTd9lrOPJJwmzGIsrFeCGrU46WpMFUb1qRyl10GuMYQ4 m+Ag== X-Gm-Message-State: AOJu0YxSR8lNZMZCuPyvwkLxyV83sfJ4D3I9ansX3wXHEpXZEgvkwDBK HOb8cUfPRaStsCNDxSynhnUTtjmyIlpe+G6RmvskQiw0kbFKbE5APX6OWcfA X-Google-Smtp-Source: AGHT+IEH6Y3iBpHLPQwWQubG1/cDQnNOVlYZo15tYemzCdb8tlmTYkh+10+10TvKTMfX9QMz/HZ+JA== X-Received: by 2002:a05:600c:34c8:b0:40f:cf69:3e1a with SMTP id d8-20020a05600c34c800b0040fcf693e1amr529767wmq.39.1707857548777; Tue, 13 Feb 2024 12:52:28 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id j9-20020a05600c190900b00410c2f39833sm8254846wmq.30.2024.02.13.12.52.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 12:52:28 -0800 (PST) Message-ID: <1df4019931c29824b174defb75e09823d604219e.1707857541.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 13 Feb 2024 20:52:16 +0000 Subject: [PATCH 07/12] 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: Jeff Hostetler , Jeff Hostetler From: Jeff Hostetler From: Jeff Hostetler Signed-off-by: Jeff Hostetler --- fsmonitor.c | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/fsmonitor.c b/fsmonitor.c index 754fe20cfd0..14585b6c516 100644 --- a/fsmonitor.c +++ b/fsmonitor.c @@ -183,11 +183,35 @@ static int query_fsmonitor_hook(struct repository *r, return result; } +/* + * Invalidate the untracked cache for the given pathname. Copy the + * buffer to a proper null-terminated string (since the untracked + * cache code does not use (buf, len) style argument). Also strip any + * trailing slash. + */ +static void my_invalidate_untracked_cache( + struct index_state *istate, const char *name, int len) +{ + struct strbuf work_path = STRBUF_INIT; + + if (!len) + return; + + if (name[len-1] == '/') + len--; + + strbuf_add(&work_path, name, len); + untracked_cache_invalidate_path(istate, work_path.buf, 0); + strbuf_release(&work_path); +} + static void fsmonitor_refresh_callback_unqualified( struct index_state *istate, const char *name, int len, int pos) { int i; + my_invalidate_untracked_cache(istate, name, len); + if (pos >= 0) { /* * We have an exact match for this path and can just @@ -253,6 +277,8 @@ static int fsmonitor_refresh_callback_slash( int i; int nr_in_cone = 0; + my_invalidate_untracked_cache(istate, name, len); + if (pos < 0) pos = -pos - 1; @@ -278,21 +304,9 @@ static void fsmonitor_refresh_callback(struct index_state *istate, char *name) if (name[len - 1] == '/') { fsmonitor_refresh_callback_slash(istate, name, len, pos); - - /* - * We need to remove the traling "/" from the path - * for the untracked cache. - */ - name[len - 1] = '\0'; } else { fsmonitor_refresh_callback_unqualified(istate, name, len, pos); } - - /* - * Mark the untracked cache dirty even if it wasn't found in the index - * as it could be a new untracked file. - */ - untracked_cache_invalidate_path(istate, name, 0); } /* From patchwork Tue Feb 13 20:52: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: 13555663 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (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 D9AE562144 for ; Tue, 13 Feb 2024 20:52:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707857553; cv=none; b=FLNCksinl9n8y1ZOXE8YZDAMul+t/WJDxNlAlBCzCMl2cIqEGFaXNa457sUBaiLsu1nLAB9qX0+Vhyv0wJR7BpPSIDCn9Lg33a/vcAhq23FpMin6GKnUj9Z1fOTPGn7ntr6TPHa1/v9uJrjtGHAj7helIJ3BbbSCOkLcbr6O9Ow= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707857553; c=relaxed/simple; bh=j3C3MZrwnGm5zxFS0cziJeQGFQ2FE0J7FnnFY+UNimA=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=k7W7STCGRyEPgSh6nADK+8VNzQziE7jaR+WVioy4gF8JBC3UEUtOdhnJDAAoW9EXnz0CPLxhTsogWMQH+Stxm3BsgBXTcErbu7y1yPuICck7uzqOZKWNGM1ZbELAAabOfXu8qsT6CtzpwYxn1mgbz2CanPMR8z6rUK11XLmFrdk= 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=AfD086YS; arc=none smtp.client-ip=209.85.128.54 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="AfD086YS" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-4114e0a2978so15297295e9.3 for ; Tue, 13 Feb 2024 12:52:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707857550; x=1708462350; 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=Pt657PS+1YvskOQb//W4hDB6kfHYbQUH81vTiCfN9rU=; b=AfD086YSQF38ZYsWWpw81Sx5R0AIcSQ9OXSZkn/ASfJ5b3PDD+QR7kmuvaNUfh90jH ntUXLL/sZsge1ZFCQdx6IpEhjciPXt2vY9NE2TKrSHhFQt/YSTQstluwNvAOn1vpW763 LGt5G5Q2EnUOX65M4qzZ+2r/fNaPK27VOB17+TQJdNt4eJzV6MH35S5XzqqeNhdupi2E yTMApLMBmCUbeMIBmrP/ksNOXrWN9G55/xBR9j0pvvCPwLP4E2dTE/RMrPerkq07rcTv UU3VzD/THoqP+94wZVisWzF+JTXTEAoACJTdzyElFddGgKbWlQq9qJtiNkRxiBlyFRxq y5gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707857550; x=1708462350; 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=Pt657PS+1YvskOQb//W4hDB6kfHYbQUH81vTiCfN9rU=; b=P6A2/pJ4V2xtI8ECs2VobjljtIqMjVOOWJ2IRjpJr2DxXw2BuFwco2jX71rYCSU3LA r4bZ1vLL1IO4DRZlV9/EcsjCo71nRNMG1YJ/8CYnvSUkLq4mMWY11XhW56kdi/gcmAfF 9iLK6yyADoECieobLHsVbCUSQZmKtmXvwI3t70qkI+EPBv+XHEseD7jHoIHBA/qZ4w2z YzfG77VE/cyRLjxbMQJhkwG4zNqP004epkEjRJU1W70nTyL2k8+1XX0A9AJs6Mx+ilRG 91TLnNixYMksQuz3QeSXUxI+H5QvNr1cmc7BByTMvrbMf0Mjqtjd2k+2wypDrscdZz/q 857w== X-Gm-Message-State: AOJu0YyVY6iW0OefKYuH0V/Q5YFdivj5ZtWjYTiKl149NIWpNCl5eGfR m/qjAUrM6Gi2nF0IzKO1YW8ip8xY3P910pYvMgb3QaBH0fio+0Cr6R8TFlKB X-Google-Smtp-Source: AGHT+IHw4+Qf+Fl42QJq/5nyMHg+nJE5R/UcDCqHIl5Mt9pE7rekGx6oQA9gD0gEStj09Ma0SJiUQA== X-Received: by 2002:a05:600c:1f8f:b0:410:c25d:37d0 with SMTP id je15-20020a05600c1f8f00b00410c25d37d0mr671969wmb.21.1707857549892; Tue, 13 Feb 2024 12:52:29 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o16-20020adfead0000000b0033b4ef142edsm10403034wrn.110.2024.02.13.12.52.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 12:52:29 -0800 (PST) Message-ID: In-Reply-To: References: Date: Tue, 13 Feb 2024 20:52:17 +0000 Subject: [PATCH 08/12] fsmonitor: support case-insensitive 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: 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 the handling of directory-style FSEvents (ones containing a path with a trailing slash) to optionally use the name-hash if the case-correct search does not find a match. (The FSMonitor daemon can send directory FSEvents if the OS provides that information.) Signed-off-by: Jeff Hostetler --- fsmonitor.c | 122 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 120 insertions(+), 2 deletions(-) diff --git a/fsmonitor.c b/fsmonitor.c index 14585b6c516..73e6ac82af7 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" @@ -183,6 +184,9 @@ static int query_fsmonitor_hook(struct repository *r, return result; } +static int fsmonitor_refresh_callback_slash( + struct index_state *istate, const char *name, int len, int pos); + /* * Invalidate the untracked cache for the given pathname. Copy the * buffer to a proper null-terminated string (since the untracked @@ -205,6 +209,84 @@ static void my_invalidate_untracked_cache( strbuf_release(&work_path); } +/* + * Use the name-hash to lookup the pathname. + * + * Returns the number of cache-entries that we invalidated. + */ +static int my_callback_name_hash( + struct index_state *istate, const char *name, int len) +{ + struct cache_entry *ce = NULL; + + ce = index_file_exists(istate, name, len, 1); + if (!ce) + return 0; + + /* + * The index contains a case-insensitive match for the pathname. + * This could either be a regular file or a sparse-index directory. + * + * 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); + + my_invalidate_untracked_cache(istate, ce->name, ce->ce_namelen); + + ce->ce_flags &= ~CE_FSMONITOR_VALID; + return 1; +} + +/* + * Use the directory 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. + * + * The pathname MUST NOT have a trailing slash. + * + * Returns the number of cache-entries that we invalidated. + */ +static int my_callback_dir_name_hash( + struct index_state *istate, const char *name, int len) +{ + struct strbuf canonical_path = STRBUF_INIT; + int pos; + int nr_in_cone; + + if (!index_dir_exists2(istate, name, len, &canonical_path)) + return 0; /* name is untracked */ + if (!memcmp(name, canonical_path.buf, len)) { + strbuf_release(&canonical_path); + return 0; /* should not happen */ + } + + trace_printf_key(&trace_fsmonitor, + "fsmonitor_refresh_callback map '%s' '%s'", + name, canonical_path.buf); + + /* + * The directory 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 + * 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 = fsmonitor_refresh_callback_slash( + istate, canonical_path.buf, canonical_path.len, pos); + strbuf_release(&canonical_path); + return nr_in_cone; +} + static void fsmonitor_refresh_callback_unqualified( struct index_state *istate, const char *name, int len, int pos) { @@ -269,7 +351,10 @@ static void fsmonitor_refresh_callback_unqualified( * * 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. + * case-insensitive search. That is, if a observed-case search 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 int fsmonitor_refresh_callback_slash( struct index_state *istate, const char *name, int len, int pos) @@ -293,17 +378,50 @@ static int fsmonitor_refresh_callback_slash( return nr_in_cone; } +/* + * On a case-insensitive FS, use the name-hash and directory name-hash + * to map the case of the observed path to the canonical case expected + * by the index. + * + * The given pathname includes the trailing slash. + * + * Return the number of cache-entries that we invalidated. + */ +static int fsmonitor_refresh_callback_slash_icase( + struct index_state *istate, const char *name, int len) +{ + int nr_in_cone; + + /* + * Look for a case-incorrect sparse-index directory. + */ + nr_in_cone = my_callback_name_hash(istate, name, len); + if (nr_in_cone) + return nr_in_cone; + + /* + * (len-1) because we do not include the trailing slash in the + * pathname. + */ + nr_in_cone = my_callback_dir_name_hash(istate, name, len-1); + return nr_in_cone; +} + static void fsmonitor_refresh_callback(struct index_state *istate, char *name) { int len = strlen(name); int pos = index_name_pos(istate, name, len); + int nr_in_cone; + trace_printf_key(&trace_fsmonitor, "fsmonitor_refresh_callback '%s' (pos %d)", name, pos); if (name[len - 1] == '/') { - fsmonitor_refresh_callback_slash(istate, name, len, pos); + nr_in_cone = fsmonitor_refresh_callback_slash(istate, name, len, pos); + if (ignore_case && !nr_in_cone) + fsmonitor_refresh_callback_slash_icase(istate, name, len); } else { fsmonitor_refresh_callback_unqualified(istate, name, len, pos); } From patchwork Tue Feb 13 20:52: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: 13555664 Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) (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 54DE4612F9 for ; Tue, 13 Feb 2024 20:52:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707857555; cv=none; b=c+BaXwDmSHIgLiYpleXjhTBXkvp0fjR9lTw/rDwilkWHQb9kKXse42BHHHHAgsKf+MAVjc2bZ0l4hPnfJMf+7/xlSEdB0oM3IHuWAOC9JDVqFHqxC0SFOGfK++6OXN4P899OFaWWgWHG6oHoQnxXHfqTbyyY+ozOuZTcYBcsV3Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707857555; c=relaxed/simple; bh=GUwgwiNLNa5h58evi7O+FZbmMziB3B7fbsZQy5Gli9A=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=iyX6koZdOk8cM3To6M3WQw0euJ89CMhq3EZ1ZjfM6oQ6wuxVsRrpD0WFqMDx24pA0w97G9LOGwQ0TIKqDaqA2cbMKkytv1Ii/gTqdfAwM/GyqVtyfzo5JnypusFtPaMaiWTdqsXyR8SlTND1BBCRkQ017JFfcGkou/ZcBTMZeEc= 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=XlAmHjg+; arc=none smtp.client-ip=209.85.208.174 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="XlAmHjg+" Received: by mail-lj1-f174.google.com with SMTP id 38308e7fff4ca-2d090c83d45so63128721fa.3 for ; Tue, 13 Feb 2024 12:52:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707857551; x=1708462351; 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=aasr3DWCPvtTIrJX3OH9e1+U7yA+xVpNznRB7OPQquU=; b=XlAmHjg+vnXpYTMobUffjFoGKfiAwXcpqDSH9FoSQiJ9L9P2ChksviD47iPM7Q7J0p TpbbGW28NAEaNO5RvYRUDvfRl01lslpTSSp9SFcGAaTnkz4YPw4GaNASnFzfiz0TpowF QNgUJQ4ZgNpIsciVNRurQVXKOu5s70vi4EF+2ppgnwmEMKcl29ntvVkv53ilaP6VcE02 Nl6oCqG7bJIB+A35CPTdFrUvG/lvyedyF7VUzIIDs78UsXIXnsjg6RaPePNHVQX94VAe gWABRLDZyiMJgV5TaMrpsRW7rPZ0jblT1ytEW4p1Qj72PDcamJpqOfuSyTUsSey/quBS RIdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707857551; x=1708462351; 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=aasr3DWCPvtTIrJX3OH9e1+U7yA+xVpNznRB7OPQquU=; b=ZuqLqP1Ln80fOYlLR8qXifayO2NYG090m4Saa3i0GQ15sxZUHMUd26AaON72kB3bBY /fknW+VPNwUf2qXvUr/vgkOVufsHFrQoNs55orN9cRUuDIPZAcNLp5cc6hAN0glOudEn G11lRaWrqCn7f3zdZpDVRGjy4ByuH9AYBoHp2LCmoPFnoUyCZU0a4U39KdQxm2vxCtzf xxG9ZDDAjVTrbWaRxtA7aj5l/5S/sTfdqe98C/0tv8CYIeQbdH0m5v6OLlg7Jb4VZQAb 7a6LTPuQNgCenVaMQvme3t8jeu/xAQgluRyrQ9ghWMo6FlkhBA8JAwG05vMK4tVE3xx1 MHrQ== X-Gm-Message-State: AOJu0YwCeShuFKIMLTFjI9HS0O7gyw5P3GIx43W2p89ou2OSgLeCaK45 MyBqpgOgCwwvxk2zMOTd6RqcG4oNJNEO8ejDqeLW20ToxRRZjI+K+UW6ezNM X-Google-Smtp-Source: AGHT+IHJlTjOp3+LixGEX13tGOEJVWSMT0re9c30Xv5ZYYlQGNmcfb+jCGTguMZ0WjfYt/GFv08pAA== X-Received: by 2002:a2e:94c2:0:b0:2d1:e53:cede with SMTP id r2-20020a2e94c2000000b002d10e53cedemr498367ljh.25.1707857550723; Tue, 13 Feb 2024 12:52:30 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id z15-20020a05600c0a0f00b00411d6c1476asm916826wmp.1.2024.02.13.12.52.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 12:52:30 -0800 (PST) Message-ID: In-Reply-To: References: Date: Tue, 13 Feb 2024 20:52:18 +0000 Subject: [PATCH 09/12] fsmonitor: refactor non-directory 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: Jeff Hostetler , Jeff Hostetler From: Jeff Hostetler From: Jeff Hostetler Refactor the fsmonitor_refresh_callback_unqualified() code to try to use the _callback_slash() code and avoid having a custom filter in the child cache-entry scanner. 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 | 59 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/fsmonitor.c b/fsmonitor.c index 73e6ac82af7..cb27bae8aa8 100644 --- a/fsmonitor.c +++ b/fsmonitor.c @@ -287,41 +287,52 @@ static int my_callback_dir_name_hash( return nr_in_cone; } -static void fsmonitor_refresh_callback_unqualified( +/* + * 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. + * + * Return the number of cache-entries that we invalidated. + */ +static int fsmonitor_refresh_callback_unqualified( struct index_state *istate, const char *name, int len, int pos) { - int i; - my_invalidate_untracked_cache(istate, name, len); 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; + return 1; } else { + int nr_in_cone; + 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. */ - 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, len); + strbuf_addch(&work_path, '/'); + pos = index_name_pos(istate, work_path.buf, work_path.len); + nr_in_cone = fsmonitor_refresh_callback_slash( + istate, work_path.buf, work_path.len, pos); + strbuf_release(&work_path); + return nr_in_cone; } } From patchwork Tue Feb 13 20:52: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: 13555665 Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 57E3562168 for ; Tue, 13 Feb 2024 20:52:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707857556; cv=none; b=uvpzzCn9KfTFswJBaIL52hRyTxj3K0mxxGaOK10Y0ndac0xPh7Z+L4S4yFL1rLFgs0vqzgNPKv4J0Emu7k4ZAE8whvrSc/hMAmA9aAO4U6lR+T4D6pv1idw3IX6Du6Qg+n5snkwZrHD/6AcGC2yJ8c9s/HgLq4yV+lLKm6AKLNc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707857556; c=relaxed/simple; bh=NdFP1QTEezanFkq27c5nWo5Lbjp8wyBfJVlmAKD4FuY=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=EbOBwdABK8oETs+Gjrsm4zZOgetyLi9WiwtVOBxrTqRW1W1RNClvmZ5H4QLlVEEbEqZGijOtHnofdcavJ51VSYKWojGKORaQPjRFp06rnznjn3CuMm0K7HjvENNsHm0kEaQBAbgSn4ptSmI3WlziJEqeJatc38zP+GHkL73C51I= 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=bJ3RNlKI; arc=none smtp.client-ip=209.85.208.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bJ3RNlKI" Received: by mail-lj1-f177.google.com with SMTP id 38308e7fff4ca-2d0e5212559so43700651fa.0 for ; Tue, 13 Feb 2024 12:52:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707857552; x=1708462352; 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=jdWsX3AXrUdArzaGIsxeDy3c9IdmIlzuNZTcXMGxkAk=; b=bJ3RNlKIQhLX0qPnK0h/Z++ubIgj9VPWGoUXVOxDXNIiW3Q4+3lNurH4wZ9dAzOGGa hM/9U22joZpU8Eb0MikAC/euBw842qQBzOYXzncE0OnDC78FDZ0KeDNr1iuwHFPqjCQQ 0Tu5FhN1AW/TpegiQAUpw/3XDV9Yg06Udhxq5jDfoOx6a45lgN7VhppYN/sH0NJT7UuE Lw5HpgGW2RVhJmgo07AK5Na6BdtV5HGANPDtIn2QKV8jgh6jOZVrZaaqePcM+Sc5s0vq tczdvEGMFn4LDxUGFsF5lsZvOU6+RhZJYlncj3KBiZ5AZZQIginyXBvvAPqTWAB6RhD/ uuaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707857552; x=1708462352; 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=jdWsX3AXrUdArzaGIsxeDy3c9IdmIlzuNZTcXMGxkAk=; b=J+0DtsUAcmY3czury0hoYDzPxLDydqY0FJyxNgvuZbEHtO6VyAdx06fD78Rh9qSTIz JAShRrC2Qb9kNpTZokI6JtWVkyf03mwxuTPCu0EJknrXXf0Gp7d2EJdEf4gMQmrRXQIr DbY7NOsA09+91fitjalLL/ko8ZLuP6eOzESY3VJllNfjki9WPqNAbQ1PDerbX+8C+ou3 +OCnqnwYg1NNCjKOi/PFXDPEmhtmEDtJpTN6A5SDiuzWFbPw8ob/ugNb3jyKxZOv+MAT o1UpPxGalz5IHp+CXpCXAKsAnE+8GqFiPgfgRXx8Un/YXMcNdKSWngfyxBRNFBIkKyiP Z9TQ== X-Gm-Message-State: AOJu0Yx+UlyvqazU7xfo4FUM+yBJJKKraAPGDbzok38TsShF4s3spDre cpyS3RTZmR1H22+tf7TIrbmjsBMw3kVk7YHtI/IW+S79R9hyLPfEQNycfWdf X-Google-Smtp-Source: AGHT+IHDnvqIodFqItlvtJ9GP6ehxEbW39k38gXgF71i3TAQIAuOKFKuaZmUPUmzVAAhk3JYQNcPFA== X-Received: by 2002:a2e:3c12:0:b0:2d0:8f01:f4d8 with SMTP id j18-20020a2e3c12000000b002d08f01f4d8mr497360lja.18.1707857551935; Tue, 13 Feb 2024 12:52:31 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id u16-20020a05600c19d000b0040f0219c371sm12938987wmq.19.2024.02.13.12.52.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 12:52:31 -0800 (PST) Message-ID: In-Reply-To: References: Date: Tue, 13 Feb 2024 20:52:19 +0000 Subject: [PATCH 10/12] fsmonitor: support case-insensitive 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: Jeff Hostetler , Jeff Hostetler From: Jeff Hostetler From: Jeff Hostetler Signed-off-by: Jeff Hostetler --- fsmonitor.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/fsmonitor.c b/fsmonitor.c index cb27bae8aa8..a7847f07a40 100644 --- a/fsmonitor.c +++ b/fsmonitor.c @@ -336,6 +336,36 @@ static int fsmonitor_refresh_callback_unqualified( } } +/* + * On a case-insensitive FS, use the name-hash to map the case of + * the observed path to the canonical case expected by the index. + * + * The given pathname DOES NOT include the trailing slash. + * + * Return the number of cache-entries that we invalidated. + */ +static int fsmonitor_refresh_callback_unqualified_icase( + struct index_state *istate, const char *name, int len) +{ + int nr_in_cone; + + /* + * Look for a case-incorrect match for this non-directory + * pathname. + */ + nr_in_cone = my_callback_name_hash(istate, name, len); + if (nr_in_cone) + return nr_in_cone; + + /* + * Try the directory name-hash and see if there is a + * case-incorrect directory with this pathanme. + * (len) because we don't have a trailing slash. + */ + nr_in_cone = my_callback_dir_name_hash(istate, name, len); + return nr_in_cone; +} + /* * The daemon can decorate directory events, such as a move or rename, * by adding a trailing slash to the observed name. Use this to @@ -434,7 +464,9 @@ static void fsmonitor_refresh_callback(struct index_state *istate, char *name) if (ignore_case && !nr_in_cone) fsmonitor_refresh_callback_slash_icase(istate, name, len); } else { - fsmonitor_refresh_callback_unqualified(istate, name, len, pos); + nr_in_cone = fsmonitor_refresh_callback_unqualified(istate, name, len, pos); + if (ignore_case && !nr_in_cone) + fsmonitor_refresh_callback_unqualified_icase(istate, name, len); } } From patchwork Tue Feb 13 20:52: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: 13555666 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (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 463156217D for ; Tue, 13 Feb 2024 20:52:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707857557; cv=none; b=ebakFrc43nnYR2Mg/I3Uj+MCCjPRSzFFnwFHjOrq2pllb0oo2fANNVcg6dOJ3mhP8AslM7BAlOIhcVOYE9rvI72nXeVVES5D83NU0aiN7vvzTRHYsb9eFp+JOy4tHcIqV5aD/t+3ymddhKga8lEwnulrZET1xQLs/xodD/hVXR0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707857557; c=relaxed/simple; bh=pxAbmsq/7vkRMb1ulokRQgdz5tVCp/sVZQlJ0XbKjjk=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=HRE/TXqw3VaFHFlgJghiiJK0TomEmmGOLHNKjPG1bu9WDcQKabtiW4QuumcAwDM8mpenqh1Bpi3IP2ZZA9q/402foht210Aj8FN4o9x9ThDVWyKs4OvbyqbXKf0X3EPujd0Z/eraHttBAfSivTqctrJ52CCVJTYOBUQgCff6T20= 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=EI3AaPLf; arc=none smtp.client-ip=209.85.221.43 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="EI3AaPLf" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-3392b12dd21so2918066f8f.0 for ; Tue, 13 Feb 2024 12:52:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707857553; x=1708462353; 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=j6Acumg5qQQsEumbS/4+I3hkHL6+6jFDW/025LV5oGY=; b=EI3AaPLfFKPUBuUX4Uz6cZNPPL3eICERq011gDzae7GVz92BqL7aNq/wP1Tj09AuDV EgG0773KOxcoLjkYZjWfT5lCK4JIBQI2WzszwYnDP43HV9tvwVFuJOI6VRTo+n2/eKA0 LKfe0w7jNhu9fDJPav9n4zPm1/oqexB/jnY8JsjeX9pv7Km8u8K6mdwkIWB2oTaVioal mTpEiS/5jaNJ/ro1zpC49Pb5Kiveh1uSno+sCgXEdIVV43SHGCwabkiFcraICxv8fzQy lKLCiUEkvQdEAqBfWamdMj8kyjJIavAzsNThfUahxsipeyLCr7VdzGYvpWYVNMgVSqHj 6n8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707857553; x=1708462353; 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=j6Acumg5qQQsEumbS/4+I3hkHL6+6jFDW/025LV5oGY=; b=Nj5v4BKbkPwKHkOHJ9DrKQssNVA/W1h+c8e4/gQy47Bz+//YfR+hJGhBd1NOe5zBB4 uJnGM2P5Qbs4w/dpCjrlwFzUg7JFYq0LBnbRkOJbGYPXfRJ51p/bU3SC3yBUq+jj/yqc KnozApPVWpurfcBrGdSz0lXsvI7WfOkxFlf4gZ7r0YKLiTOToshd7lRN9ya0ytQOAGFq iLuurasWPF9WJKl1ID0FYpp2huoSUf27cIdTlzTnX6HN2fA6PeL+XhQ2BJAEqRsLs1Gm nLBgqmx9d1TGKpk1Mr1Lk/9t9LaJlYJzRz5XOmprlUK1vPVUEQpN0c2gAuBctET8ZBkW mMJA== X-Gm-Message-State: AOJu0YwKZ3YrXNodewv3iP0eka8OZQqoOeu8RtbY9lP7zbJDMzuIL13V mmjmBhnDQgxMcDx+SWfD3/hTEuhqE5LTLglPyh8CCiDgb4MLw4l89w3SvTwo X-Google-Smtp-Source: AGHT+IH0ja1H1WIUd7mWzpd4pjPKSXMKe6Hcvu6Asjxd3enexGU6I1wPGl4YBEBV0+wahrSqlGUdIg== X-Received: by 2002:adf:dd90:0:b0:33b:377f:7aa with SMTP id x16-20020adfdd90000000b0033b377f07aamr321327wrl.52.1707857552843; Tue, 13 Feb 2024 12:52:32 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id f5-20020a5d58e5000000b0033b44456463sm10379328wrd.106.2024.02.13.12.52.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 12:52:32 -0800 (PST) Message-ID: <7775de735f41bdc601318cd15c3414f12b361a0c.1707857541.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 13 Feb 2024 20:52:20 +0000 Subject: [PATCH 11/12] 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: Jeff Hostetler , Jeff Hostetler From: Jeff Hostetler From: Jeff Hostetler Refactor code in the fsmonitor_refresh_callback() call chain dealing with invalidating the CE_FSMONITOR_VALID bit and add a trace message. During the refresh, we clear the CE_FSMONITOR_VALID bit in response to data from the FSMonitor daemon (so that a later phase will lstat() and verify the true state of the file). Create a new function to clear the bit and add some unique tracing for it to help debug edge cases. This is similar to the existing `mark_fsmonitor_invalid()` function, but we don't need the extra stuff that it does. Signed-off-by: Jeff Hostetler --- fsmonitor.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/fsmonitor.c b/fsmonitor.c index a7847f07a40..75c7f73f68d 100644 --- a/fsmonitor.c +++ b/fsmonitor.c @@ -209,6 +209,20 @@ static void my_invalidate_untracked_cache( strbuf_release(&work_path); } +/* + * Invalidate the FSM bit on this CE. This is like mark_fsmonitor_invalid() + * but we've already handled the untracked-cache and I want a different + * trace message. + */ +static void my_invalidate_ce_fsm(struct cache_entry *ce) +{ + if (ce->ce_flags & CE_FSMONITOR_VALID) + trace_printf_key(&trace_fsmonitor, + "fsmonitor_refresh_cb_invalidate '%s'", + ce->name); + ce->ce_flags &= ~CE_FSMONITOR_VALID; +} + /* * Use the name-hash to lookup the pathname. * @@ -240,7 +254,7 @@ static int my_callback_name_hash( my_invalidate_untracked_cache(istate, ce->name, ce->ce_namelen); - ce->ce_flags &= ~CE_FSMONITOR_VALID; + my_invalidate_ce_fsm(ce); return 1; } @@ -312,7 +326,7 @@ static int fsmonitor_refresh_callback_unqualified( * 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; + my_invalidate_ce_fsm(istate->cache[pos]); return 1; } else { int nr_in_cone; @@ -412,7 +426,7 @@ static int fsmonitor_refresh_callback_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; + my_invalidate_ce_fsm(istate->cache[i]); nr_in_cone++; } From patchwork Tue Feb 13 20:52: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: 13555667 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 F019C626A2 for ; Tue, 13 Feb 2024 20:52:35 +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=1707857557; cv=none; b=s4FqKOEf0z6PlK3hxGw4M/PfhawokfUiIjRcA8QKS1d3vHQxK4hNHAq6TgX3pftmfOoGosi5uJRIaOxjDQoRMxxy1b9FqaqemcrBgysMok+wnDa19KSf2tSmYdSQ7TAv+urSt7EwQbiYXMAJ1AwCvNzMR5QUTwArDY7ig+TSJCk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707857557; c=relaxed/simple; bh=uaZoASYt8j7Y2+Ka3otM10x+haDYsjdGwqhtVUdwX2s=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=sQRq5ykilEozGIxI6d2G+BzBWSkWTvqF8iLtzdnxGnbYV0Ff9GwHK0MRB7nc47ZeoeQK4Z37k57FGw9D2aveY4aTk0am4ZoCsBAS12Jiu68cLxX6uIqXJgWqu7Pvp1EKS6hRBQqcuFKB2e4sXwhh/FzMSBvhXiBa7n3gb7P3R+Y= 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=Sew45Nq4; 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="Sew45Nq4" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-411dd149bd9so1534925e9.1 for ; Tue, 13 Feb 2024 12:52:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707857554; x=1708462354; 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=U99HAYnb6Ux+HIQV1PouI4Dctf15ABVlQ0E8tGdNkKw=; b=Sew45Nq4/0xn/LlaMhFOolCge2tbdiMzeHxKcLyfVwX+z+crVRZ78n510f9GWnnoZV 3/K75D02u2f3M0XPbn+rVJgxIl8apFUmxOkByT4IsNhusHmcHApAx/ZlazzJAYhcsLsQ JncRbrRNBjnhP046jIuss46zRk/Y4uw36j4KBVX0sxlQBw8XykvRgytbU1TXim8Dfsww 5j6Q7Zrnf1HdvYVKgmiJlFKaOlE3Q+hih9L8ODz1p9sEaXHcC0MZGaBW0EBgsSABWdOy DpFKatCH1mZRAFAEqtPqqsJ7WtQdZlr7GHjkt+fFfQ/lDMwNDAZk8fhcGVeYOGeb/vwC Qebw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707857554; x=1708462354; 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=U99HAYnb6Ux+HIQV1PouI4Dctf15ABVlQ0E8tGdNkKw=; b=B7RtFJfnt4MkSdKVEntiOWW2klZohyHGxrehOUCuTWbFVy85/Qpcm9XBcj/DzUb/7v 95vsiCZhOjBmEj4RLufK1qxND532wvInHfZjr3pYh+ih4X5va5aXSmRYrumrb/I6uUe+ hYeaDTeyhL4uxevlGjLKWrr5NbkfyFMFAWYG+l19Ti+8RDzXgw/yDTzsgcQFPrUQKzdZ SoS8tXnhf6TWaALEjaPnd7NS7C7cbtqcTzS6rEcCTAi29YeCUvmx2TIhsGEqX4oJV0Qc tnEor8lXB6caD88al9fjNMeD4QZlI/t56Z7G4YnQ2P+exnzsXxtKYKUwMJk7nSsKnfV5 +cVg== X-Gm-Message-State: AOJu0YyVdqbaaP8c3YIye7b4WJk5iPEmXinr2kXqAPn5q4j8UtXnyE3v nA5ZK9RjZTPd/mqaKuWvbtdzlwTDuKS+FIV9pfTZpEJ+mLe7dIMa6tqy0Pwl X-Google-Smtp-Source: AGHT+IGJEnyMvSCqvIuEX2QmxHcpJ6xwob6sqe+5YswXGPsCmCXJzUj3YZwN+Sx7uU4IhFkyF4cXEg== X-Received: by 2002:a05:600c:a49:b0:410:d3d9:91a1 with SMTP id c9-20020a05600c0a4900b00410d3d991a1mr504010wmq.10.1707857553999; Tue, 13 Feb 2024 12:52:33 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id jw21-20020a05600c575500b004101543e843sm12575619wmb.10.2024.02.13.12.52.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 12:52:33 -0800 (PST) Message-ID: <63edb68303fdd9ddd1c2e31ccf158ef4219cd0b9.1707857541.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 13 Feb 2024 20:52:21 +0000 Subject: [PATCH 12/12] t7527: update case-insenstive fsmonitor test Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jeff Hostetler , Jeff Hostetler From: Jeff Hostetler From: Jeff Hostetler Now that the FSMonitor client has been updated to better handle events on case-insenstive file systems, update the two tests that demonstrated the bug. Signed-off-by: Jeff Hostetler --- t/t7527-builtin-fsmonitor.sh | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/t/t7527-builtin-fsmonitor.sh b/t/t7527-builtin-fsmonitor.sh index 5cd68b2ea82..03af8539ca8 100755 --- a/t/t7527-builtin-fsmonitor.sh +++ b/t/t7527-builtin-fsmonitor.sh @@ -1116,16 +1116,17 @@ test_expect_success CASE_INSENSITIVE_FS 'fsmonitor subdir case wrong on disk' ' grep -q "dir1/DIR2/dir3/file3.*pos -3" "$PWD/subdir_case_wrong.log1" && + # Also verify that we get a mapping event to correct the case. + grep -q "map.*dir1/DIR2/dir3/file3.*dir1/dir2/dir3/file3" \ + "$PWD/subdir_case_wrong.log1" && + # The refresh-callbacks should have caused "git status" to clear # the CE_FSMONITOR_VALID bit on each of those files and caused # the worktree scan to visit them and mark them as modified. grep -q " M AAA" "$PWD/subdir_case_wrong.out" && grep -q " M zzz" "$PWD/subdir_case_wrong.out" && - # However, with the fsmonitor client bug, the "(pos -3)" causes - # the client to not update the bit and never rescan the file - # and therefore not report it as dirty. - ! grep -q " M dir1/dir2/dir3/file3" "$PWD/subdir_case_wrong.out" + grep -q " M dir1/dir2/dir3/file3" "$PWD/subdir_case_wrong.out" ' test_expect_success CASE_INSENSITIVE_FS 'fsmonitor file case wrong on disk' ' @@ -1246,12 +1247,14 @@ test_expect_success CASE_INSENSITIVE_FS 'fsmonitor file case wrong on disk' ' grep -q "fsmonitor_refresh_callback.*FILE-3-A.*pos -3" "$PWD/file_case_wrong-try3.log" && grep -q "fsmonitor_refresh_callback.*file-4-a.*pos -9" "$PWD/file_case_wrong-try3.log" && - # Status should say these files are modified, but with the case - # bug, the "pos -3" cause the client to not update the FSM bit - # and never cause the file to be rescanned and therefore to not - # report it dirty. - ! grep -q " M dir1/dir2/dir3/file-3-a" "$PWD/file_case_wrong-try3.out" && - ! grep -q " M dir1/dir2/dir4/FILE-4-A" "$PWD/file_case_wrong-try3.out" + # Also verify that we get a mapping event to correct the case. + grep -q "fsmonitor_refresh_callback map.*dir1/dir2/dir3/FILE-3-A.*dir1/dir2/dir3/file-3-a" \ + "$PWD/file_case_wrong-try3.log" && + grep -q "fsmonitor_refresh_callback map.*dir1/dir2/dir4/file-4-a.*dir1/dir2/dir4/FILE-4-A" \ + "$PWD/file_case_wrong-try3.log" && + + grep -q " M dir1/dir2/dir3/file-3-a" "$PWD/file_case_wrong-try3.out" && + grep -q " M dir1/dir2/dir4/FILE-4-A" "$PWD/file_case_wrong-try3.out" ' test_done