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

[PATCH 2/3] difftool: Check all return codes from compare()

From
David Aguilar <davvid@gmail.com>
Date
Jul 25, 2012, 03:14 UTC
Message-ID
<1343186064-49350-3-git-send-email-davvid@gmail.com>
In-Reply-To
<1343186064-49350-1-git-send-email-davvid@gmail.com>

Handle the case where compare() is unable to read its inputs. Emit a warning so that the user knows that something went wrong.

We may later want to restructure the code so that we can inhibit tempdir cleanup when this condition is reached.

Signed-off-by: David Aguilar <davvid@gmail.com>
---
 git-difftool.perl | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/git-difftool.perl b/git-difftool.perl
index 3057480..591ee75 100755
--- a/git-difftool.perl
+++ b/git-difftool.perl
@@ -370,7 +370,16 @@ sub dir_diff
 	# external tool did not replace the original link with a file.
 	for my $file (@worktree) {
 		next if $symlinks && -l "$b/$file";
-		if (-f "$b/$file" && compare("$b/$file", "$workdir/$file")) {
+		next if ! -f "$b/$file";
+
+		my $diff = compare("$b/$file", "$workdir/$file");
+		if ($diff == 0) {
+			next;
+		} elsif ($diff == -1 ) {
+			my $errmsg = "warning: could not compare ";
+			$errmsg += "'$b/$file' with '$workdir/$file'\n";
+			warn $errmsg;
+		} elsif ($diff == 1) {
 			copy("$b/$file", "$workdir/$file") or die $!;
 			my $mode = stat("$b/$file")->mode;
 			chmod($mode, "$workdir/$file") or die $!;
-- 
1.7.12.rc0.15.g8157c39
Previous: David AguilarNext: David Aguilar
Message 3 of 9 in “Incremental updates for da/difftool-updates”
  1. 0/3 Incremental updates for da/difftool-updatesDavid Aguilar, Jul 25, 2012
  2. 1/3 difftool: Handle finding mergetools/ in a path with spacesDavid Aguilar, Jul 25, 2012
  3. 2/3 difftool: Check all return codes from compare()David Aguilar, Jul 25, 2012
  4. 3/3 difftool: Disable --symlinks on cygwinDavid Aguilar, Jul 25, 2012
  5. Stefano LattariniJul 25, 2012
  6. Erik Faye-LundJul 26, 2012
  7. David AguilarJul 26, 2012
  8. Junio C HamanoJul 26, 2012
  9. Junio C HamanoJul 25, 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.