Re: [PATCH v5] git-completion.bash: add support for path completion

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Apr 23, 2013 at 10:25 AM, Manlio Perillo
<manlio.perillo@xxxxxxxxx> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Il 21/04/2013 12:14, Felipe Contreras ha scritto:
>> On Fri, Jan 11, 2013 at 12:48 PM, Manlio Perillo
>> <manlio.perillo@xxxxxxxxx> wrote:
>>> The git-completion.bash script did not implemented full, git aware,
>>> support to complete paths, for git commands that operate on files within
>>> the current working directory or the index.
>>
>>> +__git_index_file_list_filter_compat ()
>>> +{
>>> +       local path
>>> +
>>> +       while read -r path; do
>>> +               case "$path" in
>>> +               ?*/*) echo "${path%%/*}/" ;;
>>> +               *) echo "$path" ;;
>>> +               esac
>>> +       done
>>> +}
>>> +
>>> +__git_index_file_list_filter_bash ()
>>> +{
>>> +       local path
>>> +
>>> +       while read -r path; do
>>> +               case "$path" in
>>> +               ?*/*)
>>> +                       # XXX if we append a slash to directory names when using
>>> +                       # `compopt -o filenames`, Bash will append another slash.
>>> +                       # This is pretty stupid, and this the reason why we have to
>>> +                       # define a compatible version for this function.
>>> +                       echo "${path%%/*}" ;;
>>
>> Which version of bash is that? It works perfectly fine here with or
>> without the /.
>>
>
> GNU bash, version 4.1.5(1)-release (i486-pc-linux-gnu)
> on a GNU Linux Debian 6

I compiled 4.1 and I can't reproduce, and I tried on a debian squeeze
chroot and I also can't reproduce. What am I missing?

GNU bash, version 4.1.5(1)-release (x86_64-pc-linux-gnu)

>>> +# __git_index_files accepts 1 or 2 arguments:
>>> +# 1: Options to pass to ls-files (required).
>>> +#    Supported options are --cached, --modified, --deleted, --others,
>>> +#    and --directory.
>>> +# 2: A directory path (optional).
>>> +#    If provided, only files within the specified directory are listed.
>>> +#    Sub directories are never recursed.  Path must have a trailing
>>> +#    slash.
>>> +__git_index_files ()
>>> +{
>>> +       local dir="$(__gitdir)" root="${2-.}"
>>> +
>>> +       if [ -d "$dir" ]; then
>>> +               __git_ls_files_helper "$root" "$1" | __git_index_file_list_filter |
>>> +                       sort | uniq
>>> +       fi
>>> +}
>>> +
>>> +# __git_diff_index_files accepts 1 or 2 arguments:
>>> +# 1) The id of a tree object.
>>> +# 2) A directory path (optional).
>>> +#    If provided, only files within the specified directory are listed.
>>> +#    Sub directories are never recursed.  Path must have a trailing
>>> +#    slash.
>>> +__git_diff_index_files ()
>>> +{
>>> +       local dir="$(__gitdir)" root="${2-.}"
>>> +
>>> +       if [ -d "$dir" ]; then
>>> +               __git_diff_index_helper "$root" "$1" | __git_index_file_list_filter |
>>> +                       sort | uniq
>>> +       fi
>>> +}
>>
>> These two are exactly the same, except one calls
>> __git_ls_files_helper, and the other one __git_diff_index_helper,
>> can't we make another argument that is and select one or the other
>> based on that?
>>
>
> They are not exactly the same.
>
> The first function requires, as first parameter, (space separed) options
> to pass to ls-files command; the second function, instead, requires the
> id of a tree object.
>
> IMHO, using only one function may be confusing.

The functions down in the call-stack might be doing something
different but these functions themselves are not. At the end of the
day they simply pass arguments to ls-files or diff-index.

I'm certain these can be simplified greatly.

Cheers.

-- 
Felipe Contreras
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]