git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Aguilar <davvid@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Tim Henigan <tim.henigan@gmail.com>, git@vger.kernel.org
Subject: [PATCH 2/3] difftool: Check all return codes from compare()
Date: Tue, 24 Jul 2012 20:14:23 -0700	[thread overview]
Message-ID: <1343186064-49350-3-git-send-email-davvid@gmail.com> (raw)
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

  parent reply	other threads:[~2012-07-25  3:15 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-25  3:14 [PATCH 0/3] Incremental updates for da/difftool-updates David Aguilar
2012-07-25  3:14 ` [PATCH 1/3] difftool: Handle finding mergetools/ in a path with spaces David Aguilar
2012-07-25  3:14 ` David Aguilar [this message]
2012-07-25  3:14 ` [PATCH 3/3] difftool: Disable --symlinks on cygwin David Aguilar
2012-07-25 19:39   ` Stefano Lattarini
2012-07-26 11:31   ` Erik Faye-Lund
2012-07-26 17:39     ` David Aguilar
2012-07-26 19:04       ` Junio C Hamano
2012-07-25 16:36 ` [PATCH 0/3] Incremental updates for da/difftool-updates Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1343186064-49350-3-git-send-email-davvid@gmail.com \
    --to=davvid@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=tim.henigan@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).