mergetool: add user configured commands to '--tool-help'
cover mergetool: add user configured commands to '--tool-help'
The first couple of these are fixups to da/mergetool-docs. I think the first one's obvious, but the second one should possible be changed into an incremental patch on top. I did it this way for now since that patch is basically my comments in [1] in patch form.
The final patch adds tools from git-config to the '--tool-help' output.
[1] http://article.gmane.org/gmane.comp.version-control.git/214964
John Keeping (3):
fixup! mergetool--lib: add functions for finding available tools fixup! doc: generate a list of valid merge tools
mergetool--lib: list user configured tools in '--tool-help'
git-mergetool--lib.sh | 82 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 63 insertions(+), 19 deletions(-)
Signature · 1 line
1.8.1.1
PATCH 1/3 fixup! mergetool--lib: add functions for finding available tools
--- git-mergetool--lib.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
git-mergetool--lib.sh +3 -2
@@ -34,9 +34,9 @@ show_tool_names () { then echo "$preamble" preamble= - shown_any=yes fi - printf "%s%s\n" "$per_line_prefix" "$tool" + shown_any=yes + printf "%s%s\n" "$per_line_prefix" "$toolname" fi done test -n "$shown_any"
@@ -244,6 +244,7 @@ show_tool_help () { tab=' ' av_shown= unav_shown= + cmd_name=${TOOL_MODE}tool if show_tool_names 'mode_ok && is_available' "$tab$tab" \ "$tool_opt may be set to one of the following:" then
Signature · 1 line
1.8.1.1
Re: [PATCH 1/3] fixup! mergetool--lib: add functions for finding available tools
Quoted 4 lines · John Keeping
Signed-off-by John Keeping <[email protected]>--- git-mergetool--lib.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
Thanks.
git-mergetool--lib.sh show_tool_names () { · line 39
Quoted 13 lines
git-mergetool--lib.sh +2
-2@@ -34,9 +34,9 @@ show_tool_names () { then echo "$preamble" preamble= - shown_any=yes fi - printf "%s%s\n" "$per_line_prefix" "$tool" + shown_any=yes + printf "%s%s\n" "$per_line_prefix" "$toolname"
Thanks for spotting s/tool/toolname/; does the change to shown_any matter, though?
Quoted 11 lines
git-mergetool--lib.sh +1
-0fi done test -n "$shown_any"@@ -244,6 +244,7 @@ show_tool_help () { tab=' ' av_shown= unav_shown= + cmd_name=${TOOL_MODE}tool if show_tool_names 'mode_ok && is_available' "$tab$tab" \ "$tool_opt may be set to one of the following:" then
Re: [PATCH 1/3] fixup! mergetool--lib: add functions for finding available tools
Quoted 8 lines · Junio C Hamano
Quoted 8 lines
git-mergetool--lib.sh +0
-0@@ -34,9 +34,9 @@ show_tool_names () { then echo "$preamble" preamble=
Quoted 8 lines
git-mergetool--lib.sh show_tool_names () { · line 39
Quoted 5 lines
git-mergetool--lib.sh +2
-2- shown_any=yes fi - printf "%s%s\n" "$per_line_prefix" "$tool" + shown_any=yes + printf "%s%s\n" "$per_line_prefix" "$toolname"Thanks for spotting s/tool/toolname/; does the change to
shown_anymatter, though?
Not really since we don't call it with an empty "$preamble" but if something ever did then this ensures that shown_any is set correctly.
The $tool -> $toolname doesn't really matter either since setup_tool sets it as a global variable, but I'd rather not rely on that.
Quoted 11 lines
Quoted 11 lines
git-mergetool--lib.sh +1
-0fi done test -n "$shown_any"@@ -244,6 +244,7 @@ show_tool_help () { tab=' ' av_shown= unav_shown= + cmd_name=${TOOL_MODE}tool if show_tool_names 'mode_ok && is_available' "$tab$tab" \ "$tool_opt may be set to one of the following:" then
PATCH 2/3 fixup! doc: generate a list of valid merge tools
In reply to John Keeping--- git-mergetool--lib.sh | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-)
git-mergetool--lib.sh +22 -18
@@ -22,6 +22,7 @@ is_available () { show_tool_names () { condition=${1:-true} per_line_prefix=${2:-} preamble=${3:-} + not_found_msg=${4:-} shown_any= ( cd "$MERGE_TOOLS_DIR" && ls ) | {
@@ -32,13 +33,19 @@ show_tool_names () { then if test -n "$preamble" then - echo "$preamble" + printf "%s\n" "$preamble" preamble= fi shown_any=yes printf "%s%s\n" "$per_line_prefix" "$toolname" fi done + + if test -n "$preamble" && test -n "$not_found_msg" + then + printf "%s\n" "$not_found_msg" + fi + test -n "$shown_any" } }
@@ -242,30 +249,27 @@ list_merge_tool_candidates () { show_tool_help () { tool_opt="'git ${TOOL_MODE}tool --tool-<tool>'" - tab=' ' av_shown= unav_shown= + tab=' ' + LF=' +' + any_shown=no cmd_name=${TOOL_MODE}tool - if show_tool_names 'mode_ok && is_available' "$tab$tab" \ - "$tool_opt may be set to one of the following:" - then - av_shown=yes - else - echo "No suitable tool for 'git $cmd_name --tool=<tool>' found." - av_shown=no - fi + show_tool_names 'mode_ok && is_available' "$tab$tab" \ + "$tool_opt may be set to one of the following:" \ + "No suitable tool for 'git $cmd_name --tool=<tool>' found." && + any_shown=yes - if show_tool_names 'mode_ok && ! is_available' "$tab$tab" \ - "The following tools are valid, but not currently available:" - then - unav_shown=yes - fi + show_tool_names 'mode_ok && ! is_available' "$tab$tab" \ + "${LF}The following tools are valid, but not currently available:" && + any_shown=yes - case ",$av_shown,$unav_shown," in - *,yes,*) + if test "$any_shown" = yes + then echo echo "Some of the tools listed above only work in a windowed" echo "environment. If run in a terminal-only session, they will fail." - esac + fi exit 0 }
Signature · 1 line
1.8.1.1
PATCH 3/3 mergetool--lib: list user configured tools in '--tool-help'
In reply to John Keeping--- git-mergetool--lib.sh | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-)
git-mergetool--lib.sh +40 -1
@@ -20,9 +20,24 @@ is_available () { type "$merge_tool_path" >/dev/null 2>&1 } +list_config_tools () { + section=$1 + line_prefix=${2:-} + + git config --get-regexp $section'\..*\.cmd' | + while read -r key value + do + toolname=${key#$section.} + toolname=${toolname%.cmd} + + printf "%s%s\n" "$line_prefix" "$toolname" + done +} + show_tool_names () { condition=${1:-true} per_line_prefix=${2:-} preamble=${3:-} not_found_msg=${4:-} + extra_content=${5:-} shown_any= ( cd "$MERGE_TOOLS_DIR" && ls ) | {
@@ -41,6 +56,19 @@ show_tool_names () { fi done + if test -n "$extra_content" + then + if test -n "$preamble" + then + # Note: no '\n' here since we don't want a + # blank line if there is no initial content. + printf "%s" "$preamble" + preamble= + fi + shown_any=yes + printf "\n%s\n" "$extra_content" + fi + if test -n "$preamble" && test -n "$not_found_msg" then printf "%s\n" "$not_found_msg"
@@ -255,9 +283,20 @@ show_tool_help () { any_shown=no cmd_name=${TOOL_MODE}tool + config_tools=$({ + diff_mode && list_config_tools difftool "$tab$tab" + list_config_tools mergetool "$tab$tab" + } | sort) + extra_content= + if test -n "$config_tools" + then + extra_content="${tab}user-defined:${LF}$config_tools" + fi + show_tool_names 'mode_ok && is_available' "$tab$tab" \ "$tool_opt may be set to one of the following:" \ - "No suitable tool for 'git $cmd_name --tool=<tool>' found." && + "No suitable tool for 'git $cmd_name --tool=<tool>' found." \ + "$extra_content" && any_shown=yes show_tool_names 'mode_ok && ! is_available' "$tab$tab" \
Signature · 1 line
1.8.1.1