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

Re: [PATCH] diff: do not reuse_worktree_file for submodules

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 24, 2014, 17:39 UTC
Message-ID
<xmqq4n3obeba.fsf@gitster.dls.corp.google.com>
In-Reply-To
<87bnxyq9n6.fsf@thomasrast.ch>
Thomas Rast <tr@thomasrast.ch> writes:
Show 22 quoted lines
> I spoke too soon; it breaks the test I wrote to cover this case, for a
> reason that gives me a headache.
>
> When we hit the conditional
>
>>>> -	if (!one->sha1_valid ||
>>>> -	    reuse_worktree_file(name, one->sha1, 1)) {
>>>> +	if (!S_ISGITLINK(one->mode) &&
>>>> +	    (!one->sha1_valid ||
>>>> +	     reuse_worktree_file(name, one->sha1, 1))) {
>
> sha1_valid=0 for the submodule on the worktree side of the diff.  The
> reason is that we start out with sha1_valid=0 and sha1=000..000 for the
> worktree side of all dirty entries, which makes sense at that point.  We
> later set the sha1 by looking inside the submodule in
> diff_fill_sha1_info(), but we never set sha1_valid.  So the above
> conditional will now trigger on the !one->sha1_valid arm, completely
> defeating the change to reuse_worktree_file().
>
> We can fix it like below, but it feels a bit wrong to me.  Are
> submodules the only case where it makes sense to set sha1_valid when we
> fill the sha1?

The meaning of filespec->sha1_valid is "Is it known that the filespec->sha1 and filespec->mode field should be used?"; I agree that this feels wrong.

Which means that the previous one was wrong, and your original was the right approach. I'll drop the update.

Thanks.
Show 17 quoted lines
>
>  diff.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git i/diff.c w/diff.c
> index dabf913..cf7281d 100644
> --- i/diff.c
> +++ w/diff.c
> @@ -3081,6 +3082,8 @@ static void diff_fill_sha1_info(struct diff_filespec *one)
>  				die_errno("stat '%s'", one->path);
>  			if (index_path(one->sha1, one->path, &st, 0))
>  				die("cannot hash %s", one->path);
> +			if (S_ISGITLINK(one->mode))
> +				one->sha1_valid = 1;
>  		}
>  	}
>  	else
Previous: Thomas Rast
Message 6 of 6 in “git diff, external diff tool, and submodules”
  1. Grégory PakoszFeb 15, 2014
  2. diff: do not reuse_worktree_file for submodulesThomas Rast, Feb 16, 2014
  3. Junio C HamanoFeb 18, 2014
  4. Thomas RastFeb 22, 2014
  5. Thomas RastFeb 23, 2014
  6. Junio C HamanoFeb 24, 2014

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.