diff options
author | Rubén Justo <rjusto@gmail.com> | 2024-03-02 16:52:03 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2024-03-03 14:21:39 -0800 |
commit | 476a236e72d7ad0d2a5237faeaa439b1054e80a5 (patch) | |
tree | d51282770671d50ff6746087f8f4b14edb8679f9 /contrib | |
parent | 3fec482b5f7f2f13c7465cf79062440a84233d14 (diff) | |
download | git-476a236e72d7ad0d2a5237faeaa439b1054e80a5.tar.gz |
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>
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/completion/git-completion.bash | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index dc5f73a9f3..f9fbf1f703 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -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 |