git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Aguilar <davvid@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Tim Henigan <tim.henigan@gmail.com>, git@vger.kernel.org
Subject: [PATCH 1/3] difftool: Handle finding mergetools/ in a path with spaces
Date: Tue, 24 Jul 2012 20:14:22 -0700	[thread overview]
Message-ID: <1343186064-49350-2-git-send-email-davvid@gmail.com> (raw)
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

  reply	other threads:[~2012-07-25  3:15 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-25  3:14 [PATCH 0/3] Incremental updates for da/difftool-updates David Aguilar
2012-07-25  3:14 ` David Aguilar [this message]
2012-07-25  3:14 ` [PATCH 2/3] difftool: Check all return codes from compare() David Aguilar
2012-07-25  3:14 ` [PATCH 3/3] difftool: Disable --symlinks on cygwin David Aguilar
2012-07-25 19:39   ` Stefano Lattarini
2012-07-26 11:31   ` Erik Faye-Lund
2012-07-26 17:39     ` David Aguilar
2012-07-26 19:04       ` Junio C Hamano
2012-07-25 16:36 ` [PATCH 0/3] Incremental updates for da/difftool-updates Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1343186064-49350-2-git-send-email-davvid@gmail.com \
    --to=davvid@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=tim.henigan@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).