git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 43/47] completion: bash: add __git_have_func helper

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Jan 1, 2021, 02:16 UTC
Message-ID
<20210101021622.798041-44-felipe.contreras@gmail.com>
In-Reply-To
<20210101021622.798041-1-felipe.contreras@gmail.com>

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>
---
 contrib/completion/git-completion.bash | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 59f1563674..4bd3e706ac 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -3200,15 +3200,19 @@ __git_support_parseopt_helper () {
 	esac
 }
 
+__git_have_func () {
+	declare -f $1 >/dev/null 2>/dev/null
+}
+
 __git_complete_command () {
 	local command="$1"
 	local completion_func="_git_${command//-/_}"
-	if ! declare -f $completion_func >/dev/null 2>/dev/null &&
-		declare -f _completion_loader >/dev/null 2>/dev/null
+	if ! __git_have_func $completion_func &&
+		__git_have_func _completion_loader
 	then
 		_completion_loader "git-$command"
 	fi
-	if declare -f $completion_func >/dev/null 2>/dev/null
+	if __git_have_func $completion_func
 	then
 		$completion_func
 		return 0
-- 
2.30.0
Previous: Felipe ContrerasNext: Felipe Contreras
Message 47 of 48 in “completion: git-completion 1.3 patches”
  1. 00/47 completion: git-completion 1.3 patchesFelipe Contreras, Jan 1, 2021
  2. 06/47 test: completion: fix currently typed wordsFelipe Contreras, Jan 1, 2021
  3. 05/47 completion: bash: do not modify COMP_WORDBREAKSFelipe Contreras, Jan 1, 2021
  4. 15/47 completion: zsh: fix for undefined completionsFelipe Contreras, Jan 1, 2021
  5. 02/47 completion: fix for suboptions with valueFelipe Contreras, Jan 1, 2021
  6. 13/47 completion: zsh: expand --git-dir file argumentFelipe Contreras, Jan 1, 2021
  7. 01/47 completion: bash: fix prefix detection in branch.*Felipe Contreras, Jan 1, 2021
  8. 04/47 completion: bash: add correct suffix in variablesFelipe Contreras, Jan 1, 2021
  9. 03/47 completion: bash: fix for multiple dash commandsFelipe Contreras, Jan 1, 2021
  10. 07/47 test: completion: switch __gitcomp_nl prefix testFelipe Contreras, Jan 1, 2021
  11. 10/47 completion: bash: get rid of _append() functionsFelipe Contreras, Jan 1, 2021
  12. 08/47 test: completion: add run_func() helperFelipe Contreras, Jan 1, 2021
  13. 17/47 completion: zsh: fix extra space on foo=Felipe Contreras, Jan 1, 2021
  14. 23/47 completion: simplify __gitcompFelipe Contreras, Jan 1, 2021
  15. 21/47 completion: simplify equal suffix checkFelipe Contreras, Jan 1, 2021
  16. 19/47 completion: zsh: always set compsetFelipe Contreras, Jan 1, 2021
  17. 27/47 test: completion: add missing testFelipe Contreras, Jan 1, 2021
  18. 11/47 completion: bash: get rid of any non-append codeFelipe Contreras, Jan 1, 2021
  19. 25/47 completion: improve __gitcomp suffix codeFelipe Contreras, Jan 1, 2021
  20. 28/47 completion: bash: improve __gitcomp descriptionFelipe Contreras, Jan 1, 2021
  21. 12/47 completion: zsh: fix options with argumentsFelipe Contreras, Jan 1, 2021
  22. 14/47 completion: zsh: add support for general -C optsFelipe Contreras, Jan 1, 2021
  23. 16/47 completion: zsh: add support for general -c optsFelipe Contreras, Jan 1, 2021
  24. 29/47 completion: add __gitcomp_optsFelipe Contreras, Jan 1, 2021
  25. 30/47 completion: bash: cleanup __gitcomp* invocationsFelipe Contreras, Jan 1, 2021
  26. 09/47 completion: bash: remove non-append functionalityFelipe Contreras, Jan 1, 2021
  27. 33/47 completion: zsh: shuffle __gitcomp* functionsFelipe Contreras, Jan 1, 2021
  28. 35/47 completion: zsh: add elements individually in __gitcomp_optsFelipe Contreras, Jan 1, 2021
  29. 36/47 completion: zsh: add __gitcompadd helperFelipe Contreras, Jan 1, 2021
  30. 31/47 completion: bash: shuffle __gitcomp functionsFelipe Contreras, Jan 1, 2021
  31. 38/47 completion: bash: simplify _get_comp_words_by_ref()Felipe Contreras, Jan 1, 2021
  32. 37/47 completion: zsh: add correct removable suffixFelipe Contreras, Jan 1, 2021
  33. 39/47 completion: bash: refactor _get_comp_words_by_ref()Felipe Contreras, Jan 1, 2021
  34. 32/47 completion: zsh: simplify __gitcomp_directFelipe Contreras, Jan 1, 2021
  35. 40/47 completion: bash: cleanup _get_comp_words_by_ref()Felipe Contreras, Jan 1, 2021
  36. 18/47 completion: zsh: add excluded optionsFelipe Contreras, Jan 1, 2021
  37. 20/47 completion: factor out check in __gitcompFelipe Contreras, Jan 1, 2021
  38. 22/47 completion: refactor __gitcompFelipe Contreras, Jan 1, 2021
  39. 24/47 completion: bash: change suffix check in __gitcompFelipe Contreras, Jan 1, 2021
  40. 44/47 completion: bash: improve function detectionFelipe Contreras, Jan 1, 2021
  41. 26/47 completion: bash: simplify config_variable_nameFelipe Contreras, Jan 1, 2021
  42. 45/47 test: completion: add tests for __git_completeFelipe Contreras, Jan 1, 2021
  43. 47/47 completion: zsh: add higher-priority locationFelipe Contreras, Jan 1, 2021
  44. 42/47 completion: bash: rename _get_comp_words_by_ref()Felipe Contreras, Jan 1, 2021
  45. 34/47 completion: zsh: fix direct quotingFelipe Contreras, Jan 1, 2021
  46. 41/47 completion: bash: trivial cleanupFelipe Contreras, Jan 1, 2021
  47. 43/47 completion: bash: add __git_have_func helperFelipe Contreras, Jan 1, 2021
  48. 46/47 completion: add proper public __git_completeFelipe Contreras, Jan 1, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.