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: