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

Re: [PATCH 1/2] difftool: only copy back files modified during directory diff

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 28, 2012, 19:51 UTC
Message-ID
<7vbok35i5s.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1340912395-16990-1-git-send-email-tim.henigan@gmail.com>
Tim Henigan <tim.henigan@gmail.com> writes:
Show 33 quoted lines
> When 'difftool --dir-diff' is used to compare working tree files,
> it always copies files from the tmp dir back to the working tree
> when the diff tool is closed, even if the files were not modified
> by the diff tool.
>
> This causes the file timestamp to change. Files should only be
> copied from the tmp dir back to the working copy if they were
> actually modified.
>
> Signed-off-by: Tim Henigan <tim.henigan@gmail.com>
> ---
>
> This patch must be applied after commit 304970d on next (diff-no-index:
> exit(1) if 'diff --quiet <repo file> <external file>' finds changes).
> because it relies on 'git diff --quiet' to compare files outside the
> repository.
>
>
>  git-difftool.perl | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/git-difftool.perl b/git-difftool.perl
> index ae1e052..679a56d 100755
> --- a/git-difftool.perl
> +++ b/git-difftool.perl
> @@ -336,8 +336,11 @@ if (defined($dirdiff)) {
>  	# files were modified during the diff, then the changes
>  	# should be copied back to the working tree
>  	for my $file (@working_tree) {
> -		copy("$b/$file", "$workdir/$file") or die $!;
> -		chmod(stat("$b/$file")->mode, "$workdir/$file") or die $!;
> +		if ((-e "$b/$file") &&
> +		    (system('git', 'diff', '--quiet', "$b/$file", "$workdir/$file") != 0)) {

Why waste cycles to spawn "git diff" when you only want to find if they are byte-for-byte identical *and* when you are importing many perl modules from File::* already into the script?

Show 6 quoted lines
> +			copy("$b/$file", "$workdir/$file") or die $!;
> +			chmod(stat("$b/$file")->mode, "$workdir/$file") or die $!;
> +		}
>  	}
>  } else {
>  	if (defined($prompt)) {
Previous: Junio C HamanoNext: David Aguilar
Message 4 of 8 in “difftool: only copy back files modified during directory diff”
  1. 1/2 difftool: only copy back files modified during directory diffTim Henigan, Jun 28, 2012
  2. 2/2 difftool: handle uninitialized variable on empty diffTim Henigan, Jun 28, 2012
  3. Junio C HamanoJun 28, 2012
  4. Junio C HamanoJun 28, 2012
  5. David AguilarJul 19, 2012
  6. difftool: only copy back files modified during directory diffDavid Aguilar, Jul 19, 2012
  7. Junio C HamanoJul 19, 2012
  8. David AguilarJul 21, 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.