πŸš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.git
Article #1287

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

#1287
From: Phillip Wood
Date: Fri, 23 Oct 2026 15:03
52 lines
12788 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 7259f6374ce..8db75d9e135 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"));
@@ -1672,6 +1671,7 @@ static int create_stash(int argc, const char **argv, const char *prefix UNUSED,
 
 	memset(&ps, 0, sizeof(ps));
 
+	repo_read_index(the_repository);
 	create_res = do_create_stash(&ps, &stash_msg_buf, 0, 0, NULL, 0, &info,
 				     NULL, 0);
 	if (create_res == CREATE_SUCCESS)
@@ -1717,7 +1717,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: <32f7c97b7c06402aa6f2c16b3d0d3407a0421ba7.1792767795.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-73044-linux-kernel-git=dewy.ru
References: <cover.1791218125.git.phillip.wood@dunelm.org.uk> <cover.1792767794.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-73044-linux-kernel-git=dewy.ru
From: phillip.wood123@gmail.com (Phillip Wood)
Newsgroups: linux.kernel.git
Subject: [PATCH v4 4/7] stash push: avoid duplicate calls to preload_index()
Date: Fri, 23 Oct 2026 16:03:32 +0100
Organization: Usenet Network
Message-ID: <32f7c97b7c06402aa6f2c16b3d0d3407a0421ba7.1792767795.git.phillip.wood@dunelm.org.uk>
References: <cover.1791218125.git.phillip.wood@dunelm.org.uk> <cover.1792767794.git.phillip.wood@dunelm.org.uk>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="530137"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:WOfcSW/NuX8Wg2fb/0AvurJHaxw= sha256:beXRwpGxD7pj9iwAPqaRlKrxOAj6bnoBJtke2XSEdZo=
	sha1:8SiR1Y9wvYMJXu0BB7QblyFZlAU= sha256:/xJVCjhPyJrarvrEFfPiPciAfze7EMoPkiIpr8HgOfc=
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 91B501114F6; Fri, 23 Oct 2026 18:04:18 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.148
X-Spam-Status: No, score=-2.148 tagged_above=-9999 required=6.31
	tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
	FORGED_GMAIL_RCVD=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 4qJ3j3HsXSrm;
	Fri, 23 Oct 2026 18:04:16 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=git+bounces-73044-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 sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
	by mail.dewy.ru (Postfix) with ESMTPS id 00A341114E8; Fri, 23 Oct 2026 18:04:07 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sto.lore.kernel.org (Postfix) with ESMTP id 724D5609E4E; Fri, 23 Oct 2026 15:03:59 +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=1792767839;
	b=tALT20KTl/J64WZ+ZAHyYmed5CuHarBQGuDgP+QG8U9Jl4V9sqD7hJ0EsHYy1ssxmYPc
	 72euk7Ic11k2L17g8seTloZkBezviVJejSbSw4RMD+u5q8ek2fy63DoRwYQO4eaYawoz7
	 ijtdpOkGEh0aF5zY6MGWbe4OAawVo5aTJgKNKf5P/l9yl0BS0fzdbeMmEWk54G94SSez0
	 5iGsWu/ltkr41SzOnr4drpQ7PLMmgSbcSJYo4EIwEdQVCfsEVDiYrRHhLkaxrpIA0IJ3b
	 iW6iCczbrTsuYTCMWw5T1UR+GKOhXBkjIj7s4qR/9f61+wnFPvr0fPPylvI9hgkWipA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792767839;
	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=bDRYeBaKtl8mi59Maaa2jsMY0p+F9HxO4yQnurRekBg=;
	b=5qer9ME8ExqYEpEdtjQ6L03aF+9PPTz1V/tXQ4ui+YEkiv7WbX6wi/u/W6TcWWwos1ru
	 bQf8FmskrlxXJK0oKpbfsw/ft8RzcC3hMwr1izMDYBhb3Xau9cuLG3MVcEZBwau00WsDT
	 5azPUx1mVGmjwvsfShetaCle8X+i7DCS5hZaCgqTsWXR81SRvkIa7woIgD2WW8ZzuIENR
	 CQ5PBELO31fhqrViN5upJnctOrpLy5sQYcmGlz6gJU2ZvOlQZVbkT43NQWsupA7BV+usc
	 wlx79R6+6N64AzoxqfTKWcAlVu7pFRy3LfiltXfXCAR9zQ5bYnPrx/UuWSl9Vux8tOw==
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="mLFOnSX/";
	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 12F86606A31A;
	Fri, 23 Oct 2026 15:03:59 +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=mLFOnSX/
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.49
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1792767833;
	b=vAhmRWLmTNg9TPj59iGzPtYmwhKM9L/I2Vg+oEK3vPsv+HEYrvYAcYjuvAPTYfE2QYUW
	 ajbU4cVT7FjhLmoskxy+WybQb8S1Ve5sqSUqpcfMDo5VRP87q0c1FzwtYAqFDupqrBMNY
	 uOZj8YV8mxTtzjIflyReCmV4VHOT6O2b5Uve0lJKap2GZtecHOg8Vr5cT7TnZis5jQOtn
	 8Z27/vUvPZpiVj+DqsVSowBBmHgbKYH7Kj8M0tFtFePRfHytuCrc4E1MkOY5/xbQEeTvm
	 l0JD14j7a3ulQ74nRrbGdbNW2VD591Qw83G4BTOJKSaZR1dtlbkc0pVj31+u2HSQovQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792767833;
	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=bDRYeBaKtl8mi59Maaa2jsMY0p+F9HxO4yQnurRekBg=;
	b=FHmB6VRumdp29YxFDzVHxwJtcaFJaTbgTqHaOEE97Hcv+kfUHUKwGDi6TuJPHC6UvVGN
	 U6eRVyedHXsXv1CUB0D9Hhtvg+pytXsvLPeyffJBEHolQWvtPLTLdvUu6t2987h1itO0n
	 BzZ8I9x4zweUT1UI4DHSzLaooLeiJ1Plh6XH/A8YU4QEjuTF9BLSmnz5mlf6JkE9IPWgn
	 DZcK02WdatRCvyo1Mdi5FOqKMUsDSfEErZcoPJ/X4m4QVLSp4whKsSv+o/ZnE3pjR5WbA
	 QqRibyvAR8zzSJEI284FjlvaTITQHH+SBxA4EG6UpShxs5l5qxWIBjZKryfQ4yK1EKQ==
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="mLFOnSX/";
	arc=none smtp.remote-ip=209.85.221.49
X-Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49])
	(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 DE774606A327
	for <git@vger.kernel.org>; Fri, 23 Oct 2026 15:03:52 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DE774606A327
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-wr1-f49.google.com with SMTP id ffacd0b85a97d-48dee593f18so699881f8f.3
        for <git@vger.kernel.org>; Fri, 23 Oct 2026 08:03:52 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20251104; t=1792767831; x=1793372631; 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=bDRYeBaKtl8mi59Maaa2jsMY0p+F9HxO4yQnurRekBg=;
        b=mLFOnSX/nSKkXlGdW1hEQHsvp43voPh+9uQX3OFNKLuj/kmMNk7sve/i3bi9j/IGz4
         o21Wtay81AGYnpO+BWS3tMGWkPVpBXZcz2ca/vkylmbZK71XRpPls7p+uArG0Yrt7BPk
         TEGV0BeslykrS0gFCbuzlh0IDds45j73Q+7O4zmfionJXGl61/q3AbGszSHDijE0jzfr
         OHI/kobupsEJrHC1vd/qtIFtScvRl0CCTNN86rv5QokbbAFpxvkzmG/9ZxSF5+1sk2vY
         ppsL0Y8YhdS6C57y7ekDb+FVXUbXmDifh5Ricw2cm9rOmuq6tRqpsoj0awmissxu1THn
         4YrQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1792767831; x=1793372631;
        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=bDRYeBaKtl8mi59Maaa2jsMY0p+F9HxO4yQnurRekBg=;
        b=AuVWruNsMJu4dMQVHFfjT9j5+E+o+hIdEH1nFRvE52/YaEhMcMBvGka8BKYqP+UYwn
         bJko0Bncn0IyY6IM163rYWQWezlwOfaLnoHB9B+oQHSxGnbyiT7q57Qzl/exIvq97h52
         q6zy+0+Tdq1FeV5piEyjCJkkH/UWozSploAkZkfqrDM8s0d2f9sL7gnofJkxBWb60m4B
         kloPBhQXP5IjoQL5fcp8F6640iJH/nrP7lDZdtn/3TmM+X7hAd1AH3rInP+zH8e2huaT
         3pnK9feZKj/cZV07btRUS3hT38OknWIrr4En8oShVHt8dBPjwi2lovivmms234HrmSen
         q4Rw==
X-Gm-Message-State: AFq9FYJ4StGOgUX7EF03SSTHwwtegn5Na8oGBfPbVJq9G4tuzelsfwxp
	aSukyUq9vrOnQP5LHRQsRVQwNLXC724Qc8H6f1uE/7qHskYPDvB1wZeobfp83w==
X-Gm-Gg: AYBFou0M4zebQc2npPDfBFc0bmO/h2mCnyekWJospjz3DaduK+Z3l7LCbyfKkKEvspJ
	eINmVRHrAnSD1jj+6u5gKjI09sBAuhtyJbcyoqtg6eyowoIp/TnpT+xomIjvXs2IJgbA3Ruh2rX
	ZDJ4KW4cU9Y38wPW5QS93aAOEoQCMIHtWD2sR7LvT9dkYPIWANoX23NPBv/Kjk6g0laFqTjyGUL
	U9PDh8T5UjFjvXsStnbwedQzzntJfqd21q8r3liMH8Cb5CNnoMKPGjdP4F12G8OloMguNikcLuK
	p52HScStNmO2l2cqNxqwHgVG7uDvDi+KPGydKX0oZ+/qHKdg/Dw9RWW8yi39Zy2wnJcO9e7+rlK
	hzigFv+aW8bB2QDEXrVyGOFLfo5tGlqLlVtUKwUSHdhLWZAVc87SjlHTCxwd9EttyiX6z0eoDLZ
	1yBuH08EZvleHgKTJxOdZz6RVGCAinew2vjNZHbCGuBuJYZD/AE38liF7+5rUe8GYNxddZpFi/t
	gdA4dkfa5b30Owv2Z+8+LW71ltg5wSTQu0cyM/hZRryhgrb2inJbjR5gGE=
X-Received: by 2002:adf:e18e:0:b0:48d:f3a4:610b with SMTP id ffacd0b85a97d-48e385945efmr4870645f8f.25.1792767831230;
        Fri, 23 Oct 2026 08:03:51 -0700 (PDT)
X-Received: from berwick ([2a0a:ef40:724:6601:f3ff:aebc:61f8:d91f])
        by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e3d427e68sm296326f8f.52.2026.10.23.08.03.50
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Fri, 23 Oct 2026 08:03:50 -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.1792767794.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