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

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

From
David Aguilar <davvid@gmail.com>
Date
Jul 25, 2012, 03:14 UTC
Message-ID
<1343186064-49350-2-git-send-email-davvid@gmail.com>
In-Reply-To
<1343186064-49350-1-git-send-email-davvid@gmail.com>

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.

Signed-off-by: David Aguilar <davvid@gmail.com>
---
 git-difftool.perl | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)
diff --git a/git-difftool.perl b/git-difftool.perl
index a5b371f..3057480 100755
--- a/git-difftool.perl
+++ b/git-difftool.perl
@@ -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";
-- 
1.7.12.rc0.15.g8157c39
Previous: David AguilarNext: David Aguilar
Message 2 of 9 in “Incremental updates for da/difftool-updates”
  1. 0/3 Incremental updates for da/difftool-updatesDavid Aguilar, Jul 25, 2012
  2. 1/3 difftool: Handle finding mergetools/ in a path with spacesDavid Aguilar, Jul 25, 2012
  3. 2/3 difftool: Check all return codes from compare()David Aguilar, Jul 25, 2012
  4. 3/3 difftool: Disable --symlinks on cygwinDavid Aguilar, Jul 25, 2012
  5. Stefano LattariniJul 25, 2012
  6. Erik Faye-LundJul 26, 2012
  7. David AguilarJul 26, 2012
  8. Junio C HamanoJul 26, 2012
  9. Junio C HamanoJul 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.