Merge branch 'cb/bash-completion-ls-files-processing'
authorJunio C Hamano <gitster@pobox.com>
Wed, 25 Apr 2018 04:29:02 +0000 (13:29 +0900)
committerJunio C Hamano <gitster@pobox.com>
Wed, 25 Apr 2018 04:29:02 +0000 (13:29 +0900)
Shell completion (in contrib) that gives list of paths have been
optimized somewhat.

* cb/bash-completion-ls-files-processing:
completion: improve ls-files filter performance

1  2 
contrib/completion/git-completion.bash
index a7570739454ac793430b7f0edb8ba229f3ff50d8,f69cb5cdff7d2602d92b8d0a0eeb8de06a76d9c2..01dd9ff07a20b7e885e8cfeba08ce7a2fecbbe02
@@@ -29,8 -29,6 +29,8 @@@
  # tell the completion to use commit completion.  This also works with aliases
  # of form "!sh -c '...'".  For example, "!sh -c ': git commit ; ... '".
  #
 +# Compatible with bash 3.2.57.
 +#
  # You can set the following environment variables to influence the behavior of
  # the completion routines:
  #
@@@ -390,12 -388,7 +390,7 @@@ __git_index_files (
        local root="${2-.}" file
  
        __git_ls_files_helper "$root" "$1" |
-       while read -r file; do
-               case "$file" in
-               ?*/*) echo "${file%%/*}" ;;
-               *) echo "$file" ;;
-               esac
-       done | sort | uniq
+       cut -f1 -d/ | sort | uniq
  }
  
  # Lists branches from the local repository.
@@@ -1286,12 -1279,6 +1281,12 @@@ _git_checkout (
  
  _git_cherry ()
  {
 +      case "$cur" in
 +      --*)
 +              __gitcomp_builtin cherry
 +              return
 +      esac
 +
        __git_complete_refs
  }
  
@@@ -1511,6 -1498,16 +1506,6 @@@ _git_fsck (
        esac
  }
  
 -_git_gc ()
 -{
 -      case "$cur" in
 -      --*)
 -              __gitcomp_builtin gc
 -              return
 -              ;;
 -      esac
 -}
 -
  _git_gitk ()
  {
        _gitk
@@@ -1635,13 -1632,6 +1630,13 @@@ _git_ls_remote (
  
  _git_ls_tree ()
  {
 +      case "$cur" in
 +      --*)
 +              __gitcomp_builtin ls-tree
 +              return
 +              ;;
 +      esac
 +
        __git_complete_file
  }
  
@@@ -1817,6 -1807,11 +1812,6 @@@ _git_mv (
        fi
  }
  
 -_git_name_rev ()
 -{
 -      __gitcomp_builtin name-rev
 -}
 -
  _git_notes ()
  {
        local subcommands='add append copy edit get-ref list merge prune remove show'
@@@ -3036,45 -3031,6 +3031,45 @@@ _git_worktree (
        fi
  }
  
 +__git_complete_common () {
 +      local command="$1"
 +
 +      case "$cur" in
 +      --*)
 +              __gitcomp_builtin "$command"
 +              ;;
 +      esac
 +}
 +
 +__git_cmds_with_parseopt_helper=
 +__git_support_parseopt_helper () {
 +      test -n "$__git_cmds_with_parseopt_helper" ||
 +              __git_cmds_with_parseopt_helper="$(__git --list-parseopt-builtins)"
 +
 +      case " $__git_cmds_with_parseopt_helper " in
 +      *" $1 "*)
 +              return 0
 +              ;;
 +      *)
 +              return 1
 +              ;;
 +      esac
 +}
 +
 +__git_complete_command () {
 +      local command="$1"
 +      local completion_func="_git_${command//-/_}"
 +      if declare -f $completion_func >/dev/null 2>/dev/null; then
 +              $completion_func
 +              return 0
 +      elif __git_support_parseopt_helper "$command"; then
 +              __git_complete_common "$command"
 +              return 0
 +      else
 +              return 1
 +      fi
 +}
 +
  __git_main ()
  {
        local i c=1 command __git_dir __git_repo_path
                return
        fi
  
 -      local completion_func="_git_${command//-/_}"
 -      declare -f $completion_func >/dev/null 2>/dev/null && $completion_func && return
 +      __git_complete_command "$command" && return
  
        local expansion=$(__git_aliased_command "$command")
        if [ -n "$expansion" ]; then
                words[1]=$expansion
 -              completion_func="_git_${expansion//-/_}"
 -              declare -f $completion_func >/dev/null 2>/dev/null && $completion_func
 +              __git_complete_command "$expansion"
        fi
  }