completion: factor out _git_xxx calling code

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Mar 24, 2018 at 21:35 UTC 48e1c69ade27395dfe7eb2be8aadf5fc50576a21
1 file changed +13 -4
contrib/completion/git-completion.bash
+13 -4
@@ -3035,6 +3035,17 @@ _git_worktree ()
3035 fi
3036 }
3037
3038 +__git_complete_command () {
3039 + local command="$1"
3040 + local completion_func="_git_${command//-/_}"
3041 + if declare -f $completion_func >/dev/null 2>/dev/null; then
3042 + $completion_func
3043 + return 0
3044 + else
3045 + return 1
3046 + fi
3047 +}
3048 +
3049 __git_main ()
3050 {
3051 local i c=1 command __git_dir __git_repo_path
@@ -3094,14 +3105,12 @@ __git_main ()
3105 return
3106 fi
3107
3097 - local completion_func="_git_${command//-/_}"
3098 - declare -f $completion_func >/dev/null 2>/dev/null && $completion_func && return
3108 + __git_complete_command "$command" && return
3109
3110 local expansion=$(__git_aliased_command "$command")
3111 if [ -n "$expansion" ]; then
3112 words[1]=$expansion
3103 - completion_func="_git_${expansion//-/_}"
3104 - declare -f $completion_func >/dev/null 2>/dev/null && $completion_func
3113 + __git_complete_command "$expansion"
3114 fi
3115 }
3116