completion: factor out __git_resolve_builtins

We're going to use the result of "git xxx --git-completion-helper" not
only for feeding COMPREPLY.

Therefore, factor out the execution and the caching of its results in
__gitcomp_builtin, to a new function __git_resolve_builtins.

While we're here, move an important comment we have in the function to
its header, so it gains visibility.

Signed-off-by: Rubén Justo <rjusto@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Rubén Justo 2024-03-02 16:52:03 +01:00 коммит произвёл Junio C Hamano
Родитель 3fec482b5f
Коммит 476a236e72
1 изменённых файлов: 25 добавлений и 6 удалений

Просмотреть файл

@ -452,16 +452,18 @@ fi
# This function is equivalent to
#
# __gitcomp "$(git xxx --git-completion-helper) ..."
# ___git_resolved_builtins=$(git xxx --git-completion-helper)
#
# except that the output is cached. Accept 1-3 arguments:
# except that the result of the execution is cached.
#
# Accept 1-3 arguments:
# 1: the git command to execute, this is also the cache key
# (use "_" when the command contains spaces, e.g. "remote add"
# becomes "remote_add")
# 2: extra options to be added on top (e.g. negative forms)
# 3: options to be excluded
__gitcomp_builtin ()
__git_resolve_builtins ()
{
# spaces must be replaced with underscore for multi-word
# commands, e.g. "git remote add" becomes remote_add.
local cmd="$1"
local incl="${2-}"
local excl="${3-}"
@ -487,7 +489,24 @@ __gitcomp_builtin ()
eval "$var=\"$options\""
fi
__gitcomp "$options"
___git_resolved_builtins="$options"
}
# This function is equivalent to
#
# __gitcomp "$(git xxx --git-completion-helper) ..."
#
# except that the output is cached. Accept 1-3 arguments:
# 1: the git command to execute, this is also the cache key
# (use "_" when the command contains spaces, e.g. "remote add"
# becomes "remote_add")
# 2: extra options to be added on top (e.g. negative forms)
# 3: options to be excluded
__gitcomp_builtin ()
{
__git_resolve_builtins "$1" "$2" "$3"
__gitcomp "$___git_resolved_builtins"
}
# Variation of __gitcomp_nl () that appends to the existing list of