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

[PATCH v1 10/43] completion: bash: get rid of _append() functions

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Apr 26, 2021, 16:14 UTC
Message-ID
<20210426161458.49860-11-felipe.contreras@gmail.com>
In-Reply-To
<20210426161458.49860-1-felipe.contreras@gmail.com>
There's no need to have duplicated functionality.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.bash | 35 ++++++--------------------
 contrib/completion/git-completion.zsh  | 10 --------
 2 files changed, 7 insertions(+), 38 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 162c8a89a2..d87d1ad12a 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -296,8 +296,7 @@ _get_comp_words_by_ref ()
 }
 fi
 
-# Fills the COMPREPLY array with prefiltered words without any additional
-# processing.
+# Appends prefiltered words to COMPREPLY without any additional processing.
 # Callers must take care of providing only words that match the current word
 # to be completed and adding any prefix and/or suffix (trailing space!), if
 # necessary.
@@ -310,19 +309,6 @@ __gitcomp_direct ()
 	COMPREPLY+=($1)
 }
 
-# Similar to __gitcomp_direct, but appends to COMPREPLY instead.
-# Callers must take care of providing only words that match the current word
-# to be completed and adding any prefix and/or suffix (trailing space!), if
-# necessary.
-# 1: List of newline-separated matching completion words, complete with
-#    prefix and suffix.
-__gitcomp_direct_append ()
-{
-	local IFS=$'\n'
-
-	COMPREPLY+=($1)
-}
-
 __gitcompappend ()
 {
 	local x i=${#COMPREPLY[@]}
@@ -440,16 +426,8 @@ __gitcomp_builtin ()
 	__gitcomp "$options"
 }
 
-# Variation of __gitcomp_nl () that appends to the existing list of
-# completion candidates, COMPREPLY.
-__gitcomp_nl_append ()
-{
-	local IFS=$'\n'
-	__gitcompappend "$1" "${2-}" "${3-$cur}" "${4- }"
-}
-
 # Generates completion reply from newline-separated possible completion words
-# by appending a space to all of them.
+# by appending a space to all of them. The result is appended to COMPREPLY.
 # It accepts 1 to 4 arguments:
 # 1: List of possible completion words, separated by a single newline.
 # 2: A prefix to be added to each possible completion word (optional).
@@ -459,7 +437,8 @@ __gitcomp_nl_append ()
 #    appended.
 __gitcomp_nl ()
 {
-	__gitcomp_nl_append "$@"
+	local IFS=$'\n'
+	__gitcompappend "$1" "${2-}" "${3-$cur}" "${4- }"
 }
 
 # Fills the COMPREPLY array with prefiltered paths without any additional
@@ -846,7 +825,7 @@ __git_complete_refs ()
 
 	# Append DWIM remote branch names if requested
 	if [ "$dwim" = "yes" ]; then
-		__gitcomp_direct_append "$(__git_dwim_remote_heads "$pfx" "$cur_" "$sfx")"
+		__gitcomp_direct "$(__git_dwim_remote_heads "$pfx" "$cur_" "$sfx")"
 	fi
 }
 
@@ -2641,7 +2620,7 @@ __git_complete_config_variable_name ()
 		local pfx="${cur_%.*}."
 		cur_="${cur_#*.}"
 		__gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")"
-		__gitcomp_nl_append $'autoSetupMerge\nautoSetupRebase\n' "$pfx" "$cur_" "${sfx- }"
+		__gitcomp_nl $'autoSetupMerge\nautoSetupRebase\n' "$pfx" "$cur_" "${sfx- }"
 		return
 		;;
 	guitool.*.*)
@@ -2691,7 +2670,7 @@ __git_complete_config_variable_name ()
 		local pfx="${cur_%.*}."
 		cur_="${cur_#*.}"
 		__gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
-		__gitcomp_nl_append "pushDefault" "$pfx" "$cur_" "${sfx- }"
+		__gitcomp_nl "pushDefault" "$pfx" "$cur_" "${sfx- }"
 		return
 		;;
 	url.*.*)
diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
index e2ea14fb33..97d2bcadd6 100644
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -121,16 +121,6 @@ __gitcomp_file ()
 	compadd -f -p "${2-}" -- ${(f)1} && _ret=0
 }
 
-__gitcomp_direct_append ()
-{
-	__gitcomp_direct "$@"
-}
-
-__gitcomp_nl_append ()
-{
-	__gitcomp_nl "$@"
-}
-
 __gitcomp_file_direct ()
 {
 	__gitcomp_file "$1" ""
-- 
2.31.0
Previous: Felipe ContrerasNext: Felipe Contreras
Message 11 of 46 in “completion: git-completion 1.3.1 patches”
  1. 00/43 completion: git-completion 1.3.1 patchesFelipe Contreras, Apr 26, 2021
  2. 01/43 completion: bash: fix prefix detection in branch.*Felipe Contreras, Apr 26, 2021
  3. 02/43 completion: fix for suboptions with valueFelipe Contreras, Apr 26, 2021
  4. 03/43 completion: bash: fix for multiple dash commandsFelipe Contreras, Apr 26, 2021
  5. 04/43 completion: bash: add correct suffix in variablesFelipe Contreras, Apr 26, 2021
  6. 05/43 completion: bash: do not modify COMP_WORDBREAKSFelipe Contreras, Apr 26, 2021
  7. 06/43 test: completion: fix currently typed wordsFelipe Contreras, Apr 26, 2021
  8. 07/43 test: completion: switch __gitcomp_nl prefix testFelipe Contreras, Apr 26, 2021
  9. 08/43 test: completion: add run_func() helperFelipe Contreras, Apr 26, 2021
  10. 09/43 completion: bash: remove non-append functionalityFelipe Contreras, Apr 26, 2021
  11. 10/43 completion: bash: get rid of _append() functionsFelipe Contreras, Apr 26, 2021
  12. 11/43 completion: bash: get rid of any non-append codeFelipe Contreras, Apr 26, 2021
  13. 12/43 completion: zsh: fix options with argumentsFelipe Contreras, Apr 26, 2021
  14. 13/43 completion: zsh: expand --git-dir file argumentFelipe Contreras, Apr 26, 2021
  15. 14/43 completion: zsh: add support for general -C optsFelipe Contreras, Apr 26, 2021
  16. 15/43 completion: zsh: fix for undefined completionsFelipe Contreras, Apr 26, 2021
  17. 16/43 completion: zsh: add support for general -c optsFelipe Contreras, Apr 26, 2021
  18. 17/43 completion: zsh: fix extra space on foo=Felipe Contreras, Apr 26, 2021
  19. 18/43 completion: zsh: add excluded optionsFelipe Contreras, Apr 26, 2021
  20. 19/43 completion: zsh: always set compsetFelipe Contreras, Apr 26, 2021
  21. 20/43 completion: factor out check in __gitcompFelipe Contreras, Apr 26, 2021
  22. 21/43 completion: simplify equal suffix checkFelipe Contreras, Apr 26, 2021
  23. 22/43 completion: refactor __gitcompFelipe Contreras, Apr 26, 2021
  24. 23/43 completion: simplify __gitcompFelipe Contreras, Apr 26, 2021
  25. 24/43 completion: bash: change suffix check in __gitcompFelipe Contreras, Apr 26, 2021
  26. 25/43 completion: improve __gitcomp suffix codeFelipe Contreras, Apr 26, 2021
  27. 26/43 completion: bash: simplify config_variable_nameFelipe Contreras, Apr 26, 2021
  28. 27/43 test: completion: add missing testFelipe Contreras, Apr 26, 2021
  29. 28/43 completion: bash: improve __gitcomp descriptionFelipe Contreras, Apr 26, 2021
  30. 29/43 completion: add __gitcomp_optsFelipe Contreras, Apr 26, 2021
  31. 30/43 completion: bash: cleanup __gitcomp* invocationsFelipe Contreras, Apr 26, 2021
  32. 31/43 completion: bash: shuffle __gitcomp functionsFelipe Contreras, Apr 26, 2021
  33. 32/43 completion: zsh: simplify __gitcomp_directFelipe Contreras, Apr 26, 2021
  34. 33/43 completion: zsh: shuffle __gitcomp* functionsFelipe Contreras, Apr 26, 2021
  35. 34/43 completion: zsh: fix direct quotingFelipe Contreras, Apr 26, 2021
  36. 35/43 completion: zsh: add elements individually in __gitcomp_optsFelipe Contreras, Apr 26, 2021
  37. 36/43 completion: zsh: add __gitcompadd helperFelipe Contreras, Apr 26, 2021
  38. 37/43 completion: zsh: add correct removable suffixFelipe Contreras, Apr 26, 2021
  39. 38/43 completion: bash: simplify _get_comp_words_by_ref()Felipe Contreras, Apr 26, 2021
  40. 39/43 completion: bash: refactor _get_comp_words_by_ref()Felipe Contreras, Apr 26, 2021
  41. 40/43 completion: bash: cleanup _get_comp_words_by_ref()Felipe Contreras, Apr 26, 2021
  42. 41/43 completion: bash: trivial cleanupFelipe Contreras, Apr 26, 2021
  43. 42/43 completion: bash: rename _get_comp_words_by_ref()Felipe Contreras, Apr 26, 2021
  44. 43/43 completion: zsh: add higher-priority locationFelipe Contreras, Apr 26, 2021
  45. Junio C HamanoMay 6, 2021
  46. Felipe ContrerasMay 7, 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.