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

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

From
PWPhillip Wood <phillip.wood123@gmail.com>
Date
Oct 7, 2026, 13:49 UTC
Message-ID
<771a2364-7e5e-4d6f-be34-1764e609c514@gmail.com>
In-Reply-To
<xmqqpkxngfrw.fsf@gitster.g>
On 06/10/2026 13:44, Junio C Hamano wrote:
Show 8 quoted lines
> Phillip Wood <phillip.wood123@gmail.com> writes:
> >> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>>
>> Before it creates a stash, git checks if there are any unstaged,
>> or uncommitted changes. If there isn't anything to stash it bails
>> out. Since ef0f0b4509 (stash: optimize `get_untracked_files()`
>> and `check_changes()`, 2019-02-25) "git stash store" has checked
> > "store"?  Aren't we talking about "create"?
Sorry, it looks like I managed to confuse "create" with "store" when I wrote the message. It should be
stash create: remove duplicate changes detection

Before it creates a stash, git checks if there are any unstaged, or uncommitted changes. If there isn't anything to stash it bails out. Since ef0f0b4509 (stash: optimize `get_untracked_files()` and `check_changes()`, 2019-02-25) "git stash create" has checked for changes twice, once in create_stash() before we refresh the index and then again in do_create_stash() after the index has been refreshed. That commit claims it is an optimization but it is not clear what it is trying to optimize by checking for changes twice, especially as checking for changes before refreshing the index is unreliable (the scripted version of "git stash create", called "git update-index -q --refresh" before looking for any changes).

Avoid checking for changes twice by removing the call to check_changes_tracked_files() from create_stash() and restore the return code handling in create_stash() that was removed by ef0f0b4509 so that we continue to exit 0 when there are no changes to stash. In principle we could remove the call to check_changes() from do_create_stash() instead, but then we'd need to pass in the list of untracked files.

Thanks
Phillip
Show 10 quoted lines
> >> unreliable (the scripted version of "git stash store", called "git
>> update-index -q --refresh" before looking for any changes).
> > Ditto.
> >> Avoid checking for changes twice by removing the call to
>> check_changes_tracked_files() from store_stash() and restore the return
>> code handling in store_stash() that was removed by ef0f0b4509 so that
>> we continue to exit 0 when there are no changes to stash. In principle
>> we could remove the call to check_changes() from do_store_stash()
>> instead, but then we'd need to pass in the list of untracked files.
> > Again "(do_)?store" -> "\1create"?
Previous: Junio C HamanoNext: Phillip Wood
Message 4 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.