git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 14, 2026, 18:09 UTC
Message-ID
<xmqqy0c0rw63.fsf@gitster.g>
In-Reply-To
<6ca7e1c567a9e31d6668e59df81cd793e2b3411e.1791992404.git.phillip.wood@dunelm.org.uk>
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()?
Show 11 quoted lines
> 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.

Show 33 quoted lines
> 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);
Previous: Phillip WoodNext: Phillip Wood
Message 15 of 47 in “stash: stop checking for changes twice”
  1. 0/2 stash: stop checking for changes twicePhillip Wood, Oct 5, 2026
  2. 1/2 stash create: remove duplicate changes detectionPhillip Wood, Oct 5, 2026
  3. Junio C HamanoOct 6, 2026
  4. Phillip WoodOct 7, 2026
  5. 2/2 stash push: remove duplicate changes detectionPhillip Wood, Oct 5, 2026
  6. Junio C HamanoOct 6, 2026
  7. Phillip WoodOct 7, 2026
  8. Junio C HamanoOct 7, 2026
  9. Phillip WoodOct 8, 2026
  10. 0/7 stash creation: avoid unecessary index loads and refreshesPhillip Wood, Oct 14, 2026
  11. 1/7 stash: use an enum for create statusPhillip Wood, Oct 14, 2026
  12. 2/7 stash create: remove duplicate changes detectionPhillip Wood, Oct 14, 2026
  13. 3/7 stash push: remove duplicate changes detectionPhillip Wood, Oct 14, 2026
  14. 4/7 stash push: avoid duplicate calls to preload_index()Phillip Wood, Oct 14, 2026
  15. Junio C HamanoOct 14, 2026
  16. 5/7 stash create: rework temporary index creationPhillip Wood, Oct 14, 2026
  17. Junio C HamanoOct 14, 2026
  18. Phillip WoodOct 20, 2026
  19. 6/7 stash create: remove unnecessary index load and refreshPhillip Wood, Oct 14, 2026
  20. Junio C HamanoOct 14, 2026
  21. 7/7 stash: simplify reset_tree() function signaturePhillip Wood, Oct 14, 2026
  22. 0/7 stash creation: avoid unecessary index loads and refreshesPhillip Wood, Oct 20, 2026
  23. 1/7 stash: use an enum for create statusPhillip Wood, Oct 20, 2026
  24. Junio C HamanoOct 21, 2026
  25. Phillip WoodOct 22, 2026
  26. Junio C HamanoOct 22, 2026
  27. Phillip WoodOct 22, 2026
  28. 2/7 stash create: remove duplicate changes detectionPhillip Wood, Oct 20, 2026
  29. 3/7 stash push: remove duplicate changes detectionPhillip Wood, Oct 20, 2026
  30. 4/7 stash push: avoid duplicate calls to preload_index()Phillip Wood, Oct 20, 2026
  31. 5/7 stash create: rework temporary index creationPhillip Wood, Oct 20, 2026
  32. Junio C HamanoOct 20, 2026
  33. 6/7 stash create: remove unnecessary index load and refreshPhillip Wood, Oct 20, 2026
  34. 7/7 stash: simplify reset_tree() function signaturePhillip Wood, Oct 20, 2026
  35. Junio C HamanoOct 21, 2026
  36. 0/7 stash creation: avoid unecessary index loads and refreshesPhillip Wood, Oct 23, 2026
  37. 1/7 stash: use an enum for create statusPhillip Wood, Oct 23, 2026
  38. 2/7 stash create: remove duplicate changes detectionPhillip Wood, Oct 23, 2026
  39. 3/7 stash push: remove duplicate changes detectionPhillip Wood, Oct 23, 2026
  40. 4/7 stash push: avoid duplicate calls to preload_index()Phillip Wood, Oct 23, 2026
  41. 5/7 stash create: rework temporary index creationPhillip Wood, Oct 23, 2026
  42. Junio C HamanoNov 5, 2026
  43. 6/7 stash create: remove unnecessary index load and refreshPhillip Wood, Oct 23, 2026
  44. Junio C HamanoNov 6, 2026
  45. 7/7 stash: simplify reset_tree() function signaturePhillip Wood, Oct 23, 2026
  46. Junio C HamanoNov 6, 2026
  47. Junio C HamanoNov 5, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.