Skip to contentSkip to conversation

Incremental updates for da/difftool-updates

PATCH In review David Aguilar 4 participants 9 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

cover Incremental updates for da/difftool-updates

These are incremental updates on top of da/difftool-updates, which is currently in next.

David Aguilar (3):
difftool: Handle finding mergetools/ in a path with spaces
difftool: Check all return codes from compare()
difftool: Disable --symlinks on cygwin

 git-difftool.perl | 41 +++++++++++++++++++++++++++++++++--------
 1 file changed, 33 insertions(+), 8 deletions(-)
Signature · 1 line
1.7.12.rc0.15.g8157c39
#1 lore raw

PATCH 1/3 difftool: Handle finding mergetools/ in a path with spaces

Use the original File::Find implementation from bf73fc212a159210398b6d46ed5e9101c650e7db so that we properly handle mergetools/ being located in a path containing spaces.

One small difference is that we avoid using a global variable by passing a reference to the list of tools.

---
 git-difftool.perl | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)
git-difftool.perl +21 -6
index a5b371f..3057480 100755
@@ -13,9 +13,10 @@
 use 5.008;
 use strict;
 use warnings;
-use File::Basename qw(basename dirname);
+use File::Basename qw(dirname);
 use File::Copy;
 use File::Compare;
+use File::Find;
 use File::stat;
 use File::Path qw(mkpath);
 use File::Temp qw(tempdir);
@@ -58,13 +59,27 @@ sub find_worktree
 	return $worktree;
 }
 
+sub filter_tool_scripts
+{
+	my ($tools) = @_;
+	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 ($cmd, @found, @notfound, @tools);
 	my $gitpath = Git::exec_path();
 
-	my @files = map { basename($_) } glob("$gitpath/mergetools/*");
-	my @tools = sort(grep { !m{^defaults$} } @files);
+	find(sub { filter_tool_scripts(\@tools) }, "$gitpath/mergetools");
 
 	foreach my $tool (@tools) {
 		$cmd  = "TOOL_MODE=diff";
@@ -79,10 +94,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";
Signature · 1 line
1.7.12.rc0.15.g8157c39
#2 lore raw

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

In reply to David Aguilar

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.

---
 git-difftool.perl | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
git-difftool.perl +10 -1
index 3057480..591ee75 100755
@@ -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 $!;
Signature · 1 line
1.7.12.rc0.15.g8157c39
#3 lore raw

PATCH 3/3 difftool: Disable --symlinks on cygwin

In reply to David Aguilar

Symlinks are not ubiquitous on Windows so make --no-symlinks the default.

---
I don't have cygwin so I can't verify this one myself. Is 'cygwin' really the value of $^O there?

 git-difftool.perl | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
git-difftool.perl +2 -1
index 591ee75..10d3d97 100755
@@ -291,7 +291,8 @@ sub main
 		gui => undef,
 		help => undef,
 		prompt => undef,
-		symlinks => $^O ne 'MSWin32' && $^O ne 'msys',
+		symlinks => $^O ne 'cygwin' &&
+				$^O ne 'MSWin32' && $^O ne 'msys',
 		tool_help => undef,
 	);
 	GetOptions('g|gui!' => \$opts{gui},
Signature · 1 line
1.7.12.rc0.15.g8157c39
#4 lore raw

Re: [PATCH 3/3] difftool: Disable --symlinks on cygwin

Quoted 7 lines · David Aguilar

Symlinks are not ubiquitous on Windows so make --no-symlinks the default.

---
I don't have cygwin so I can't verify this one myself. Is 'cygwin' really the value of $^O there?

Apparently yes:

  $ uname -rso
  CYGWIN_NT-5.1 1.5.25(0.156/4/2) Cygwin
  $ perl -e 'print $^O'
  cygwin

Regards,
Stefano

#5 lore raw

Re: [PATCH 3/3] difftool: Disable --symlinks on cygwin

In reply to David Aguilar
Quoted 15 lines · David Aguilar

Symlinks are not ubiquitous on Windows so make --no-symlinks the default.

---
I don't have cygwin so I can't verify this one myself. Is 'cygwin' really the value of $^O there?

 git-difftool.perl | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
git-difftool.perl +0 -0
index 591ee75..10d3d97 100755

git-difftool.perl sub main · line 295

Quoted 6 lines
git-difftool.perl +2 -1
@@ -291,7 +291,8 @@ sub main
                gui => undef,
                help => undef,
                prompt => undef,
-               symlinks => $^O ne 'MSWin32' && $^O ne 'msys',
+               symlinks => $^O ne 'cygwin' &&
+                               $^O ne 'MSWin32' && $^O ne 'msys',

I thought Cygwin supported (their own version of) symlinks? What's the rationale for not using it by default there?

#6 lore raw

Re: [PATCH 3/3] difftool: Disable --symlinks on cygwin

Quoted 11 lines · Erik Faye-Lund
Quoted 10 lines · David Aguilar

Symlinks are not ubiquitous on Windows so make --no-symlinks the default.

---
I don't have cygwin so I can't verify this one myself. Is 'cygwin' really the value of $^O there?

 git-difftool.perl | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 14 lines

git-difftool.perl sub main · line 295

Quoted 11 lines
git-difftool.perl +2 -1
index 591ee75..10d3d97 100755
@@ -291,7 +291,8 @@ sub main
                gui => undef,
                help => undef,
                prompt => undef,
-               symlinks => $^O ne 'MSWin32' && $^O ne 'msys',
+               symlinks => $^O ne 'cygwin' &&
+                               $^O ne 'MSWin32' && $^O ne 'msys',

I thought Cygwin supported (their own version of) symlinks? What's the rationale for not using it by default there?

I am not a Cygwin user so I cannot verify whether it is a good or bad idea.

I have a few questions regarding symlinks on Cygwin:

Do the symlinks work consistently with the Perl symlink() function? Can we always rely on this capability being available? Do all win32 filesystems support it?
Do all builds of cygwin perl support it?

If any of these answers are "no" or "maybe", then an improvement beyond this patch would be to perhaps support a difftool.symlinks configuration variable so that the user can tell us what to use as the default.

Signature · 1 line
David
#7 lore raw

Re: [PATCH 3/3] difftool: Disable --symlinks on cygwin

Quoted 36 lines · David Aguilar
Quoted 11 lines · Erik Faye-Lund
Quoted 10 lines · David Aguilar

Symlinks are not ubiquitous on Windows so make --no-symlinks the default.

---
I don't have cygwin so I can't verify this one myself. Is 'cygwin' really the value of $^O there?

 git-difftool.perl | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 14 lines

git-difftool.perl sub main · line 295

Quoted 11 lines
git-difftool.perl +2 -1
index 591ee75..10d3d97 100755
@@ -291,7 +291,8 @@ sub main
                gui => undef,
                help => undef,
                prompt => undef,
-               symlinks => $^O ne 'MSWin32' && $^O ne 'msys',
+               symlinks => $^O ne 'cygwin' &&
+                               $^O ne 'MSWin32' && $^O ne 'msys',

I thought Cygwin supported (their own version of) symlinks? What's the rationale for not using it by default there?

I am not a Cygwin user so I cannot verify whether it is a good or bad idea.

I have a few questions regarding symlinks on Cygwin:

Do the symlinks work consistently with the Perl symlink() function? Can we always rely on this capability being available? Do all win32 filesystems support it?
Do all builds of cygwin perl support it?

Quoted 4 lines

If any of these answers are "no" or "maybe", then an improvement beyond this patch would be to perhaps support a difftool.symlinks configuration variable so that the user can tell us what to use as the default.

I would think it is an independent topic that can be used by people not on Windows. It is good to be conservative by disabling symlinks by default.

Thanks.