Article View: linux.kernel.git
Article #515[PATCH v2 5/7] stash create: rework temporary index creation
From: Phillip Wood
Date: Wed, 14 Oct 2026 15:40
Date: Wed, 14 Oct 2026 15:40
74 lines
10657 bytes
10657 bytes
From: Phillip Wood <phillip.wood@dunelm.org.uk>
Use create_index_from_tree() instead of reset_tree() when we create a
temporary index file to stash the working tree changes. This matches
what we do for "git stash push -p" and means we can avoid messing with
set_alternate_index_output(). Add a new parameter to control whether
the index is reset, as we need to merge the index rather than reset
it so that we still detect intent-to-add entries. We do not alter the
in-memory index so we can remove the call to repo_read_index_preload()
which saves one lstat() call per changed path.
Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
---
builtin/stash.c | 15 ++++-----------
1 file changed, 4 insertions(+), 11 deletions(-)
diff --git a/builtin/stash.c b/builtin/stash.c
index b4fe7465e4..ddeb5a5d2a 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -374,7 +374,7 @@ static int reset_tree(struct object_id *i_tree, int update, int reset)
}
static int create_index_from_tree(const struct object_id *tree_id,
- const char *index_path)
+ const char *index_path, bool reset)
{
int nr_trees = 1;
int ret = 0;
@@ -403,7 +403,7 @@ static int create_index_from_tree(const struct object_id *tree_id,
opts.src_index = the_repository->index;
opts.dst_index = &dst_istate;
opts.merge = 1;
- opts.reset = UNPACK_RESET_PROTECT_UNTRACKED;
+ opts.reset = reset ? UNPACK_RESET_PROTECT_UNTRACKED : 0;
opts.fn = oneway_merge;
if (unpack_trees(nr_trees, t, &opts)) {
@@ -1399,7 +1399,7 @@ static enum create_result stash_patch(struct stash_info *info,
goto done;
}
- if (create_index_from_tree(head_tree, stash_index_path.buf)) {
+ if (create_index_from_tree(head_tree, stash_index_path.buf, true)) {
ret = CREATE_ERROR;
goto done;
}
@@ -1458,22 +1458,15 @@ static int stash_working_tree(struct stash_info *info, const struct pathspec *ps
repo_init_revisions(the_repository, &rev, NULL);
copy_pathspec(&rev.prune_data, ps);
- set_alternate_index_output(stash_index_path.buf);
- if (reset_tree(&info->i_tree, 0, 0)) {
+ if (create_index_from_tree(&info->i_tree, stash_index_path.buf, false)) {
ret = -1;
goto done;
}
- set_alternate_index_output(NULL);
rev.diffopt.output_format = DIFF_FORMAT_CALLBACK;
rev.diffopt.format_callback = add_diff_to_buf;
rev.diffopt.format_callback_data = &diff_output;
- if (repo_read_index_preload(the_repository, &rev.diffopt.pathspec, 0) < 0) {
- ret = -1;
- goto done;
- }
-
add_pending_object(&rev, parse_object(the_repository, &info->b_commit),
"");
run_diff_index(&rev, 0);
--
2.56.0.134.g299a3c16181
Technical Details
Message-ID:
<f799d86f52796cc1b83788460568cc0d9849bed9.1791992404.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-72028-linux-kernel-git=dewy.ruReferences:
<cover.1791218125.git.phillip.wood@dunelm.org.uk> <cover.1791992404.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-72028-linux-kernel-git=dewy.ru
From: phillip.wood123@gmail.com (Phillip Wood)
Newsgroups: linux.kernel.git
Subject: [PATCH v2 5/7] stash create: rework temporary index creation
Date: Wed, 14 Oct 2026 16:40:17 +0100
Organization: Usenet Network
Message-ID: <f799d86f52796cc1b83788460568cc0d9849bed9.1791992404.git.phillip.wood@dunelm.org.uk>
References: <cover.1791218125.git.phillip.wood@dunelm.org.uk> <cover.1791992404.git.phillip.wood@dunelm.org.uk>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="2326172"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:gNiMpYy6IQP4KyEqj0fJAJlYI78= sha256:UsIENu/uFOESGq5h3AQrL2K33KfSp/M2bugGvFH4rPw=
sha1:G9ivdn8VBz2LJPwmCrm40haQUYE= sha256:1OBOwh6agXxygool+SDjxZi7kxgLeHXjokbYXyX8wQo=
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 23908110134; Wed, 14 Oct 2026 18:46:36 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: 0.352
X-Spam-Status: No, score=0.352 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001]
autolearn=no 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 5A4BfjjDgSlI;
Wed, 14 Oct 2026 18:46:33 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=git+bounces-72028-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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
by mail.dewy.ru (Postfix) with ESMTPS id DBA62110103; Wed, 14 Oct 2026 18:46:24 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1])
by tor.lore.kernel.org (Postfix) with ESMTP id 6A56847450; Wed, 14 Oct 2026 15:41:05 +0000 (UTC)
X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 4D7FE4E9C12;
Wed, 14 Oct 2026 15:40:49 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="A2ka4mU6"
X-Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44])
(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5A76555C316
for <git@vger.kernel.org>; Wed, 14 Oct 2026 15:40:43 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44
X-ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
t=1791992448; cv=none; b=cNKcRK9JxiykWjkCM5HSnseeMaEr7U6S5LKG57pDqCdBfT32sG+hqG631fp6rw0fINHIdkJ4iNEPGhIaxOokUSTQgh6ANtf1ph9DQgdOxCo4BF60lWLznfxWegxuOF8CK7hXkSR57wfsIYSrqmU+JVdL4Q7/x5Y0HXvbrgHP+oo=
X-ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org;
s=arc-20240116; t=1791992448; c=relaxed/simple;
bh=Umok2u1Q1oKtOY9QSiRGA7Mzv1OUoh8BC4iXMfQwi9g=;
h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:
MIME-Version; b=N8rTSwfHxfOMg34ZSbGs7EIGjZVZh9oZAEevUlcS0PzTIisGw1u+l//fAJRhwD8iRdwZXroR5WgfnWzmX/z8sGvRG1jdl0EaGLqhXoTaVwBR6jnM//rWotmfVehlyaGsLM93k4fV3CCi35tIQfwcxbehowMrV7/1lnSYOOKZnVQ=
X-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=A2ka4mU6; arc=none smtp.client-ip=209.85.128.44
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-f44.google.com with SMTP id 5b1f17b1804b1-4a1635f7c89so11643975e9.2
for <git@vger.kernel.org>; Wed, 14 Oct 2026 08:40:42 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20251104; t=1791992441; x=1792597241; 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=/vWwFfwAM3yQoT6XA+yzvPOPcbYCknX1WqvqDMgFrXo=;
b=A2ka4mU6wsNFg9e2WUGLTuAupq8LURTe72eh7+Vfb1KioSfRa06MdziWA0g/4PDa8K
Ti4+cEpxGDG0+CHOF8xYHg3oHA0m8oROK5n63b9rJjFgWh8vE6e8HzcF9PKO9LrRGTZc
gOcMhoWdE0sp5HhllDc1AO6luW87bY/J5ffqhK4Ekm9XMxLBr8MqvqzjGDTF0UneiWG2
Wb74qdyXJ6qOzIMdFml6pV/qFCGxeaijL50J4bpslS6BIHbnvUnGXe/c5eD1qU+aPjft
kiNAtfBDsJLVwJh7pK1+kKR0DhCeg5w7TE7T6feDCaQCW/1nhhGNml/DxxeUJEQwhvUH
8osw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1791992441; x=1792597241;
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=/vWwFfwAM3yQoT6XA+yzvPOPcbYCknX1Wq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a with SMTP id 5b1f17b1804b1-4a18e4e7a85mr309775845e9.30.1791992441092;
Wed, 14 Oct 2026 08:40:41 -0700 (PDT)
X-Received: from berwick ([2a0a:ef40:724:6601:f3ff:aebc:61f8:d91f])
by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48de0967acasm10324829f8f.2.2026.10.14.08.40.39
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Wed, 14 Oct 2026 08:40:40 -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.1791992404.git.phillip.wood@dunelm.org.uk>
X-Reply-To: Phillip Wood <phillip.wood@dunelm.org.uk>
X-Precedence: bulk
X-Mailing-List: git@vger.kernel.org
X-List-Subscribe: <mailto:git+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:git+unsubscribe@vger.kernel.org>