completion: bash: add __git_have_func helper

This makes the code more readable, and also will help when new code wants to do similar checks. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Felipe Contreras committed Dec 30, 2020 at 17:29 UTC 7f94b78ddabdb49cde32b088ca66b422e7cda628
1 file changed +7 -3
contrib/completion/git-completion.bash
+7 -3
@@ -3358,15 +3358,19 @@ __git_support_parseopt_helper () {
3358 esac
3359 }
3360
3361 +__git_have_func () {
3362 + declare -f $1 >/dev/null 2>/dev/null
3363 +}
3364 +
3365 __git_complete_command () {
3366 local command="$1"
3367 local completion_func="_git_${command//-/_}"
3364 - if ! declare -f $completion_func >/dev/null 2>/dev/null &&
3365 - declare -f _completion_loader >/dev/null 2>/dev/null
3368 + if ! __git_have_func $completion_func &&
3369 + __git_have_func _completion_loader
3370 then
3371 _completion_loader "git-$command"
3372 fi
3369 - if declare -f $completion_func >/dev/null 2>/dev/null
3373 + if __git_have_func $completion_func
3374 then
3375 $completion_func
3376 return 0