🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.git
3 messages
3 total messages Started by Phillip Wood Wed, 07 Oct 2026 13:46
Re: [PATCH 2/2] stash push: remove duplicate changes detection
#11
Author: Phillip Wood
Date: Wed, 07 Oct 2026 13:46
85 lines
11150 bytes
On 06/10/2026 15:27, Junio C Hamano wrote:
> Phillip Wood <phillip.wood123@gmail.com> writes:
> 
>> diff --git a/builtin/stash.c b/builtin/stash.c
>> index 9a5006e3d92..79fdfff09a2 100644
>> --- a/builtin/stash.c
>> +++ b/builtin/stash.c
>> @@ -1538,7 +1538,7 @@ static int do_create_stash(const struct pathspec *ps, struct strbuf *stash_msg_b
>>   	}
>>   
>>   	if (!check_changes(ps, include_untracked, &untracked_files)) {
>> -		ret = 1;
>> +		ret = 2;
>>   		goto done;
>>   	}
> 
> It may be time for us to introduce symbolic constants once we have
> three choices instead of two.

That makes sense

>> @@ -1728,12 +1728,6 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q
>>   		goto done;
>>   	}
>>   
>> -	if (!check_changes(ps, include_untracked, &untracked_files)) {
>> -		if (!quiet)
>> -			printf_ln(_("No local changes to save"));
>> -		goto done;
>> -	}
>> -
>>   	if (!refs_reflog_exists(get_main_ref_store(the_repository), ref_stash) && do_clear_stash()) {
>>   		ret = -1;
>>   		if (!quiet)
> 
> 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). 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.

> do_create_stash() does call check_changes() to return early without
> creating stash, so we did save the cost of check_changes() with this
> patch, though.

Yes, lets add another patch to avoid unnecessarily refreshing the index 
as well.

Thanks

Phillip

>> +	if (ret == 2) {
>> +		if (!quiet)
>> +			printf_ln(_("No local changes to save"));
>> +		ret = 0;
>> +		goto done;
>> +	} else if (ret) {
>>   		ret = -1;
>>   		goto done;
>>   	}
Re: [PATCH 2/2] stash push: remove duplicate changes detection
#31
Author: Junio C Hamano
Date: Wed, 07 Oct 2026 17:15
42 lines
11490 bytes
Phillip Wood <phillip.wood123@gmail.com> writes:

>> 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?

> 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.
Re: [PATCH 2/2] stash push: remove duplicate changes detection
#98
Author: Phillip Wood
Date: Thu, 08 Oct 2026 13:35
54 lines
10633 bytes
On 07/10/2026 18:15, Junio C Hamano wrote:
> Phillip Wood <phillip.wood123@gmail.com> writes:
> 
>>> 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?

If there are no changes then the first refresh will mark all the index 
entries as up-to-date, which means the second refresh wont stat anything 
so I'm not sure there is a noticeable change. To me the more important 
problem is that we're lstat()ing each changed file half a dozen times 
before we call check_changes() when we should be lstat()ing them twice.

>> 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?

Yes and improve things for the case where we actually have something to 
stash.

Thanks

Phillip
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads