πŸš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.git
Article #906

[PATCH v3 4/7] stash push: avoid duplicate calls to preload_index()

#906
From: Phillip Wood
Date: Tue, 20 Oct 2026 15:20
52 lines
12737 bytes
From: Phillip Wood <phillip.wood@dunelm.org.uk>

do_push_stash() needs to load the index so it can check that any
pathspec argument refers to tracked files. To do that it calls
repo_read_index_preload() which does not just load the index, it also
calls preload_index() which lstat()s all the files to see which ones
are up-to-date. do_create_stash() then calls repo_read_index_preload()
for a second time which lstat()s all the changed paths again and then
calls repo_refresh_and_write_index() which invokes preload_index() for a
third time. So we're preloading the index three times when we only need
to do it once. Avoid this by making the callers of do_create_stash()
responsible for reading the index and use repo_read_index() rather
than repo_read_index_preload(). This saves two lstat() calls per
changed path.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
---
 builtin/stash.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/builtin/stash.c b/builtin/stash.c
index aec79ed473..b4fe7465e4 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -1526,7 +1526,6 @@ static enum create_result do_create_stash(const struct pathspec *ps,
 
 	prepare_fallback_ident("git stash", "git@stash");
 
-	repo_read_index_preload(the_repository, NULL, 0);
 	if (repo_refresh_and_write_index(the_repository, REFRESH_QUIET, 0, 0,
 					 NULL, NULL, NULL) < 0) {
 		ret = error(_("could not write index"));
@@ -1662,6 +1661,7 @@ static int create_stash(int argc, const char **argv, const char *prefix UNUSED,
 
 	memset(&ps, 0, sizeof(ps));
 
+	repo_read_index(the_repository);
 	ret = do_create_stash(&ps, &stash_msg_buf, 0, 0, NULL, 0, &info,
 			      NULL, 0);
 	if (ret == CREATE_SUCCESS)
@@ -1707,7 +1707,7 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q
 		goto done;
 	}
 
-	repo_read_index_preload(the_repository, NULL, 0);
+	repo_read_index(the_repository);
 	if (!include_untracked && ps->nr) {
 		char *ps_matched = xcalloc(ps->nr, 1);
 
-- 
2.56.0.134.g299a3c16181
Technical Details
Message-ID: <a9875ba5b3595adde9e830c1ccb641633bab7454.1792509606.git.phillip.wood@dunelm.org.uk>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-72552-linux-kernel-git=dewy.ru
References: <cover.1791218125.git.phillip.wood@dunelm.org.uk> <cover.1792509606.git.phillip.wood@dunelm.org.uk>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-72552-linux-kernel-git=dewy.ru
From: phillip.wood123@gmail.com (Phillip Wood)
Newsgroups: linux.kernel.git
Subject: [PATCH v3 4/7] stash push: avoid duplicate calls to preload_index()
Date: Tue, 20 Oct 2026 16:20:39 +0100
Organization: Usenet Network
Message-ID: <a9875ba5b3595adde9e830c1ccb641633bab7454.1792509606.git.phillip.wood@dunelm.org.uk>
References: <cover.1791218125.git.phillip.wood@dunelm.org.uk> <cover.1792509606.git.phillip.wood@dunelm.org.uk>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3883323"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:t4hOojIqfmgBw2b1aNraenDEn1c= sha256:To1QY9PzDbkFDDGOmRskEsFfyunY8Wt03cXZxBIv4qY=
	sha1:4ErrJ2ww85SY2vY2JO5LEVEDkug= sha256:iJtyUbv+rbWeK8RL9xtfgboNThAGcI8DrE6gf4V+dU4=
List-ID: <git.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id DD06F110D4E; Tue, 20 Oct 2026 18:28:04 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -1.948
X-Spam-Status: No, score=-1.948 tagged_above=-9999 required=6.31
	tests=[DCC_CHECK=1.1, DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
	FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id a3HyGhzJYonQ;
	Tue, 20 Oct 2026 18:28:02 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=git+bounces-72552-linux-kernel-git=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 66025110C79; Tue, 20 Oct 2026 18:27:54 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 57E03479DD; Tue, 20 Oct 2026 15:21:16 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1792509663;
	b=1Y7d8TbQJ1/ZD/DS47vBD8y0wgydlmq/0lFfX/Cc4PGmw+ldeuTR8l764vAHk5iUUsyv
	 9fxze6rAbYghPv4b1cNQGi4zoCLW+smq4XCpgBL5WVnLro5aQAwZjg0P4Vr5LlILSaqQh
	 0zmVYbAgR7W+XBEBP+4XC+Bmo8XpwCG1RjURqgQeDUxJON7iy4YCjjt3eaILvHSymroaC
	 py0QYH2xNyu/soFXKnz0rDmtEWr6bMxbWi7B0bxJfN+0Qv8prYjiIb2CLJGfdxeEF384i
	 +nSBxCJ9EU4/U9QFsH5z92Um/KPMybmEAJxR6geMmB+BR+hXBdsY05+nyVKecMRGxdQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792509663;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
	 X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
	 Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:
	 References:Reply-To:X-Mailing-List:List-Id:List-Post:List-Help:
	 List-Subscribe:List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Transfer-Encoding;
	bh=8gxvILfny4AJqOd+78eY8j1hngOmrkmVucA4OiGoloE=;
	b=HumORKL+4XfQ7jT3iFt1GEYh/4gxp++/hY3TaGGJRNDnYPfZ8w4DLYMlbDV24MxSVAMY
	 kJ1KB72IrxmOWL73pPyN61UP/HqJyT1OHCa3jtvDQLxtGbMqmdWgaQ2V94SYv8ahggJoc
	 tR1mRc4SjNqZXJKDFayiz2eKEvDPYlLpjbXrN5BXWdxClX5WdfU83scXC6U1Gv0lsF5EP
	 2TcsY8wmOmy+DX4IPytbYUQ31jnfsI7czm3BlKHxHVHo5hhP8aC2eIBe1FjZgwk+E98j1
	 rjnqCSp+Z14xq02FfBNt3HPhJIy2bjw+Rt2gMRG2tD5YtrS8cWB4TG5WgE7Sjjtwimg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b="owUI/Um5";
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id D229C60A3802;
	Tue, 20 Oct 2026 15:21:03 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=owUI/Um5
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.45
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1792509663;
	b=ClJTJPtDCCE3pdnCshKoRBS/r2CPhQvyhXfcLVffiUZK3lYpfzc7C4iyN6MXHKTtITUE
	 PjEGcixBabocG1ZNihGUXcznS4JSwhJW4DSoWy8ARIPqrwF2MYEqM//TKYmcbNRgxRWMb
	 tzR42MMXcGIYz6qI2umtVZx+WfKNWRBLdzhOiaAa18l9OxH7kZHxcUXuwJ4zOr0jsiCto
	 SJC3k+M7pyRV4v1peIL3NK7CyKCTPkjT1BtdsVdvYRiGtDvneeBK+Qg4HSSM67ByVUrgj
	 czjN2pk5idMbBHGhbIU1SZDe2Qq3OAftldPifGOSfKpeKMIedWL0uXVdHsYqvH1298w==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792509663;
	h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
	 X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:
	 Date:Message-ID:X-Mailer:In-Reply-To:References:Reply-To:MIME-Version:
	 Content-Transfer-Encoding;
	bh=8gxvILfny4AJqOd+78eY8j1hngOmrkmVucA4OiGoloE=;
	b=hA89IOl0uCh6b0pzvZm18T3SzLzIRjzFXHMRsI/QiCIrKahxbPvsCdeCW6/XSk8wul8J
	 zOXnoMMP4oPmZAQDARBf28KzhgsO9bs+5jWRkmRC10A8WsV+ltQvOA384L2eio/PUQlgZ
	 StlYQZ2X54ndzpf3yNsLsXyGn0y03H3f8N4GzkGdiwhUoXUpW7AUd0GIYrU56wmbyFz0h
	 T/BD3avCR/1xKR8gJFqgIvQaIfraFp634EzWVFGxdYb72yoyU1Uuq+FaIHJ6YvjQBmerz
	 gZY5PsomD9XqbIcWf89x1kVYqjGn/fjfG1/1wHLlasq8tnqI+IcqsbPZcENUyXPSFaw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b="owUI/Um5";
	arc=none smtp.remote-ip=209.85.128.45
X-Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9C167606A330
	for <git@vger.kernel.org>; Tue, 20 Oct 2026 15:21:02 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9C167606A330
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-4a1dec056ddso19210105e9.1
        for <git@vger.kernel.org>; Tue, 20 Oct 2026 08:21:02 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20251104; t=1792509661; x=1793114461; darn=vger.kernel.org;
        h=content-transfer-encoding:mime-version:reply-to:references
         :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject
         :date:message-id:reply-to:content-type;
        bh=8gxvILfny4AJqOd+78eY8j1hngOmrkmVucA4OiGoloE=;
        b=owUI/Um5uciemAA0kHg0eWhGJyd5iqFql9uGMQEak+AG4Bn5ar0oE2KfwBkDHwbrcX
         rB7OGxAPdiCYnWm7WseAaN3kUPuJr7KSLDqYeD7rfXTxoXMRdKLFEmtdvf49Iv7+lTeJ
         M0/R1tyctJVZaRpddIiN3WJmsngPvncLJ/WkXkC5B38LFKV/samDfDE7Yn/QbV4kibeE
         QHna+oG5WZeE8bPxvykvImaK9Nacs55adKO4ioZNqqNQ084C9soxqK4el5YDs5w6CG6Y
         jXzwaSYFK/tbs34eBUj2SBYXaYcUD9w97VazgHDQ5ylFdrpN/4m3NciOxXrdf3SWhYdj
         PT7A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1792509661; x=1793114461;
        h=content-transfer-encoding:mime-version:reply-to:references
         :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg
         :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to
         :content-type;
        bh=8gxvILfny4AJqOd+78eY8j1hngOmrkmVucA4OiGoloE=;
        b=GA1yMQQG4UbTtMeeGgtd6ptfFFMmdducH1yKGI8mQaA5XufEwzVfHXw8hLvOQik2FJ
         bQhTuw21hNW4i+6AoV4M65rPq8G6isII59b69b7NvNDJ04hk6GNB932EotKCYJ4ObZI5
         WFI76rCJKeh2Smo6IXNLB1P+b+pq0Kc9NhP1kiHaUhyep54MKtoQ2ORVWAQbjsdgoVRE
         2ul/oWjeWU3PjfJYCR41/gF/H2ZpvM8Jq4YfmMQZF7oZlt8fG4IgFqegL4yiP3msKHGu
         YwHRYR76EpmIVJG9WzHTtnNDT5amW9RnbjCz196U0fFdGvj2QglPJnFjb1nKHz/Tf8lb
         qVDQ==
X-Gm-Message-State: AFq9FYIkW27CNkt5Ydrok0cvu/yzRVNOzFcXD+nIdp/bveXCsOq8hYah
	TTCxaaPG7SXk32j0e3pil81rWQdA/WKQDe1LT8QA5r729DzQcTJJ0Ip1D610/A==
X-Gm-Gg: AYBFou1IY6/gkUKEqKP66zt9ANp5csDMYMDkRcJwYZ4wzpobQclN0AJdBiMR1HOEqED
	IhxLbhwx4bwLFEIr45znFPD9zoAElaOhscFDpqZa3UqphVwFjEGlN0QFt/rMIIA6nYCe9DW0Spz
	ZY484333LCy1BmzAmK40mBDeApswRUkmdj98cmAd8ObJ9wrHzoEObhsWbeSGkz7dHRRNbcGJ/DC
	s72zGpi03DfoxKkQ078Xbb6AQAVGj1nRimO0BnPZSKMFkNPKbhnqkbPsfT42aIKvMzfisqVVOLo
	NkRryxzIeDk0bKWwNy6BvSTsMsBylr3YqAWRZdml8HqN3CEqbxEpNyKJPlaLBfl4VSOeGyN8HfZ
	Mj9lJdV+JiWJLHwcjxxlKrd57Z9HSbAr79HiD1p5aj6h9QlVqCKQbK3xOOszEfnXj1zU0lAiD7J
	JmY8bFYNLnc0QApPrjHcgNSBOhmB4nttg6qXu6wYz0ikd1lQ8/CRBUyAW26yAvvvgqMbKpUtVWq
	Q==
X-Received: by 2002:a05:600c:4e8a:b0:4a1:d307:b52a with SMTP id 5b1f17b1804b1-4a1d7628838mr247659565e9.19.1792509660365;
        Tue, 20 Oct 2026 08:21:00 -0700 (PDT)
X-Received: from berwick ([2a0a:ef40:724:6601:f3ff:aebc:61f8:d91f])
        by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e1d823ca7sm6307355f8f.38.2026.10.20.08.20.59
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Tue, 20 Oct 2026 08:20:59 -0700 (PDT)
X-Cc: 重田一聖 <kazumasa.shigeta@kanamei.com>,
	Phillip Wood <phillip.wood123@gmail.com>
X-Mailer: git-send-email 2.56.0.134.g299a3c16181
X-In-Reply-To: <cover.1792509606.git.phillip.wood@dunelm.org.uk>
X-Reply-To: Phillip Wood <phillip.wood@dunelm.org.uk>
X-Mailing-List: git@vger.kernel.org
X-List-Post: <mailto:git@vger.kernel.org>
X-List-Help: <mailto:git+help@vger.kernel.org>
X-List-Subscribe: <mailto:git+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:git+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:git+owner@vger.kernel.org>
X-Precedence: list