Skip to contentSkip to conversation

t7800-difftool.sh failure on pu

PATCH Ramsay Jones 4 participants 7 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

Hi Tim,

With the current pu branch, I have t7800.3 (difftool ignores bad --tool values) failing on Linux (I haven't tried cygwin or mingw yet). The failure is caused by the test for the value of the exit code; for me the exit code is 9 not 1.

I have investigated, briefly, and found *two* alternatives for a fix. ;-)

The first option is to (effectively) revert commit 0440ed72 ("difftool: replace system call with Git::command_noisy", 22-03-2012), like so:

-- >8 --

git-difftool.perl +3 -1
index e1754ff..49613b1 100755
@@ -237,5 +237,7 @@ if (defined($dirdiff)) {
 
 	$ENV{GIT_PAGER} = '';
 	$ENV{GIT_EXTERNAL_DIFF} = 'git-difftool--helper';
-	git_cmd_try { Git::command_noisy(('diff', @ARGV)) } 'exit code %d';
+	my @command = ('git', 'diff', @ARGV);
+	my $rc = system(@command);
+	exit($rc | ($rc >> 8));
 }

-- 8< --

The second option is a bit of a mystery, since I don't see why it is necessary or why it works! :-P

First take a look at the following:

$ perl -e 'print $!+0, " $!\n";'
0 
$ echo $?
0
$ perl -e 'use Carp qw(croak); print $!+0, " $!\n";'
9 Bad file descriptor
$ echo $?
0
$ perl -e 'use Carp qw(croak); print $!+0, " $!\n"; croak oops;'
9 Bad file descriptor
oops at -e line 1
$ echo $?
9
$ perl -e 'use Carp qw(croak); print $!+0, " $!\n"; $!=0; croak oops;'
9 Bad file descriptor
oops at -e line 1
$ echo $?
255
$ perl -e 'use Carp qw(croak); print $!+0, " $!\n"; $!=0;  $?=1<<8; croak oops;'
9 Bad file descriptor
oops at -e line 1
$ echo $?
1

$

So, it seems that a stray non-zero errno (Bad file descriptor) is finding it's way to the perl exit value via the die call from within croak(). In particular, the call to croak within git_cmd_try() from Git.pm.

However, I don't see why this is happening, since just before the call to croak the perl vars $! (errno) and $? (exit status) are set to the *correct* values. Namely, $! is zero and $? is 256 (1<<8). As you can see from the above, that *should* result in the correct exit code. However, unlike above, git-difftool.perl returns 9.

Since 'croak' exits via a 'die' call, in desperation, I tried the following patch - and it works! Just don't ask me why. :-D

-- 8< --

perl/Git.pm +1 -1
index 1c96a20..264a45f 100644
@@ -1258,7 +1258,7 @@ sub git_cmd_try(&$) {
 		# We can't croak here since Error.pm would mangle
 		# that to Error::Simple.
 	};
-	$err and croak $err;
+	$err and die $err;
 	return $array ? @result : $result[0];
 }
 

-- >8 --

HTH

ATB,
Ramsay Jones

#1 lore raw
Quoted 17 lines · Ramsay Jones

Hi Tim,

With the current pu branch, I have t7800.3 (difftool ignores bad --tool values) failing on Linux (I haven't tried cygwin or mingw yet). The failure is caused by the test for the value of the exit code; for me the exit code is 9 not 1.

I have investigated, briefly, and found *two* alternatives for a fix. ;-)

The first option is to (effectively) revert commit 0440ed72 ("difftool: replace system call with Git::command_noisy", 22-03-2012), like so:

-- >8 --

git-difftool.perl +0 -0
index e1754ff..49613b1 100755

git-difftool.perl if (defined($dirdiff)) {

Quoted 9 lines
git-difftool.perl +3 -2
@@ -237,5 +237,7 @@ if (defined($dirdiff)) {
 
 	$ENV{GIT_PAGER} = '';
 	$ENV{GIT_EXTERNAL_DIFF} = 'git-difftool--helper';
-	git_cmd_try { Git::command_noisy(('diff', @ARGV)) } 'exit code %d';
+	my @command = ('git', 'diff', @ARGV);
+	my $rc = system(@command);
+	exit($rc | ($rc >> 8));
 }
-- 8< --

I would prefer this, regardless of the issue.

I actually recall asking Tim about the exit status when I reviewed this change.

#2 lore raw
Quoted 31 lines · Junio C Hamano
Quoted 17 lines · Ramsay Jones

Hi Tim,

With the current pu branch, I have t7800.3 (difftool ignores bad --tool values) failing on Linux (I haven't tried cygwin or mingw yet). The failure is caused by the test for the value of the exit code; for me the exit code is 9 not 1.

I have investigated, briefly, and found *two* alternatives for a fix. ;-)

The first option is to (effectively) revert commit 0440ed72 ("difftool: replace system call with Git::command_noisy", 22-03-2012), like so:

-- >8 --

git-difftool.perl +0 -0
index e1754ff..49613b1 100755

git-difftool.perl if (defined($dirdiff)) {

Quoted 9 lines
git-difftool.perl +3 -2
@@ -237,5 +237,7 @@ if (defined($dirdiff)) {
 
       $ENV{GIT_PAGER} = '';
       $ENV{GIT_EXTERNAL_DIFF} = 'git-difftool--helper';
-     git_cmd_try { Git::command_noisy(('diff', @ARGV)) } 'exit code %d';
+     my @command = ('git', 'diff', @ARGV);
+     my $rc = system(@command);
+     exit($rc | ($rc >> 8));
  }
-- 8< --

I would prefer this, regardless of the issue.

Quoted 2 lines

I actually recall asking Tim about the exit status when I reviewed this change.

I would also prefer this.

A question for the msysgit/cygwin folks:

would we need to go back to use "git.exe" as well?

Signature · 1 line
David
#3 lore raw
Quoted 24 lines · David Aguilar
Quoted 23 lines · Junio C Hamano
Quoted 9 lines · Ramsay Jones

The first option is to (effectively) revert commit 0440ed72 ("difftool: replace system call with Git::command_noisy", 22-03-2012), like so:

-- >8 --

git-difftool.perl +0 -0
index e1754ff..49613b1 100755

git-difftool.perl if (defined($dirdiff)) {

Quoted 9 lines
git-difftool.perl +3 -2
@@ -237,5 +237,7 @@ if (defined($dirdiff)) {
 
       $ENV{GIT_PAGER} = '';
       $ENV{GIT_EXTERNAL_DIFF} = 'git-difftool--helper';
-     git_cmd_try { Git::command_noisy(('diff', @ARGV)) } 'exit code %d';
+     my @command = ('git', 'diff', @ARGV);
+     my $rc = system(@command);
+     exit($rc | ($rc >> 8));
  }
-- 8< --

I would prefer this, regardless of the issue.

Quoted 2 lines
Quoted 2 lines

I actually recall asking Tim about the exit status when I reviewed this change.

This breakage is a surprise to me. All the tests in t7800 have passed for me since my first modifications to them. They continue to pass for me on Ubuntu. That being said, the simple tests that Ramsay posted in his email (simply printing $!) also fail for me on msysgit.

Quoted 2 lines

I would also prefer this.

This change will involve:
- Dropping 7/9 from the series
- Editing 8/9 to replace 'git_cmd_try' with simple system calls

Would it be better to resend the entire series or just edit and resend 8/9?

Quoted 3 lines

A question for the msysgit/cygwin folks:

would we need to go back to use "git.exe" as well?

I would welcome some feedback from other Windows users. I have been successfully using this series on Win7 with msysgit, but obviously some setups differ.

#4 lore raw
Quoted 5 lines · Tim Henigan

This change will involve:
- Dropping 7/9 from the series
- Editing 8/9 to replace 'git_cmd_try' with simple system calls

Would it be better to resend the entire series or just edit and resend 8/9?

As long as you know I have the right "previous round" in my tree, it would be sufficient to just send an updated 8/9 and tell me clearly what to do, i.e. "drop 0440ed7 and replace 6fbdb7b with this patch, leaving everything else intact.", after "---" line in it (if you were resending many patches with an updated cover letter, the insn to me will be in 0/n instead).

Thanks.

#5 lore raw
In reply to Junio C Hamano
Quoted 11 lines · Junio C Hamano
Quoted 10 lines · Ramsay Jones

The first option is to (effectively) revert commit 0440ed72 ("difftool: replace system call with Git::command_noisy", 22-03-2012), like so:

-- >8 --

git-difftool.perl +0 -0
index e1754ff..49613b1 100755
@@ -237,5 +237,7 @@ if (defined($dirdiff)) {
 
Quoted 10 lines

git-difftool.perl if (defined($dirdiff)) {

Quoted 8 lines
git-difftool.perl +3 -2
 	$ENV{GIT_PAGER} = '';
 	$ENV{GIT_EXTERNAL_DIFF} = 'git-difftool--helper';
-	git_cmd_try { Git::command_noisy(('diff', @ARGV)) } 'exit code %d';
+	my @command = ('git', 'diff', @ARGV);
+	my $rc = system(@command);
+	exit($rc | ($rc >> 8));
 }
-- 8< --

I would prefer this, regardless of the issue.

Me too! ;-P

I noticed this afternoon (using my isp's web-mail interface) that Tim has already sent a patch fixing this issue along these lines. [Thanks Tim]

However, just for the record, all three of the platforms I test on failed in more-or-less the same way. [the exit code on cygwin was 2 (No such File or Directory) rather than 9.]

Note that the failure occurred (on Linux, cygwin and MinGW) when pu was at commit e5471b396660313b172e102b50939c9c35d4c637 (v1.7.10-rc2-260-ge5471b3). However, on Linux, having fetched an updated pu which is now at commit ae98c9308d3a79f2b22de2f6dae614f700f7ce0c (v1.7.10-rc3-272-gae98c93), then test t7800 now reliably passes!

[when I say it reliably passes (fails), I mean it passes (fails) each time on ten consecutive runs.]

I created a diff of git-difftool.perl between these two commits and applied the patch, in reverse, to effectively revert that file. Having done so, then t7800 once again reliably fails! Looking at the diff, I have no idea why! [I've included the diff below, just for completeness.]

ATB,
Ramsay Jones

dt.diff:
-- >8 --

git-difftool.perl +24 -7
index e1754ff..78e93a6 100755
@@ -14,14 +14,16 @@
 use 5.008;
 use strict;
 use warnings;
-use File::Basename qw(dirname basename);
+use File::Basename qw(dirname);
 use File::Copy;
+use File::Find;
 use File::stat;
 use File::Path qw(mkpath);
 use File::Temp qw(tempdir);
 use Getopt::Long qw(:config pass_through);
 use Git;
 
+my @tools;
 my @working_tree;
 
 sub usage
@@ -38,17 +40,32 @@ USAGE
 	exit($exitcode);
 }
 
+sub filter_tool_scripts
+{
+	if (-d $_) {
+		if ($_ ne ".") {
+			# Ignore files in subdirectories
+			$File::Find::prune = 1;
+		}
+	} else {
+		if ((-f $_) && ($_ ne "defaults")) {
+			push(@tools, $_);
+		}
+	}
+}
+
 sub print_tool_help
 {
 	my ($cmd, @found, @notfound);
 	my $gitpath = Git::exec_path();
 
-	for (glob "$gitpath/mergetools/*") {
-		my $tool = basename($_);
-		next if ($tool eq "defaults");
+	find(\&filter_tool_scripts, "$gitpath/mergetools");
 
-		$cmd  = '. "$(git --exec-path)/git-mergetool--lib"';
+	foreach my $tool (@tools) {
+		$cmd  = "TOOL_MODE=diff";
+		$cmd .= ' && . "$(git --exec-path)/git-mergetool--lib"';
 		$cmd .= " && get_merge_tool_path $tool >/dev/null 2>&1";
+		$cmd .= " && can_diff >/dev/null 2>&1";
 		if (system('sh', '-c', $cmd) == 0) {
 			push(@found, $tool);
 		} else {
@@ -57,10 +74,10 @@ sub print_tool_help
 	}
 
 	print "'git difftool --tool=<tool>' may be set to one of the following:\n";
-	print "\t$_\n" for (@found);
+	print "\t$_\n" for (sort(@found));
 
 	print "\nThe following tools are valid, but not currently available:\n";
-	print "\t$_\n" for (@notfound);
+	print "\t$_\n" for (sort(@notfound));
 
 	print "\nNOTE: Some of the tools listed above only work in a windowed\n";
 	print "environment. If run in a terminal-only session, they will fail.\n";

-- 8< --

#6 lore raw
In reply to Ramsay Jones

Hi Ramsay - thank you for running the tests and trying this out.

Quoted 4 lines · Ramsay Jones

With the current pu branch, I have t7800.3 (difftool ignores bad --tool values) failing on Linux (I haven't tried cygwin or mingw yet). The failure is caused by the test for the value of the exit code; for me the exit code is 9 not 1.

This is interesting. On my Ubuntu box, I am able to run all of t7800 without error. This has been my primary development platform and the tests have consistently passed for me on that system.

I have had trouble getting the test suite to run on msysgit. However, I just tried the simple test sequence that you demonstrated and found that I get the same failure on that platform (i.e. "9 Bad file descriptor"). So it appears that Carp is broken on some platforms.

Quoted 4 lines

I have investigated, briefly, and found *two* alternatives for a fix. ;-)

The first option is to (effectively) revert commit 0440ed72 ("difftool: replace system call with Git::command_noisy", 22-03-2012), like so:

Thanks again for spending the time to dig into the problem. Based on feedback from Junio and David in later emails, I plan to revert commit 0440ed72.

Quoted 10 lines

The second option is a bit of a mystery, since I don't see why it is necessary or why it works! :-P

First take a look at the following:

$ perl -e 'print $!+0, " $!\n";'
0
$ echo $?
0
Quoted 4 lines
$ perl -e 'use Carp qw(croak); print $!+0, " $!\n";'
9 Bad file descriptor
$ echo $?
0

I agree that this is mysterious. On my Ubuntu box, this Perl one-liner prints and exits with 0 for me (i.e. no bad file descriptor error). However, I was able to replicate the failure on msysgit. This makes me wonder if other users of Git.pm have had the same problem. The primary user appears to be 'git-svn.perl' and its related tests. A quick review of those files did not show any mention of problems with Carp. Perhaps they simply do not check the exact exit code on failure?