Re: [PATCH] difftool: print list of valid tools with '--tool-help'

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH] difftool: print list of valid tools with '--tool-help'

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:53:19

Tim Henigan [off-list ref] writes:
quoted hunk
@@ -100,6 +101,15 @@ sub generate_command
 		if ($arg eq '-h') {
 			usage();
 		}
+		if ($arg eq '--tool-help') {
+			my $gitpath = Git::exec_path();
+			print "'git difftool --tool=<tool>' may be set to one of the following:\n";
+			for (glob "$gitpath/mergetools/*") {
+				next if /defaults$/;
+				print "\t" . basename($_) . "\n";
+			}
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.

        for (glob "$gitpath/mergetools/*") {
                next unless can_run($_);
                print ...
        }
        ...

   and "can_run" may look like this:

        sub can_run {
                my ($script) = @_;
             my $cmd = ". '$script' && cando";
             system('sh', '-c', $cmd) == 0;
        }

 - perhaps show the result in columnar layout.

Re: [PATCH] difftool: print list of valid tools with '--tool-help'

From: Tim Henigan <hidden>
Date: 2016-06-15 22:53:22

On Thu, Mar 15, 2012 at 7:18 PM, Junio C Hamano [off-list ref] wrote:
Tim Henigan [off-list ref] 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?
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help