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

Re: [PATCH 3/4] mergetool--lib: Add functions for finding available tools

From
David Aguilar <davvid@gmail.com>
Date
Jan 27, 2013, 23:45 UTC
Message-ID
<CAJDDKr6eTN6FE6mF_6boXBzw5TqmA6f5+7V0S6nQSkhQKZAmCg@mail.gmail.com>
In-Reply-To
<7v8v7ecicm.fsf@alter.siamese.dyndns.org>
On Sun, Jan 27, 2013 at 3:32 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 86 quoted lines
> David Aguilar <davvid@gmail.com> writes:
>
>> +filter_tools () {
>> +     filter="$1"
>> +     prefix="$2"
>> +     (
>> +             cd "$MERGE_TOOLS_DIR" &&
>> +             for i in *
>> +             do
>> +                     echo "$i"
>> +             done
>> +     ) | sort | while read tool
>> +     do
>> +             setup_tool "$tool" 2>/dev/null &&
>> +             (eval "$filter" "$tool") &&
>> +             printf "$prefix$tool\n"
>> +     done
>> +}
>> +
>>  diff_mode() {
>>       test "$TOOL_MODE" = diff
>>  }
>> @@ -199,27 +226,13 @@ 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 2>&1
>> -             then
>> -                     available="$available$tool$LF"
>> -             else
>> -                     unavailable="$unavailable$tool$LF"
>> -             fi
>> -     done
>> -
>>       cmd_name=${TOOL_MODE}tool
>> +     available=$(filter_tools 'mode_ok && is_available' '\t\t')
>> +     unavailable=$(filter_tools 'mode_ok && ! is_available' '\t\t')
>>       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/^/ /'
>> +             printf "$available"
>
> This may happen to be safe as available will not have anything with
> a per-cent % in it, but is not a good discipline in general.
>
>         printf "%s" "$available"
>
> If you are giving filter_tools an optional "prefix-per-line", I do
> not think it is too much of a stretch to introduce another optional
> "perfix for the whole thing" and let this call site say something
> like this:
>
>         cmd_name=${TOOL_MODE}tool
>         show_tool_names 'mode_ok && is_available' '\t\t' \
>                 "'git $cmd_name --tool=<tool>' may be set to one of these:"
>         show_tool_names 'mode_ok && !is_available' '\t\t' \
>                 "These are valid but not available:"
>
> without any of the above logic (and the same for unav).  It may look like this:
>
> show_tool_names () {
>         condition=${1?condition} 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")
>                 then
>                         if test -n "$preamble"
>                         then
>                                 echo "$preamble"
>                                 preamble=
>                         fi
>                         printf "%s%s\n" "$prefix" "$toolname"
>                 fi
>         done
> }
Thanks guys.  I'll re-roll this soon.
-- 
David
Previous: Junio C HamanoNext: David Aguilar
Message 14 of 18 in “Documentation: Auto-generate merge tool lists”
  1. 0/4 Documentation: Auto-generate merge tool listsDavid Aguilar, Jan 27, 2013
  2. 1/4 mergetool--lib: Simplify command expressionsDavid Aguilar, Jan 27, 2013
  3. Johannes SixtJan 27, 2013
  4. David AguilarJan 27, 2013
  5. Junio C HamanoJan 27, 2013
  6. Junio C HamanoJan 27, 2013
  7. 2/4 mergetool--lib: Improve the help text in guess_merge_tool()David Aguilar, Jan 27, 2013
  8. Junio C HamanoJan 27, 2013
  9. 3/4 mergetool--lib: Add functions for finding available toolsDavid Aguilar, Jan 27, 2013
  10. Johannes SixtJan 27, 2013
  11. Junio C HamanoJan 27, 2013
  12. John KeepingJan 27, 2013
  13. Junio C HamanoJan 27, 2013
  14. David AguilarJan 27, 2013
  15. 4/4 doc: Generate a list of valid merge toolsDavid Aguilar, Jan 27, 2013
  16. Junio C HamanoJan 27, 2013
  17. John KeepingJan 27, 2013
  18. Junio C HamanoJan 27, 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.