[PATCH v3 4/7] stash push: avoid duplicate calls to preload_index()
- From
- Phillip Wood <phillip.wood123@gmail.com>
- Date
- Oct 20, 2026, 15:20 UTC
- Message-ID
- <a9875ba5b3595adde9e830c1ccb641633bab7454.1792509606.git.phillip.wood@dunelm.org.uk>
- In-Reply-To
- <cover.1792509606.git.phillip.wood@dunelm.org.uk>
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