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

[PATCH 22/47] completion: refactor __gitcomp

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

We have to chunks of code doing exactly the same. There's no need for that.

No functional changes.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.bash | 52 +++++++++-----------------
 contrib/completion/git-completion.zsh  | 52 ++++++++------------------
 2 files changed, 34 insertions(+), 70 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 0522750b9f..b356e3c86f 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -325,44 +325,28 @@ __gitcomp ()
 		return
 	fi
 
-	case "$cur_" in
-	--no-*)
-		local c i=0 IFS=$' \t\n'
-		for c in $1; do
-			if [[ $c == "--" ]]; then
+	local c i=0 IFS=$' \t\n'
+	for c in $1; do
+		if [[ $c == "--" ]]; then
+			if [[ "$cur_" == --no-* ]]; then
 				continue
 			fi
-			c="$c${4-}"
-			if [[ $c == "$cur_"* ]]; then
-				case $c in
-				*=|*.) ;;
-				*) c="$c " ;;
-				esac
-				COMPREPLY[i++]="${2-}$c"
-			fi
-		done
-		;;
-	*)
-		local c i=0 IFS=$' \t\n'
-		for c in $1; do
-			if [[ $c == "--" ]]; then
-				c="--no-...${4-}"
-				if [[ $c == "$cur_"* ]]; then
-					COMPREPLY[i++]="${2-}$c "
-				fi
-				break
-			fi
-			c="$c${4-}"
+
+			c="--no-...${4-}"
 			if [[ $c == "$cur_"* ]]; then
-				case $c in
-				*=|*.) ;;
-				*) c="$c " ;;
-				esac
-				COMPREPLY[i++]="${2-}$c"
+				COMPREPLY[i++]="${2-}$c "
 			fi
-		done
-		;;
-	esac
+			break
+		fi
+		c="$c${4-}"
+		if [[ $c == "$cur_"* ]]; then
+			case $c in
+			*=|*.) ;;
+			*) c="$c " ;;
+			esac
+			COMPREPLY[i++]="${2-}$c"
+		fi
+	done
 }
 
 # Clear the variables caching builtins' options when (re-)sourcing
diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
index 8db7d0693d..fbd03a0180 100644
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -57,42 +57,22 @@ __gitcomp ()
 
 	[[ "$cur_" == *= ]] && return
 
-	case "$cur_" in
-	--no-*)
-		local c IFS=$' \t\n'
-		local -a array
-		for c in ${=1}; do
-			if [[ $c == "--" ]]; then
-				continue
-			fi
-			c="$c${4-}"
-			case $c in
-			*=|*.) ;;
-			*) c="$c " ;;
-			esac
-			array+=("$c")
-		done
-		compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
-		;;
-	*)
-		local c IFS=$' \t\n'
-		local -a array
-		for c in ${=1}; do
-			if [[ $c == "--" ]]; then
-				c="--no-...${4-}"
-				array+=("$c ")
-				break
-			fi
-			c="$c${4-}"
-			case $c in
-			*=|*.) ;;
-			*) c="$c " ;;
-			esac
-			array+=("$c")
-		done
-		compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
-		;;
-	esac
+	local c IFS=$' \t\n'
+	local -a array
+	for c in ${=1}; do
+		if [[ $c == "--" ]]; then
+			[[ "$cur_" == --no-* ]] && continue
+			array+=("--no-...${4-} ")
+			break
+		fi
+		c="$c${4-}"
+		case $c in
+		*=|*.) ;;
+		*) c="$c " ;;
+		esac
+		array+=("$c")
+	done
+	compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
 }
 
 __gitcomp_direct ()
-- 
2.30.0
Previous: Felipe ContrerasNext: Felipe Contreras
Message 38 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.