Skip to content

Commit 35989c6

Browse files
davvidgitster
authored andcommitted
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>
1 parent 05df532 commit 35989c6

File tree

1 file changed

+5
-20
lines changed

1 file changed

+5
-20
lines changed

git-difftool.perl

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,15 @@
1313
use 5.008;
1414
use strict;
1515
use warnings;
16-
use File::Basename qw(dirname);
16+
use File::Basename qw(basename dirname);
1717
use File::Copy;
1818
use File::Compare;
19-
use File::Find;
2019
use File::stat;
2120
use File::Path qw(mkpath);
2221
use File::Temp qw(tempdir);
2322
use Getopt::Long qw(:config pass_through);
2423
use Git;
2524

26-
my @tools;
2725
my @working_tree;
2826
my $rc;
2927
my $repo = Git->repository();
@@ -65,26 +63,13 @@ sub find_worktree
6563

6664
my $workdir = find_worktree();
6765

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-
8266
sub print_tool_help
8367
{
8468
my ($cmd, @found, @notfound);
8569
my $gitpath = Git::exec_path();
8670

87-
find(\&filter_tool_scripts, "$gitpath/mergetools");
71+
my @files = map { basename($_) } glob("$gitpath/mergetools/*");
72+
my @tools = sort(grep { !m{^defaults$} } @files);
8873

8974
foreach my $tool (@tools) {
9075
$cmd = "TOOL_MODE=diff";
@@ -99,10 +84,10 @@ sub print_tool_help
9984
}
10085

10186
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);
10388

10489
print "\nThe following tools are valid, but not currently available:\n";
105-
print "\t$_\n" for (sort(@notfound));
90+
print "\t$_\n" for (@notfound);
10691

10792
print "\nNOTE: Some of the tools listed above only work in a windowed\n";
10893
print "environment. If run in a terminal-only session, they will fail.\n";

0 commit comments

Comments
 (0)