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

Re: [PATCH 2/2] stash push: remove duplicate changes detection

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 7, 2026, 17:15 UTC
Message-ID
<xmqqa4opa0up.fsf@gitster.g>
In-Reply-To
<725487d3-5a07-40c6-a603-990a661e0193@gmail.com>
Phillip Wood <phillip.wood123@gmail.com> writes:
Show 23 quoted lines
>> Before the precontext of this hunk, repo_refresh_and_write_index()
>> is called to refresh the index.  We used to leave early when
>> check_changes() saw no need to save.  We no longer do so, and
>> instead keep going.
>> 
>>> @@ -1743,8 +1737,15 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q
>>>   
>>>   	if (stash_msg)
>>>   		strbuf_addstr(&stash_msg_buf, stash_msg);
>>> -	if (do_create_stash(ps, &stash_msg_buf, include_untracked, patch_mode,
>>> -			    interactive_opts, only_staged, &info, &patch, quiet)) {
>>> +	ret =  do_create_stash(ps, &stash_msg_buf, include_untracked,
>>> +			       patch_mode, interactive_opts, only_staged, &info,
>>> +			       &patch, quiet);
>> 
>> And we call do_create_stash().  The first thing it does is to call
>> repo_read_index_preload() and repo_refresh_and_write_index().
>> 
>> Are we refreshing the index twice now, even though we know nothing
>> has changed in between, when we run "git stash push"?
>
> We've always been doing that when there is something to stash (which is 
> the normal case).

So when there is nothing to stash, we only refreshed once but now refreshing twice is not a regression?

Show 6 quoted lines
> To avoid that we need to make the callers of do_create_stash()
> responsible for refreshing the index.  At the moment
> create_stash() calls do_create_stash() without evening reading the
> index, but do_push_stash() needs to read the index to check if it
> the pathspec contains paths that don't match the index. That would
> also avoid calling preload_index() multiple times.

Yes, that exactly is the right direction. Then we can reduce the number of check_changes() without increasing the number of refreshes, right?

Thanks.
Previous: Phillip WoodNext: Phillip Wood
Message 8 of 9 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

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.