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

Re: [PATCH 5/5] difftool: Use symlinks when diffing against the worktree

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 23, 2012, 04:57 UTC
Message-ID
<7vzk6rnkgq.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1343015831-17498-6-git-send-email-davvid@gmail.com>
David Aguilar <davvid@gmail.com> writes:
Show 5 quoted lines
> +	# Do not copy back files when symlinks are used
> +	if ($symlinks) {
> +		exit(0);
> +	}
> +

Isn't this a bit risky, depending on the behaviour of the tool that eventually lead the user to invoke his favorite editor to muck with the files in the temporary directory? I think most sane people and their editors would follow symlinks and update the file the symlink points at when writing out the modified contents, but it should not be too much trouble to detect the case in which the editor unlinked the symlink and recreated a regular file in its place, and copy the file back when that happened, to make it even safer, no?

The most lazy solution would be to just remove the above block, and let the compare() compare the symlink $b/$file and the working tree file $workdir/$file that is pointed by it. We will find data losing case where the editor unlinks and creates that way automatically.

Optionally, you can update
	if (-e "$b/$file" && compare("$b/$file", "$workdir/$file")) {
with
	if (! -l "$b/$file" && -f _ && compare("$b/$file", "$workdir/$file")) {
to avoid the cost of comparison.
Show 14 quoted lines
>  	# If the diff including working copy files and those
>  	# files were modified during the diff, then the changes
>  	# should be copied back to the working tree
> +
>  	for my $file (@working_tree) {
>  		if (-e "$b/$file" && compare("$b/$file", "$workdir/$file")) {
>  			copy("$b/$file", "$workdir/$file") or die $!;
> -			chmod(stat("$b/$file")->mode, "$workdir/$file") or die $!;
> +			my $mode = stat("$b/$file")->mode;
> +			chmod($mode, "$workdir/$file") or die $!;
>  		}
>  	}
> +	exit(0);
>  }
Other than that, the series looked well thought-out.
Thanks.
Previous: David AguilarNext: David Aguilar
Message 7 of 13 in “difftool: Use symlinks in dir-diff mode”
  1. 0/5 difftool: Use symlinks in dir-diff modeDavid Aguilar, Jul 23, 2012
  2. 1/5 difftool: Simplify print_tool_help()David Aguilar, Jul 23, 2012
  3. 2/5 difftool: Eliminate global variablesDavid Aguilar, Jul 23, 2012
  4. 3/5 difftool: Move option values into a hashDavid Aguilar, Jul 23, 2012
  5. 4/5 difftool: Call the temp directory "git-difftool"David Aguilar, Jul 23, 2012
  6. 5/5 difftool: Use symlinks when diffing against the worktreeDavid Aguilar, Jul 23, 2012
  7. Junio C HamanoJul 23, 2012
  8. 4/5 difftool: Use symlinks when diffing against the worktreeDavid Aguilar, Jul 23, 2012
  9. Junio C HamanoJul 23, 2012
  10. Tim HeniganJul 24, 2012
  11. Junio C HamanoJul 24, 2012
  12. Junio C HamanoJul 23, 2012
  13. David AguilarJul 23, 2012

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.