git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Victoria Dye <vdye@github.com>
To: Derrick Stolee <derrickstolee@github.com>,
	Victoria Dye via GitGitGadget <gitgitgadget@gmail.com>,
	git@vger.kernel.org
Cc: reichemn@icloud.com, gitster@pobox.com
Subject: Re: [PATCH] mv: refresh stat info for moved entry
Date: Fri, 25 Mar 2022 15:37:41 -0700	[thread overview]
Message-ID: <d03a34e6-d6a7-6ddb-5784-57078e32ab89@github.com> (raw)
In-Reply-To: <30d20d10-da33-ae41-7887-d73279e14e92@github.com>

Derrick Stolee wrote:
> On 3/24/2022 9:56 PM, Victoria Dye via GitGitGadget wrote:
>> From: Victoria Dye <vdye@github.com>
>>
>> Add 'refresh_cache_entry()' after moving the index entry in
>> 'rename_index_entry_at()'. Internally, 'git mv' uses
>> 'rename_index_entry_at()' to move the source index entry to the destination,
>> overwriting the old entry if '-f' is specified. However, it does not refresh
>> the stat information on destination index entry, making its 'CE_UPTODATE'
>> flag out-of-date until the index is refreshed (e.g., by 'git status').
>>
>> Some commands, such as 'git reset', assume the 'CE_UPTODATE' information
>> they read from the index is accurate, and use that information to determine
>> whether the operation can be done successfully or not. In order to ensure
>> the index is correct for commands such as these, explicitly refresh the
>> destination index entry in 'git mv' before exiting.
> 
> Good find. Thanks for the fix!
> 
>> Reported-by: Maximilian Reichel <reichemn@icloud.com>
> 
> Thanks for the report, Maximilian!
> 
>> @@ -148,6 +148,7 @@ void rename_index_entry_at(struct index_state *istate, int nr, const char *new_n
>>  	untracked_cache_remove_from_index(istate, old_entry->name);
>>  	remove_index_entry_at(istate, nr);
>>  	add_index_entry(istate, new_entry, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE);
>> +	refresh_cache_entry(istate, new_entry, CE_MATCH_REFRESH);
> 
> It certainly seems reasonable to add this line. I was unfamiliar
> with this method, and it is used only twice: when creating a new
> cache entry in make_cache_entry() and in merge-recursive.c's
> add_cache_info(). So, it is currently acting in the case of a
> newly-inserted cache entry in its existing cases, and here in
> 'git mv' that's essentially what we are doing (deleting the old
> and adding a new would be more appropriate than just moving the
> old one).
> 
> I took a brief detour thinking about performance, but this is
> run only once per command-line argument, so any new overhead
> is minimal.
>   
>> +test_expect_success 'mv -f refreshes updated index entry' '
>> +	echo test >bar &&
>> +	git add bar &&
>> +	git commit -m test &&
>> +
>> +	echo foo >foo &&
>> +	git add foo &&
>> +	git mv -f foo bar &&
>> +	git reset --merge HEAD
> 
> Is there any post-condition on the index that we want to check here?
> 
> That is, is there anything that we could notice via 'git status' or
> similar that would break before this patch (assuming we put a
> test_might_fail in front of the 'git reset --merge HEAD' line)?
> 

While looking into this, I realized 1) that I wasn't actually refreshing the
cache entry because 'refresh_cache_entry' doesn't work in-place (will fix in
the next version) and 2) the test was only passing because of a race
condition that (as of right now) I can't quite figure out. 

If I add a 'sleep 1' after the 'git add', the test behaves as I expect:
fails when 'mv' doesn't refresh the entry, passes when it does. However,
when the sleep *isn't* there and I'm testing 'git mv' without the refresh,
most of the time the test *doesn't* fail (sometimes it does, but not
reliably). I'm going to try finding the root cause of that before sending
V2, in case I'm missing something else that should be fixed.

But to answer your question, yes - 'git diff-files' will produce an empty
result if the cache is reset properly, and will be non-empty if it is not.
I'll include that in the re-roll as well. 

> Thanks,
> -Stolee


  reply	other threads:[~2022-03-25 22:40 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-25  1:56 [PATCH] mv: refresh stat info for moved entry Victoria Dye via GitGitGadget
2022-03-25 14:31 ` Derrick Stolee
2022-03-25 22:37   ` Victoria Dye [this message]
2022-03-25 23:29 ` Junio C Hamano
2022-03-26  1:23   ` Victoria Dye
2022-03-29  1:07 ` [PATCH v2] " Victoria Dye via GitGitGadget
2022-03-29 13:19   ` Derrick Stolee
2022-03-29 16:44     ` Junio C Hamano
2022-03-29 18:54       ` Derrick Stolee
2022-03-29 19:05         ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d03a34e6-d6a7-6ddb-5784-57078e32ab89@github.com \
    --to=vdye@github.com \
    --cc=derrickstolee@github.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=gitster@pobox.com \
    --cc=reichemn@icloud.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).