git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/5] difftool: Simplify print_tool_help()

From
David Aguilar <davvid@gmail.com>
Date
Jul 23, 2012, 03:42 UTC
Message-ID
<1343014940-16439-1-git-send-email-davvid@gmail.com>

Eliminate a global variable and File::Find usage by building upon basename() and glob() instead.

Signed-off-by: David Aguilar <davvid@gmail.com>
---
 git-difftool.perl | 25 +++++--------------------
 1 file changed, 5 insertions(+), 20 deletions(-)
diff --git a/git-difftool.perl b/git-difftool.perl
index c079854..ac0ed63 100755
--- a/git-difftool.perl
+++ b/git-difftool.perl
@@ -13,17 +13,15 @@
 use 5.008;
 use strict;
 use warnings;
-use File::Basename qw(dirname);
+use File::Basename qw(basename dirname);
 use File::Copy;
 use File::Compare;
-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;
 my $rc;
 my $repo = Git->repository();
@@ -65,26 +63,13 @@ sub find_worktree
 
 my $workdir = find_worktree();
 
-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();
 
-	find(\&filter_tool_scripts, "$gitpath/mergetools");
+	my @files = map { basename($_) } glob("$gitpath/mergetools/*");
+	my @tools = sort(grep { !m{^defaults$} } @files);
 
 	foreach my $tool (@tools) {
 		$cmd  = "TOOL_MODE=diff";
@@ -99,10 +84,10 @@ sub print_tool_help
 	}
 
 	print "'git difftool --tool=<tool>' may be set to one of the following:\n";
-	print "\t$_\n" for (sort(@found));
+	print "\t$_\n" for (@found);
 
 	print "\nThe following tools are valid, but not currently available:\n";
-	print "\t$_\n" for (sort(@notfound));
+	print "\t$_\n" for (@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";
-- 
1.7.11.2.255.g5f133da
Next: David Aguilar
Message 1 of 15 in “difftool: Simplify print_tool_help()”
  1. 1/5 difftool: Simplify print_tool_help()David Aguilar, Jul 23, 2012
  2. 2/5 difftool: Eliminate global variablesDavid Aguilar, Jul 23, 2012
  3. Sebastian SchuberthJul 23, 2012
  4. David AguilarJul 23, 2012
  5. Sebastian SchuberthJul 23, 2012
  6. David AguilarJul 23, 2012
  7. Sebastian SchuberthJul 23, 2012
  8. 3/5 difftool: Move option values into a hashDavid Aguilar, Jul 23, 2012
  9. David AguilarJul 23, 2012
  10. 5/5 difftool: Use symlinks when diffing against the worktreeDavid Aguilar, Jul 23, 2012
  11. Tim HeniganJul 24, 2012
  12. David AguilarJul 25, 2012
  13. David AguilarJul 25, 2012
  14. Junio C HamanoJul 25, 2012
  15. David AguilarJul 25, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.