difftool: Simplify print_tool_help()

Eliminate a global variable and File::Find usage by building upon basename() and glob() instead. Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

David Aguilar committed Jul 22, 2012 at 20:57 UTC 35989c68ee5f577ae959f69281e456fd14460469
1 file changed +5 -20
git-difftool.perl
+5 -20
@@ -13,17 +13,15 @@
13 use 5.008;
14 use strict;
15 use warnings;
16 -use File::Basename qw(dirname);
16 +use File::Basename qw(basename dirname);
17 use File::Copy;
18 use File::Compare;
19 -use File::Find;
19 use File::stat;
20 use File::Path qw(mkpath);
21 use File::Temp qw(tempdir);
22 use Getopt::Long qw(:config pass_through);
23 use Git;
24
26 -my @tools;
25 my @working_tree;
26 my $rc;
27 my $repo = Git->repository();
@@ -65,26 +63,13 @@ sub find_worktree
63
64 my $workdir = find_worktree();
65
68 -sub filter_tool_scripts
69 -{
70 - if (-d $_) {
71 - if ($_ ne ".") {
72 - # Ignore files in subdirectories
73 - $File::Find::prune = 1;
74 - }
75 - } else {
76 - if ((-f $_) && ($_ ne "defaults")) {
77 - push(@tools, $_);
78 - }
79 - }
80 -}
81 -
66 sub print_tool_help
67 {
68 my ($cmd, @found, @notfound);
69 my $gitpath = Git::exec_path();
70
87 - find(\&filter_tool_scripts, "$gitpath/mergetools");
71 + my @files = map { basename($_) } glob("$gitpath/mergetools/*");
72 + my @tools = sort(grep { !m{^defaults$} } @files);
73
74 foreach my $tool (@tools) {
75 $cmd = "TOOL_MODE=diff";
@@ -99,10 +84,10 @@ sub print_tool_help
84 }
85
86 print "'git difftool --tool=<tool>' may be set to one of the following:\n";
102 - print "\t$_\n" for (sort(@found));
87 + print "\t$_\n" for (@found);
88
89 print "\nThe following tools are valid, but not currently available:\n";
105 - print "\t$_\n" for (sort(@notfound));
90 + print "\t$_\n" for (@notfound);
91
92 print "\nNOTE: Some of the tools listed above only work in a windowed\n";
93 print "environment. If run in a terminal-only session, they will fail.\n";