git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tim Henigan <tim.henigan@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, David Aguilar <davvid@gmail.com>
Subject: Re: [PATCH] difftool: print list of valid tools with '--tool-help'
Date: Fri, 23 Mar 2012 14:26:32 -0400	[thread overview]
Message-ID: <CAFouethYEmY7g3Uw0HfFMOKFNcBv=TyAsSyEkBU-cQrhaf6v7g@mail.gmail.com> (raw)
In-Reply-To: <7v8vj1ihcn.fsf@alter.siamese.dyndns.org>

On Thu, Mar 15, 2012 at 7:18 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Tim Henigan <tim.henigan@gmail.com> writes:
>
> As this topic to show list of tools dynamically has plenty of time to be
> in the mainline (it will be post 1.7.10), I would suggest a follow-up
> series to this patch to do things like the following (just thinking
> aloud):
>
>  - define a new entry point to these mergetools/ scriptlets, let's call
>   it "cando".  An entry for mergetools/kompare might look like this:
>
>        cando () {
>                type kompare >/dev/null && test -n "$DISPLAY"
>        }
>
>   that would yield true only when kompare is available and $DISPLAY is
>   set.
>
>  - instead of dumping everything in $gitpath/mergetools/*, check if each
>   tool says it can be used in the user's environment.

I experimented with this a bit and came up with the following idea
(not protected for GMail whitespace mangling):

# The following is to be added to 'git-difftool.perl'
sub print_tool_help
{
	my ($cmd, @found, @notfound);
	my $gitpath = Git::exec_path();

	for (glob "$gitpath/mergetools/*") {
		my $tool = basename($_);
		next if ($tool eq "defaults");

		$cmd  = '. "$(git --exec-path)/git-mergetool--lib"';
		$cmd .= " && get_merge_tool_path $tool >/dev/null 2>&1";
		if (system('sh', '-c', $cmd) == 0) {
			push(@found, $tool);
		} else {
			push(@notfound, $tool);
		}
	}

	print "'git difftool --tool=<tool>' may be set to one of the following:\n";
	print "\t$_\n" for (@found);

	print "\nThe following are valid tools, but not currently installed:\n";
	print "\t$_\n" for (@notfound);

	exit(0);
}

Rather than create a new entry point, I used the existing
'get_merge_tool_path' that resides in 'git-mergetool--lib' to
determine if a given tool is actually installed on the system.

The '$DISPLAY' variable is lost in this implementation, but honestly I
don't understand how it was intended to be used.

Does this look useful?

  reply	other threads:[~2012-03-23 18:26 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-15 22:25 [PATCH] difftool: print list of valid tools with '--tool-help' Tim Henigan
2012-03-15 22:32 ` Junio C Hamano
2012-03-17  3:31   ` David Aguilar
2012-03-15 23:18 ` Junio C Hamano
2012-03-23 18:26   ` Tim Henigan [this message]
2012-03-23 19:48     ` Junio C Hamano
2012-03-26 16:23       ` [PATCH 9/9 v7] " Tim Henigan

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='CAFouethYEmY7g3Uw0HfFMOKFNcBv=TyAsSyEkBU-cQrhaf6v7g@mail.gmail.com' \
    --to=tim.henigan@gmail.com \
    --cc=davvid@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.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).