From: Junio C Hamano <gitster@pobox.com>
To: Phillip Wood <phillip.wood123@gmail.com>
Cc: git@vger.kernel.org, 重田一聖 <kazumasa.shigeta@kanamei.com>
Subject: Re: [PATCH v2 4/7] stash push: avoid duplicate calls to preload_index()
Date: Wed, 14 Oct 2026 11:09:40 -0700 [thread overview]
Message-ID: <xmqqy0c0rw63.fsf@gitster.g> (raw)
In-Reply-To: <6ca7e1c567a9e31d6668e59df81cd793e2b3411e.1791992404.git.phillip.wood@dunelm.org.uk> (Phillip Wood's message of "Wed, 14 Oct 2026 16:40:16 +0100")
Phillip Wood <phillip.wood123@gmail.com> writes:
> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>
> do_stash_push() needs to load the index so it can check that any
Perhaps you meant do_push_stash()?
> 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.
The other caller of do_create_stash() is create_stash(). And it
does not need to call the preload version for the same reason.
> 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);
next prev parent reply other threads:[~2026-10-14 18:09 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-05 16:35 [PATCH 0/2] stash: stop checking for changes twice Phillip Wood
2026-10-05 16:35 ` [PATCH 1/2] stash create: remove duplicate changes detection Phillip Wood
2026-10-06 12:44 ` Junio C Hamano
2026-10-07 13:49 ` Phillip Wood
2026-10-05 16:35 ` [PATCH 2/2] stash push: " Phillip Wood
2026-10-06 14:27 ` Junio C Hamano
2026-10-07 13:46 ` Phillip Wood
2026-10-07 17:15 ` Junio C Hamano
2026-10-08 13:35 ` Phillip Wood
2026-10-14 15:40 ` [PATCH v2 0/7] stash creation: avoid unecessary index loads and refreshes Phillip Wood
2026-10-14 15:40 ` [PATCH v2 1/7] stash: use an enum for create status Phillip Wood
2026-10-14 15:40 ` [PATCH v2 2/7] stash create: remove duplicate changes detection Phillip Wood
2026-10-14 15:40 ` [PATCH v2 3/7] stash push: " Phillip Wood
2026-10-14 15:40 ` [PATCH v2 4/7] stash push: avoid duplicate calls to preload_index() Phillip Wood
2026-10-14 18:09 ` Junio C Hamano [this message]
2026-10-14 15:40 ` [PATCH v2 5/7] stash create: rework temporary index creation Phillip Wood
2026-10-14 18:16 ` Junio C Hamano
2026-10-14 15:40 ` [PATCH v2 6/7] stash create: remove unnecessary index load and refresh Phillip Wood
2026-10-14 18:21 ` Junio C Hamano
2026-10-14 15:40 ` [PATCH v2 7/7] stash: simplify reset_tree() function signature Phillip Wood
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqy0c0rw63.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=kazumasa.shigeta@kanamei.com \
--cc=phillip.wood123@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox