difftool: Handle finding mergetools/ in a path with spaces
Use the original File::Find implementation from bf73fc2 (difftool: print list of valid tools with '--tool-help', 2012-03-29) 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. Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
David Aguilar committed
Jul 24, 2012 at 20:14 UTC
7c7584b97096a168fe1236c84e5e12d7bee24476
1 file changed
+21
-6
git-difftool.perl
+21
-6
@@ -13,9 +13,10 @@
13
use 5.008;
14
use strict;
15
use warnings;
16
-use File::Basename qw(basename dirname);
16
+use File::Basename qw(dirname);
17
use File::Copy;
18
use File::Compare;
19
+use File::Find;
20
use File::stat;
21
use File::Path qw(mkpath);
22
use File::Temp qw(tempdir);
@@ -58,13 +59,27 @@ sub find_worktree
59
return $worktree;
60
}
61
62
+sub filter_tool_scripts
63
+{
64
+ my ($tools) = @_;
65
+ if (-d $_) {
66
+ if ($_ ne ".") {
67
+ # Ignore files in subdirectories
68
+ $File::Find::prune = 1;
69
+ }
70
+ } else {
71
+ if ((-f $_) && ($_ ne "defaults")) {
72
+ push(@$tools, $_);
73
+ }
74
+ }
75
+}
76
+
77
sub print_tool_help
78
{
63
- my ($cmd, @found, @notfound);
79
+ my ($cmd, @found, @notfound, @tools);
80
my $gitpath = Git::exec_path();
81
66
- my @files = map { basename($_) } glob("$gitpath/mergetools/*");
67
- my @tools = sort(grep { !m{^defaults$} } @files);
82
+ find(sub { filter_tool_scripts(\@tools) }, "$gitpath/mergetools");
83
84
foreach my $tool (@tools) {
85
$cmd = "TOOL_MODE=diff";
@@ -79,10 +94,10 @@ sub print_tool_help
94
}
95
96
print "'git difftool --tool=<tool>' may be set to one of the following:\n";
82
- print "\t$_\n" for (@found);
97
+ print "\t$_\n" for (sort(@found));
98
99
print "\nThe following tools are valid, but not currently available:\n";
85
- print "\t$_\n" for (@notfound);
100
+ print "\t$_\n" for (sort(@notfound));
101
102
print "\nNOTE: Some of the tools listed above only work in a windowed\n";
103
print "environment. If run in a terminal-only session, they will fail.\n";