* [PATCH 1/3] fixup! mergetool--lib: add functions for finding available tools
2013-01-30 19:55 [PATCH 0/3] mergetool: add user configured commands to '--tool-help' John Keeping
@ 2013-01-30 19:55 ` John Keeping
2013-01-30 20:23 ` Junio C Hamano
2013-01-30 19:55 ` [PATCH 2/3] fixup! doc: generate a list of valid merge tools John Keeping
2013-01-30 19:55 ` [PATCH 3/3] mergetool--lib: list user configured tools in '--tool-help' John Keeping
2 siblings, 1 reply; 6+ messages in thread
From: John Keeping @ 2013-01-30 19:55 UTC (permalink / raw)
To: git; +Cc: David Aguilar, Junio C Hamano
Signed-off-by: John Keeping <john@keeping.me.uk>
---
git-mergetool--lib.sh | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh
index 25631cd..b6ed2fa 100644
--- a/git-mergetool--lib.sh
+++ b/git-mergetool--lib.sh
@@ -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
--
1.8.1.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/3] fixup! mergetool--lib: add functions for finding available tools
2013-01-30 19:55 ` [PATCH 1/3] fixup! mergetool--lib: add functions for finding available tools John Keeping
@ 2013-01-30 20:23 ` Junio C Hamano
2013-01-30 20:34 ` John Keeping
0 siblings, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2013-01-30 20:23 UTC (permalink / raw)
To: John Keeping; +Cc: git, David Aguilar
John Keeping <john@keeping.me.uk> writes:
> Signed-off-by: John Keeping <john@keeping.me.uk>
> ---
> git-mergetool--lib.sh | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
Thanks.
> diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh
> index 25631cd..b6ed2fa 100644
> --- a/git-mergetool--lib.sh
> +++ b/git-mergetool--lib.sh
> @@ -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?
> 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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/3] fixup! mergetool--lib: add functions for finding available tools
2013-01-30 20:23 ` Junio C Hamano
@ 2013-01-30 20:34 ` John Keeping
0 siblings, 0 replies; 6+ messages in thread
From: John Keeping @ 2013-01-30 20:34 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, David Aguilar
On Wed, Jan 30, 2013 at 12:23:34PM -0800, Junio C Hamano wrote:
> > diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh
> > index 25631cd..b6ed2fa 100644
> > --- a/git-mergetool--lib.sh
> > +++ b/git-mergetool--lib.sh
> > @@ -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?
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.
> > 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
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/3] fixup! doc: generate a list of valid merge tools
2013-01-30 19:55 [PATCH 0/3] mergetool: add user configured commands to '--tool-help' John Keeping
2013-01-30 19:55 ` [PATCH 1/3] fixup! mergetool--lib: add functions for finding available tools John Keeping
@ 2013-01-30 19:55 ` John Keeping
2013-01-30 19:55 ` [PATCH 3/3] mergetool--lib: list user configured tools in '--tool-help' John Keeping
2 siblings, 0 replies; 6+ messages in thread
From: John Keeping @ 2013-01-30 19:55 UTC (permalink / raw)
To: git; +Cc: David Aguilar, Junio C Hamano
Signed-off-by: John Keeping <john@keeping.me.uk>
---
git-mergetool--lib.sh | 40 ++++++++++++++++++++++------------------
1 file changed, 22 insertions(+), 18 deletions(-)
diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh
index b6ed2fa..b44a2c8 100644
--- a/git-mergetool--lib.sh
+++ b/git-mergetool--lib.sh
@@ -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
}
--
1.8.1.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/3] mergetool--lib: list user configured tools in '--tool-help'
2013-01-30 19:55 [PATCH 0/3] mergetool: add user configured commands to '--tool-help' John Keeping
2013-01-30 19:55 ` [PATCH 1/3] fixup! mergetool--lib: add functions for finding available tools John Keeping
2013-01-30 19:55 ` [PATCH 2/3] fixup! doc: generate a list of valid merge tools John Keeping
@ 2013-01-30 19:55 ` John Keeping
2 siblings, 0 replies; 6+ messages in thread
From: John Keeping @ 2013-01-30 19:55 UTC (permalink / raw)
To: git; +Cc: David Aguilar, Junio C Hamano
Signed-off-by: John Keeping <john@keeping.me.uk>
---
git-mergetool--lib.sh | 41 ++++++++++++++++++++++++++++++++++++++++-
1 file changed, 40 insertions(+), 1 deletion(-)
diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh
index b44a2c8..e338be5 100644
--- a/git-mergetool--lib.sh
+++ b/git-mergetool--lib.sh
@@ -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" \
--
1.8.1.1
^ permalink raw reply related [flat|nested] 6+ messages in thread