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

[PATCH v7 29/49] completion: refactor __gitcomp

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Apr 1, 2023, 08:46 UTC
Message-ID
<20230401084626.304356-30-felipe.contreras@gmail.com>
In-Reply-To
<20230401084626.304356-1-felipe.contreras@gmail.com>

We have two 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 187350dbfc..9de394b223 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -345,44 +345,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-}"
+
+			c="--no-...${4-}"
 			if [[ $c == "$cur_"* ]]; then
-				case $c in
-				*=|*.) ;;
-				*) c="$c " ;;
-				esac
-				COMPREPLY[i++]="${2-}$c"
+				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-}"
-			if [[ $c == "$cur_"* ]]; then
-				case $c in
-				*=|*.) ;;
-				*) c="$c " ;;
-				esac
-				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 c9520589db..029ca23e50 100644
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -58,42 +58,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.33.0
Previous: Felipe ContrerasNext: Felipe Contreras
Message 30 of 50 in “completion: git-completion 2.0 patches”
  1. 00/49 completion: git-completion 2.0 patchesFelipe Contreras, Apr 1, 2023
  2. 02/49 completion: bash: trivial cleanupFelipe Contreras, Apr 1, 2023
  3. 01/49 test: completion add test for __git_cmd_idxFelipe Contreras, Apr 1, 2023
  4. 03/49 zsh: remove versionFelipe Contreras, Apr 1, 2023
  5. 04/49 completion: bash: trivial grammar fixFelipe Contreras, Apr 1, 2023
  6. 05/49 completion: zsh: add higher-priority locationFelipe Contreras, Apr 1, 2023
  7. 06/49 zsh: resolve symlink of scriptFelipe Contreras, Apr 1, 2023
  8. 07/49 zsh: simplify realpath dirname idiomFelipe Contreras, Apr 1, 2023
  9. 08/49 test: completion: use global configFelipe Contreras, Apr 1, 2023
  10. 09/49 completion: fix __git_cmd_idx regression for zshFelipe Contreras, Apr 1, 2023
  11. 10/49 completion: fix for suboptions with valueFelipe Contreras, Apr 1, 2023
  12. 11/49 completion: zsh: trivial improvementFelipe Contreras, Apr 1, 2023
  13. 12/49 completion: bash: do not modify COMP_WORDBREAKSFelipe Contreras, Apr 1, 2023
  14. 13/49 test: completion: fix currently typed wordsFelipe Contreras, Apr 1, 2023
  15. 14/49 test: completion: switch __gitcomp_nl prefix testFelipe Contreras, Apr 1, 2023
  16. 15/49 test: completion: add run_func() helperFelipe Contreras, Apr 1, 2023
  17. 16/49 completion: bash: remove non-append functionalityFelipe Contreras, Apr 1, 2023
  18. 17/49 completion: bash: get rid of _append() functionsFelipe Contreras, Apr 1, 2023
  19. 18/49 completion: bash: get rid of any non-append codeFelipe Contreras, Apr 1, 2023
  20. 19/49 completion: zsh: fix options with argumentsFelipe Contreras, Apr 1, 2023
  21. 20/49 completion: zsh: expand --git-dir file argumentFelipe Contreras, Apr 1, 2023
  22. 21/49 completion: zsh: add support for general -C optsFelipe Contreras, Apr 1, 2023
  23. 22/49 completion: zsh: fix for undefined completionsFelipe Contreras, Apr 1, 2023
  24. 23/49 completion: zsh: add support for general -c optsFelipe Contreras, Apr 1, 2023
  25. 24/49 completion: zsh: fix extra space on foo=Felipe Contreras, Apr 1, 2023
  26. 25/49 completion: zsh: add excluded optionsFelipe Contreras, Apr 1, 2023
  27. 26/49 completion: zsh: always set compsetFelipe Contreras, Apr 1, 2023
  28. 27/49 completion: factor out check in __gitcompFelipe Contreras, Apr 1, 2023
  29. 28/49 completion: simplify equal suffix checkFelipe Contreras, Apr 1, 2023
  30. 29/49 completion: refactor __gitcompFelipe Contreras, Apr 1, 2023
  31. 30/49 completion: simplify __gitcompFelipe Contreras, Apr 1, 2023
  32. 31/49 completion: bash: change suffix check in __gitcompFelipe Contreras, Apr 1, 2023
  33. 32/49 completion: improve __gitcomp suffix codeFelipe Contreras, Apr 1, 2023
  34. 33/49 test: completion: add missing testFelipe Contreras, Apr 1, 2023
  35. 34/49 completion: bash: simplify config_variable_nameFelipe Contreras, Apr 1, 2023
  36. 35/49 completion: bash: improve __gitcomp descriptionFelipe Contreras, Apr 1, 2023
  37. 36/49 completion: add __gitcomp_optsFelipe Contreras, Apr 1, 2023
  38. 37/49 completion: bash: cleanup __gitcomp* invocationsFelipe Contreras, Apr 1, 2023
  39. 38/49 completion: bash: shuffle __gitcomp functionsFelipe Contreras, Apr 1, 2023
  40. 39/49 completion: zsh: simplify __gitcomp_directFelipe Contreras, Apr 1, 2023
  41. 40/49 completion: zsh: shuffle __gitcomp* functionsFelipe Contreras, Apr 1, 2023
  42. 41/49 completion: zsh: fix direct quotingFelipe Contreras, Apr 1, 2023
  43. 42/49 completion: zsh: add elements individually in __gitcomp_optsFelipe Contreras, Apr 1, 2023
  44. 43/49 completion: zsh: add __gitcompadd helperFelipe Contreras, Apr 1, 2023
  45. 44/49 completion: zsh: add correct removable suffixFelipe Contreras, Apr 1, 2023
  46. 45/49 completion: bash: simplify _get_comp_words_by_ref()Felipe Contreras, Apr 1, 2023
  47. 46/49 completion: bash: refactor _get_comp_words_by_ref()Felipe Contreras, Apr 1, 2023
  48. 47/49 completion: bash: cleanup _get_comp_words_by_ref()Felipe Contreras, Apr 1, 2023
  49. 48/49 completion: bash: trivial cleanupFelipe Contreras, Apr 1, 2023
  50. 49/49 completion: bash: rename _get_comp_words_by_ref()Felipe Contreras, Apr 1, 2023

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.