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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thomas Rast <tr@xxxxxxxxxxxxx> writes:

> Junio C Hamano <gitster@xxxxxxxxx> writes:
>
>> Thomas Rast <tr@xxxxxxxxxxxxx> writes:
>>
>>> @@ -2845,8 +2845,9 @@ static struct diff_tempfile *prepare_temp_file(const char *name,
>>>  		remove_tempfile_installed = 1;
>>>  	}
>>>  
>>> -	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))) {
>>
>> I agree with the goal/end result, but I have to wonder if the
>> reuse_worktree_file() be the helper function that ought to
>> encapsulate such a logic?
>>
>> Instead of feeding it an object name and a path, if we passed a
>> diff_filespec to the helper, it would have access to the mode as
>> well.  It would result in a more intrusive change, so I'd prefer to
>> see your patch applied first and then build such a refactor on top,
>> perhaps like the attached.
>
> I see that you already queued 721e727, which has the change you
> described plus moving the S_ISGITLINK test into reuse_worktree_file.
> The change looks good to me.

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?


 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


-- 
Thomas Rast
tr@xxxxxxxxxxxxx
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]