Re: [PATCH v2 3/4] mergetool--lib: Add functions for finding available tools
On Sun, Jan 27, 2013 at 04:52:25PM -0800, David Aguilar wrote: --- a/git-mergetool--lib.sh +++ b/git-mergetool--lib.sh @@ -2,6 +2,35 @@ # git-mergetool--lib is a library for common merge tool functions MERGE_TOOLS_DIR=$(git --exec-path)/mergetools +mode_ok () { + diff_mode can_diff || + merge_mode can_merge +} + +is_available () { + merge_tool_path=$(translate_merge_tool_path $1) + type $merge_tool_path /dev/null 21 +} + +show_tool_names () { + condition=${1:-true} per_line_prefix=${2:-} preamble=${3:-} + + ( cd $MERGE_TOOLS_DIR ls -1 * ) | Is the '*' necessary here? I would expect ls to list the current directory if given no arguments, but perhaps some platforms behave differently? + while read toolname + do + if setup_tool $toolname 2/dev/null + (eval $condition $toolname) + then + if test -n $preamble + then + echo $preamble + preamble= + fi + printf %s%s\n $per_line_prefix $tool + fi + done +} + diff_mode() { test $TOOL_MODE = diff } @@ -199,35 +228,21 @@ list_merge_tool_candidates () { } show_tool_help () { - unavailable= available= LF=' -' - for i in $MERGE_TOOLS_DIR/* - do - tool=$(basename $i) - setup_tool $tool 2/dev/null || continue - - merge_tool_path=$(translate_merge_tool_path $tool) - if type $merge_tool_path /dev/null 21 - then - available=$available$tool$LF - else - unavailable=$unavailable$tool$LF - fi - done - - cmd_name=${TOOL_MODE}tool + tool_opt='git ${TOOL_MODE}tool --tool-tool' + available=$(show_tool_names 'mode_ok is_available' '\t\t' \ + $tool_opt may be set to one of the following:) + unavailable=$(show_tool_names 'mode_ok ! is_available' '\t\t' \ + The following tools are valid, but not currently available:) if test -n $available then - echo 'git $cmd_name --tool=tool' may be set to one of the following: - echo $available | sort | sed -e 's/^/ /' + echo $available else echo No suitable tool for 'git $cmd_name --tool=tool' found. fi if test -n $unavailable then echo - echo 'The following tools are valid, but not currently available:' - echo $unavailable | sort | sed -e 's/^/ /' + echo $unavailable fi if test -n $unavailable$available then You haven't taken full advantage of the simplification Junio suggested in response to v1 here. We can change the unavailable block to be: show_tool_names 'mode_ok ! is_available' $TAB$TAB \ ${LF}The following tools are valid, but not currently available: If you also add a not_found_msg parameter to show_tool_names then the available case is also simplified: 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. with this at the end of show_tool_names: test -n $preamble test -n $not_found_msg \ echo $not_found_msg John -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2 3/4] mergetool--lib: Add functions for finding available tools
John Keeping j...@keeping.me.uk writes: On Sun, Jan 27, 2013 at 04:52:25PM -0800, David Aguilar wrote: --- a/git-mergetool--lib.sh +++ b/git-mergetool--lib.sh @@ -2,6 +2,35 @@ # git-mergetool--lib is a library for common merge tool functions MERGE_TOOLS_DIR=$(git --exec-path)/mergetools +mode_ok () { +diff_mode can_diff || +merge_mode can_merge +} + +is_available () { +merge_tool_path=$(translate_merge_tool_path $1) +type $merge_tool_path /dev/null 21 +} + +show_tool_names () { +condition=${1:-true} per_line_prefix=${2:-} preamble=${3:-} + +( cd $MERGE_TOOLS_DIR ls -1 * ) | Is the '*' necessary here? No, it was just from a bad habit (I have ls aliased to ls -A or ls -a in my interactive environment, which trained my fingers to this). I also think you can lose -1, although it does not hurt. +tool_opt='git ${TOOL_MODE}tool --tool-tool' +available=$(show_tool_names 'mode_ok is_available' '\t\t' \ +$tool_opt may be set to one of the following:) +unavailable=$(show_tool_names 'mode_ok ! is_available' '\t\t' \ +The following tools are valid, but not currently available:) if test -n $available then -echo 'git $cmd_name --tool=tool' may be set to one of the following: -echo $available | sort | sed -e 's/^/ /' +echo $available else echo No suitable tool for 'git $cmd_name --tool=tool' found. fi if test -n $unavailable then echo -echo 'The following tools are valid, but not currently available:' -echo $unavailable | sort | sed -e 's/^/ /' +echo $unavailable fi if test -n $unavailable$available then You haven't taken full advantage of the simplification Junio suggested in response to v1 here. We can change the unavailable block to be: show_tool_names 'mode_ok ! is_available' $TAB$TAB \ ${LF}The following tools are valid, but not currently available: Actually I was hoping that we can enhance show_tool_names so that we can do without the $available and $unavailable variables at all. If you also add a not_found_msg parameter to show_tool_names then the available case is also simplified: 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. with this at the end of show_tool_names: test -n $preamble test -n $not_found_msg \ echo $not_found_msg Yes, something along that line. -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2 3/4] mergetool--lib: Add functions for finding available tools
On Tue, Jan 29, 2013 at 12:22 PM, Junio C Hamano gits...@pobox.com wrote: John Keeping j...@keeping.me.uk writes: On Sun, Jan 27, 2013 at 04:52:25PM -0800, David Aguilar wrote: --- a/git-mergetool--lib.sh +++ b/git-mergetool--lib.sh @@ -2,6 +2,35 @@ # git-mergetool--lib is a library for common merge tool functions MERGE_TOOLS_DIR=$(git --exec-path)/mergetools +mode_ok () { +diff_mode can_diff || +merge_mode can_merge +} + +is_available () { +merge_tool_path=$(translate_merge_tool_path $1) +type $merge_tool_path /dev/null 21 +} + +show_tool_names () { +condition=${1:-true} per_line_prefix=${2:-} preamble=${3:-} + +( cd $MERGE_TOOLS_DIR ls -1 * ) | Is the '*' necessary here? No, it was just from a bad habit (I have ls aliased to ls -A or ls -a in my interactive environment, which trained my fingers to this). I also think you can lose -1, although it does not hurt. +tool_opt='git ${TOOL_MODE}tool --tool-tool' +available=$(show_tool_names 'mode_ok is_available' '\t\t' \ +$tool_opt may be set to one of the following:) +unavailable=$(show_tool_names 'mode_ok ! is_available' '\t\t' \ +The following tools are valid, but not currently available:) if test -n $available then -echo 'git $cmd_name --tool=tool' may be set to one of the following: -echo $available | sort | sed -e 's/^/ /' +echo $available else echo No suitable tool for 'git $cmd_name --tool=tool' found. fi if test -n $unavailable then echo -echo 'The following tools are valid, but not currently available:' -echo $unavailable | sort | sed -e 's/^/ /' +echo $unavailable fi if test -n $unavailable$available then You haven't taken full advantage of the simplification Junio suggested in response to v1 here. We can change the unavailable block to be: show_tool_names 'mode_ok ! is_available' $TAB$TAB \ ${LF}The following tools are valid, but not currently available: Actually I was hoping that we can enhance show_tool_names so that we can do without the $available and $unavailable variables at all. If you also add a not_found_msg parameter to show_tool_names then the available case is also simplified: 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. with this at the end of show_tool_names: test -n $preamble test -n $not_found_msg \ echo $not_found_msg Yes, something along that line. I don't want to stomp on your feet and poke at this file too much if you're planning on building on top of it (I already did a few times ;-). My git time is a bit limited for the next few days so I don't want to hold you up. I can help shepherd through small fixups that come up until the weekend rolls around and I have more time, but I also don't want to hold you back until then. I will have some time tonight. If you guys would prefer an incremental patch I can send one that changes the ls expression and the way the unavailable block is structured. Otherwise, I can send replacements to handle the test -z thing, $TAB$TAB, and the simplification of the unavailable block. Later patches (that are working towards the new feature) can generalize show_tool_names() further and eliminate the need for the available/unavailable variables altogether. John, I would imagine that you'd want to pick that up since you're driving towards having --tool-help honor custom tools. What do you think? -- David -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2 3/4] mergetool--lib: Add functions for finding available tools
David Aguilar dav...@gmail.com writes: I don't want to stomp on your feet and poke at this file too much if you're planning on building on top of it (I already did a few times ;-). My git time is a bit limited for the next few days so I don't want to hold you up. I can help shepherd through small fixups that come up until the weekend rolls around and I have more time, but I also don't want to hold you back until then. I can work with John to get this part into a shape to support his extended use sometime toward the end of this week, by which time hopefully you have some time to comment on the result. John, how does that sound? -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2 3/4] mergetool--lib: Add functions for finding available tools
On Tue, Jan 29, 2013 at 02:27:21PM -0800, David Aguilar wrote: I don't want to stomp on your feet and poke at this file too much if you're planning on building on top of it (I already did a few times ;-). My git time is a bit limited for the next few days so I don't want to hold you up. I can help shepherd through small fixups that come up until the weekend rolls around and I have more time, but I also don't want to hold you back until then. I will have some time tonight. If you guys would prefer an incremental patch I can send one that changes the ls expression and the way the unavailable block is structured. Otherwise, I can send replacements to handle the test -z thing, $TAB$TAB, and the simplification of the unavailable block. Later patches (that are working towards the new feature) can generalize show_tool_names() further and eliminate the need for the available/unavailable variables altogether. John, I would imagine that you'd want to pick that up since you're driving towards having --tool-help honor custom tools. What do you think? I was planning to hold off until this series is in a reasonable state - there's no rush as far as I'm concerned, but if Junio's happy to leave these patches with just the small fixups I'm happy to build on that with a patch that removes the available and unavailable variables before adding the tools from git-config. John -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2 3/4] mergetool--lib: Add functions for finding available tools
On Tue, Jan 29, 2013 at 02:55:26PM -0800, Junio C Hamano wrote: David Aguilar dav...@gmail.com writes: I don't want to stomp on your feet and poke at this file too much if you're planning on building on top of it (I already did a few times ;-). My git time is a bit limited for the next few days so I don't want to hold you up. I can help shepherd through small fixups that come up until the weekend rolls around and I have more time, but I also don't want to hold you back until then. I can work with John to get this part into a shape to support his extended use sometime toward the end of this week, by which time hopefully you have some time to comment on the result. John, how does that sound? My email crossed with yours - that sounds good to me. If da/mergetool-docs is in a reasonable state by tomorrow evening (GMT) I should be able to have a look at it then - if not I'm happy to hold off longer. John -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2 3/4] mergetool--lib: Add functions for finding available tools
John Keeping j...@keeping.me.uk writes: On Tue, Jan 29, 2013 at 02:55:26PM -0800, Junio C Hamano wrote: ... I can work with John to get this part into a shape to support his extended use sometime toward the end of this week, by which time hopefully you have some time to comment on the result. John, how does that sound? My email crossed with yours - that sounds good to me. If da/mergetool-docs is in a reasonable state by tomorrow evening (GMT) I should be able to have a look at it then - if not I'm happy to hold off longer. Heh, I actually was hoping that you will send in a replacement for David's patch ;-) Here is what I will squash into the one we have been discussing. In a few hours, I expect I'll be able to push this out in the 'pu' branch. -- 8 -- From: Junio C Hamano gits...@pobox.com Date: Tue, 29 Jan 2013 18:57:55 -0800 Subject: [PATCH] [SQUASH] mergetools: tweak show_tool_names and its users Use show_tool_names as a function to produce output, not as a function to compute a string. Indicate if any output was given with its return status, so that the caller can say if it didn't give any output, I'll say this instead easily. To be squashed into the previous; no need to keep this log message. --- git-mergetool--lib.sh | 30 +- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh index 135da96..79cbdc7 100644 --- a/git-mergetool--lib.sh +++ b/git-mergetool--lib.sh @@ -22,7 +22,7 @@ is_available () { show_tool_names () { condition=${1:-true} per_line_prefix=${2:-} preamble=${3:-} - ( cd $MERGE_TOOLS_DIR ls -1 * ) | + ( cd $MERGE_TOOLS_DIR ls ) | while read toolname do if setup_tool $toolname 2/dev/null @@ -36,6 +36,7 @@ show_tool_names () { printf %s%s\n $per_line_prefix $tool fi done + test -n $preamble } diff_mode() { @@ -236,27 +237,30 @@ list_merge_tool_candidates () { show_tool_help () { tool_opt='git ${TOOL_MODE}tool --tool-tool' - available=$(show_tool_names 'mode_ok is_available' '\t\t' \ - $tool_opt may be set to one of the following:) - unavailable=$(show_tool_names 'mode_ok ! is_available' '\t\t' \ - The following tools are valid, but not currently available:) - if test -n $available + + tab=' ' av_shown= unav_shown= + + if show_tool_names 'mode_ok is_available' $tab$tab \ + $tool_opt may be set to one of the following: then - echo $available + av_shown=yes else echo No suitable tool for 'git $cmd_name --tool=tool' found. + av_shown=no fi - if test -n $unavailable + + if show_tool_names 'mode_ok ! is_available' $tab$tab \ + The following tools are valid, but not currently available: then - echo - echo $unavailable + unav_shown=yes fi - if test -n $unavailable$available - then + + case ,$av_shown,$unav_shown, in + *,yes,*) 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. - fi + esac exit 0 } -- 1.8.1.2.555.gedafe79 -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2 3/4] mergetool--lib: Add functions for finding available tools
Junio C Hamano gits...@pobox.com writes: Heh, I actually was hoping that you will send in a replacement for David's patch ;-) Here is what I will squash into the one we have been discussing. In a few hours, I expect I'll be able to push this out in the 'pu' branch. I ended up doing this a bit differently; will push out the result after merging the other topics to 'pu'. -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2 3/4] mergetool--lib: Add functions for finding available tools
On Sun, Jan 27, 2013 at 04:52:25PM -0800, David Aguilar wrote: Refactor show_tool_help() so that the tool-finding logic is broken out into a separate show_tool_names() function. Signed-off-by: David Aguilar dav...@gmail.com --- filter_tools renamed to show_tool_names() and simplfied to use ls -1. show_tool_names() now has a preamble as discussed. git-mergetool--lib.sh | 68 +-- 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh index db3eb58..fe068f6 100644 --- a/git-mergetool--lib.sh +++ b/git-mergetool--lib.sh @@ -2,6 +2,35 @@ # git-mergetool--lib is a library for common merge tool functions MERGE_TOOLS_DIR=$(git --exec-path)/mergetools +mode_ok () { + diff_mode can_diff || + merge_mode can_merge +} + +is_available () { + merge_tool_path=$(translate_merge_tool_path $1) + type $merge_tool_path /dev/null 21 +} + Can we move show_tool_names() to be above show_tool_help()? It's a very minor nit but I prefer having related functionality grouped together. +show_tool_names () { + condition=${1:-true} per_line_prefix=${2:-} preamble=${3:-} Would this be better with one value on each line? Also perhaps per_line_prefix - line_prefix. + + ( cd $MERGE_TOOLS_DIR ls -1 * ) | + while read toolname + do + if setup_tool $toolname 2/dev/null + (eval $condition $toolname) + then + if test -n $preamble + then + echo $preamble + preamble= + fi + printf %s%s\n $per_line_prefix $tool This needs to be: printf $per_line_prefix%s\n $tool since $per_line_prefix is usually '\t\t' which isn't expanded if we format it with %s - an alternative would be to change the value passed in to '$TAB$TAB' with literal tabs. + fi + done +} + diff_mode() { test $TOOL_MODE = diff } -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2 3/4] mergetool--lib: Add functions for finding available tools
John Keeping j...@keeping.me.uk writes: +printf %s%s\n $per_line_prefix $tool This needs to be: printf $per_line_prefix%s\n $tool since $per_line_prefix is usually '\t\t' which isn't expanded if we format it with %s - an alternative would be to change the value passed in to '$TAB$TAB' with literal tabs. I would prefer the latter, actually. I do understand the convenience of being able to write backslash-t, but I do not think it outweighs the potential risk of mistakingly passing a string with per-cent in it. -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v2 3/4] mergetool--lib: Add functions for finding available tools
Refactor show_tool_help() so that the tool-finding logic is broken out into a separate show_tool_names() function. Signed-off-by: David Aguilar dav...@gmail.com --- filter_tools renamed to show_tool_names() and simplfied to use ls -1. show_tool_names() now has a preamble as discussed. git-mergetool--lib.sh | 68 +-- 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh index db3eb58..fe068f6 100644 --- a/git-mergetool--lib.sh +++ b/git-mergetool--lib.sh @@ -2,6 +2,35 @@ # git-mergetool--lib is a library for common merge tool functions MERGE_TOOLS_DIR=$(git --exec-path)/mergetools +mode_ok () { + diff_mode can_diff || + merge_mode can_merge +} + +is_available () { + merge_tool_path=$(translate_merge_tool_path $1) + type $merge_tool_path /dev/null 21 +} + +show_tool_names () { + condition=${1:-true} per_line_prefix=${2:-} preamble=${3:-} + + ( cd $MERGE_TOOLS_DIR ls -1 * ) | + while read toolname + do + if setup_tool $toolname 2/dev/null + (eval $condition $toolname) + then + if test -n $preamble + then + echo $preamble + preamble= + fi + printf %s%s\n $per_line_prefix $tool + fi + done +} + diff_mode() { test $TOOL_MODE = diff } @@ -199,35 +228,21 @@ list_merge_tool_candidates () { } show_tool_help () { - unavailable= available= LF=' -' - for i in $MERGE_TOOLS_DIR/* - do - tool=$(basename $i) - setup_tool $tool 2/dev/null || continue - - merge_tool_path=$(translate_merge_tool_path $tool) - if type $merge_tool_path /dev/null 21 - then - available=$available$tool$LF - else - unavailable=$unavailable$tool$LF - fi - done - - cmd_name=${TOOL_MODE}tool + tool_opt='git ${TOOL_MODE}tool --tool-tool' + available=$(show_tool_names 'mode_ok is_available' '\t\t' \ + $tool_opt may be set to one of the following:) + unavailable=$(show_tool_names 'mode_ok ! is_available' '\t\t' \ + The following tools are valid, but not currently available:) if test -n $available then - echo 'git $cmd_name --tool=tool' may be set to one of the following: - echo $available | sort | sed -e 's/^/ /' + echo $available else echo No suitable tool for 'git $cmd_name --tool=tool' found. fi if test -n $unavailable then echo - echo 'The following tools are valid, but not currently available:' - echo $unavailable | sort | sed -e 's/^/ /' + echo $unavailable fi if test -n $unavailable$available then @@ -248,17 +263,12 @@ See 'git ${TOOL_MODE}tool --tool-help' or 'git help config' for more details. $tools EOF # Loop over each candidate and stop when a valid merge tool is found. - for i in $tools + for tool in $tools do - merge_tool_path=$(translate_merge_tool_path $i) - if type $merge_tool_path /dev/null 21 - then - echo $i - return 0 - fi + is_available $tool echo $tool return 0 done - echo 2 No known merge resolution program available. + echo 2 No known ${TOOL_MODE} tool is available. return 1 } -- 1.8.0.13.g3ff16bb -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html