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

Re: [PATCH 7/7] mergetool--lib: Improve show_tool_help() output

From
John Keeping <john@keeping.me.uk>
Date
Jan 25, 2013, 20:08 UTC
Message-ID
<20130125200807.GB7498@serenity.lan>
In-Reply-To
<20130125195446.GA7498@serenity.lan>
On Fri, Jan 25, 2013 at 07:54:46PM +0000, John Keeping wrote:
Show 78 quoted lines
> On Fri, Jan 25, 2013 at 01:43:54AM -0800, David Aguilar wrote:
> > Check the can_diff and can_merge functions before deciding whether to
> > add the tool to the available/unavailable lists.  This makes --tool-help context-
> > sensitive so that "git mergetool --tool-help" displays merge tools only
> > and "git difftool --tool-help" displays diff tools only.
> 
> This log message is misleading - the existing code in
> list_merge_tool_candidates already filters the tools like this, so the
> change is more:
> 
>     mergetool--lib: don't use a hardcoded list for "--tool-help"
> 
>     Instead of using a list of tools in list_merge_tool_candidates, list
>     the available scriptlets and query each of those to know whether it
>     applies to diff mode and/or merge mode.
> 
>     guess_merge_tool still relies on list_merge_tool_candidates so we
>     can't remove that function now.
> 
> 
> The patch seems to do the right thing, although I have a couple of minor
> nits...
> 
> > Signed-off-by: David Aguilar <davvid@gmail.com>
> > ---
> >  git-mergetool--lib.sh | 26 +++++++++++++++++++++-----
> >  1 file changed, 21 insertions(+), 5 deletions(-)
> > 
> > diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh
> > index db8218a..c547c59 100644
> > --- a/git-mergetool--lib.sh
> > +++ b/git-mergetool--lib.sh
> > @@ -168,17 +168,33 @@ list_merge_tool_candidates () {
> >  }
> >  
> >  show_tool_help () {
> > -	list_merge_tool_candidates
> >  	unavailable= available= LF='
> >  '
> > -	for i in $tools
> > +
> > +	scriptlets="$(git --exec-path)"/mergetools
> > +	for i in "$scriptlets"/*
> >  	do
> > -		merge_tool_path=$(translate_merge_tool_path "$i")
> > +		. "$scriptlets"/defaults
> > +		. "$i"
> > +
> > +		tool="$(basename "$i")"
> 
> Quotes are unnecessary here.
> 
> > +		if test "$tool" = "defaults"
> > +		then
> > +			continue
> > +		elif merge_mode && ! can_merge
> > +		then
> > +			continue
> > +		elif diff_mode && ! can_diff
> > +		then
> > +			continue
> > +		fi
> 
> Would this be better as:
> 
>     test "$tool" = "defaults" && continue
> 
>     can_merge || ! merge_mode || continue
>     can_diff || ! diff_mode || continue
> 
> or is that a bit too concise?
> 
> I'd prefer to see two separate if statements either way since the "test
> $tool = defaults" case is different from the "does it apply to the
> current mode?" case.  The "$tool = defaults" case could even move to the
> top of the loop.
> 
> > +		merge_tool_path=$(translate_merge_tool_path "$tool")
Actually, can we just change all of the above part of the loop to:
	test "$tool" = defaults && continue
	merge_tool_path=$(
		setup_tool "$tool" >/dev/null 2>&1 &&
		translate_merge_tool_path "$tool"
	) || continue
Show 13 quoted lines
> >  		if type "$merge_tool_path" >/dev/null 2>&1
> >  		then
> > -			available="$available$i$LF"
> > +			available="$available$tool$LF"
> >  		else
> > -			unavailable="$unavailable$i$LF"
> > +			unavailable="$unavailable$tool$LF"
> >  		fi
> >  	done
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous: Junio C HamanoNext: Junio C Hamano
Message 18 of 30 in “mergetool-lib improvements for --tool-help”
  1. 0/7 mergetool-lib improvements for --tool-helpDavid Aguilar, Jan 25, 2013
  2. 1/7 git-mergetool: move show_tool_help to mergetool--libDavid Aguilar, Jan 25, 2013
  3. 2/7 git-mergetool: remove redundant assignmentDavid Aguilar, Jan 25, 2013
  4. 3/7 git-mergetool: don't hardcode 'mergetool' in show_tool_helpDavid Aguilar, Jan 25, 2013
  5. 4/7 git-difftool: use git-mergetool--lib for "--tool-help"David Aguilar, Jan 25, 2013
  6. 5/7 mergetools/vim: Remove redundant diff commandDavid Aguilar, Jan 25, 2013
  7. 6/7 mergetools: Fix difftool/mergetool --tool-help listing for vimDavid Aguilar, Jan 25, 2013
  8. Sebastian SchuberthJan 25, 2013
  9. David AguilarJan 25, 2013
  10. Sebastian SchuberthJan 25, 2013
  11. Sebastian SchuberthJan 25, 2013
  12. John KeepingJan 25, 2013
  13. David AguilarJan 25, 2013
  14. Junio C HamanoJan 25, 2013
  15. 7/7 mergetool--lib: Improve show_tool_help() outputDavid Aguilar, Jan 25, 2013
  16. John KeepingJan 25, 2013
  17. Junio C HamanoJan 25, 2013
  18. John KeepingJan 25, 2013
  19. Junio C HamanoJan 25, 2013
  20. John KeepingJan 25, 2013
  21. Junio C HamanoJan 25, 2013
  22. John KeepingJan 25, 2013
  23. Junio C HamanoJan 25, 2013
  24. John KeepingJan 25, 2013
  25. 8/7 mergetool--lib: don't call "exit" in setup_toolJohn Keeping, Jan 25, 2013
  26. Junio C HamanoJan 26, 2013
  27. David AguilarJan 26, 2013
  28. 1/2 mergetool--lib: don't call "exit" in setup_toolJohn Keeping, Jan 26, 2013
  29. 1/2 mergetool--lib: don't call "exit" in setup_toolJohn Keeping, Jan 26, 2013
  30. 9/7 mergetool--lib: fix path lookup in guess_merge_toolJohn Keeping, Jan 25, 2013

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.