Skip to content

Commit 476a236

Browse files
rjustogitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3fec482 commit 476a236

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

contrib/completion/git-completion.bash

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -452,16 +452,18 @@ fi
452452

453453
# This function is equivalent to
454454
#
455-
# __gitcomp "$(git xxx --git-completion-helper) ..."
455+
# ___git_resolved_builtins=$(git xxx --git-completion-helper)
456456
#
457-
# except that the output is cached. Accept 1-3 arguments:
457+
# except that the result of the execution is cached.
458+
#
459+
# Accept 1-3 arguments:
458460
# 1: the git command to execute, this is also the cache key
461+
# (use "_" when the command contains spaces, e.g. "remote add"
462+
# becomes "remote_add")
459463
# 2: extra options to be added on top (e.g. negative forms)
460464
# 3: options to be excluded
461-
__gitcomp_builtin ()
465+
__git_resolve_builtins ()
462466
{
463-
# spaces must be replaced with underscore for multi-word
464-
# commands, e.g. "git remote add" becomes remote_add.
465467
local cmd="$1"
466468
local incl="${2-}"
467469
local excl="${3-}"
@@ -487,7 +489,24 @@ __gitcomp_builtin ()
487489
eval "$var=\"$options\""
488490
fi
489491

490-
__gitcomp "$options"
492+
___git_resolved_builtins="$options"
493+
}
494+
495+
# This function is equivalent to
496+
#
497+
# __gitcomp "$(git xxx --git-completion-helper) ..."
498+
#
499+
# except that the output is cached. Accept 1-3 arguments:
500+
# 1: the git command to execute, this is also the cache key
501+
# (use "_" when the command contains spaces, e.g. "remote add"
502+
# becomes "remote_add")
503+
# 2: extra options to be added on top (e.g. negative forms)
504+
# 3: options to be excluded
505+
__gitcomp_builtin ()
506+
{
507+
__git_resolve_builtins "$1" "$2" "$3"
508+
509+
__gitcomp "$___git_resolved_builtins"
491510
}
492511

493512
# Variation of __gitcomp_nl () that appends to the existing list of

0 commit comments

Comments
 (0)