git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] bash: remove unnecessary conditions when checking for subcommands
@ 2008-03-10 15:02 SZEDER Gábor
  2008-03-10 15:02 ` [PATCH 2/2] bash: refactor searching for subcommands on the command line SZEDER Gábor
  2008-03-10 23:54 ` [PATCH 1/2] bash: remove unnecessary conditions when checking for subcommands Shawn O. Pearce
  0 siblings, 2 replies; 5+ messages in thread
From: SZEDER Gábor @ 2008-03-10 15:02 UTC (permalink / raw)
  To: Shawn O. Pearce; +Cc: Junio C Hamano, git, SZEDER Gábor

Checking emptyness of $command is sufficient.

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
---
 contrib/completion/git-completion.bash |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 86b7ebe..39b2186 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -505,7 +505,7 @@ _git_bisect ()
 		c=$((++c))
 	done
 
-	if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
+	if [ -z "$command" ]; then
 		__gitcomp "start bad good reset visualize replay log"
 		return
 	fi
@@ -1050,7 +1050,7 @@ _git_remote ()
 		c=$((++c))
 	done
 
-	if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
+	if [ -z "$command" ]; then
 		__gitcomp "add rm show prune update"
 		return
 	fi
@@ -1143,7 +1143,7 @@ _git_submodule ()
 		c=$((++c))
 	done
 
-	if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
+	if [ -z "$command" ]; then
 		local cur="${COMP_WORDS[COMP_CWORD]}"
 		case "$cur" in
 		--*)
@@ -1206,7 +1206,7 @@ _git ()
 		c=$((++c))
 	done
 
-	if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
+	if [ -z "$command" ]; then
 		case "${COMP_WORDS[COMP_CWORD]}" in
 		--*=*) COMPREPLY=() ;;
 		--*)   __gitcomp "
-- 
1.5.4.4.481.g5075

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] bash: refactor searching for subcommands on the command line
  2008-03-10 15:02 [PATCH 1/2] bash: remove unnecessary conditions when checking for subcommands SZEDER Gábor
@ 2008-03-10 15:02 ` SZEDER Gábor
  2008-03-10 15:02   ` [PATCH] bash: add new 'git stash' subcommands SZEDER Gábor
  2008-03-10 23:54 ` [PATCH 1/2] bash: remove unnecessary conditions when checking for subcommands Shawn O. Pearce
  1 sibling, 1 reply; 5+ messages in thread
From: SZEDER Gábor @ 2008-03-10 15:02 UTC (permalink / raw)
  To: Shawn O. Pearce; +Cc: Junio C Hamano, git, SZEDER Gábor

This patch adds the __git_find_subcommand function, which takes one
argument: a string containing all subcommands separated by spaces.  The
function searches through the command line whether a subcommand is
already present.  The first found subcommand will be printed to standard
output.

This enables us to remove code duplications from completion functions
for commands having subcommands.

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
---
 contrib/completion/git-completion.bash |   71 ++++++++++++++-----------------
 1 files changed, 32 insertions(+), 39 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 39b2186..0feed97 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -436,6 +436,22 @@ __git_aliased_command ()
 	done
 }
 
+__git_find_subcommand ()
+{
+	local word subcommand c=1
+
+	while [ $c -lt $COMP_CWORD ]; do
+		word="${COMP_WORDS[c]}"
+		for subcommand in $1; do
+			if [ "$subcommand" = "$word" ]; then
+				echo "$subcommand"
+				return
+			fi
+		done
+		c=$((++c))
+	done
+}
+
 __git_whitespacelist="nowarn warn error error-all strip"
 
 _git_am ()
@@ -493,24 +509,14 @@ _git_add ()
 
 _git_bisect ()
 {
-	local i c=1 command
-	while [ $c -lt $COMP_CWORD ]; do
-		i="${COMP_WORDS[c]}"
-		case "$i" in
-		start|bad|good|reset|visualize|replay|log)
-			command="$i"
-			break
-			;;
-		esac
-		c=$((++c))
-	done
-
-	if [ -z "$command" ]; then
-		__gitcomp "start bad good reset visualize replay log"
+	local subcommands="start bad good reset visualize replay log"
+	local subcommand="$(__git_find_subcommand "$subcommands")"
+	if [ -z "$subcommand" ]; then
+		__gitcomp "$subcommands"
 		return
 	fi
 
-	case "$command" in
+	case "$subcommand" in
 	bad|good|reset)
 		__gitcomp "$(__git_refs)"
 		;;
@@ -1041,21 +1047,13 @@ _git_config ()
 
 _git_remote ()
 {
-	local i c=1 command
-	while [ $c -lt $COMP_CWORD ]; do
-		i="${COMP_WORDS[c]}"
-		case "$i" in
-		add|rm|show|prune|update) command="$i"; break ;;
-		esac
-		c=$((++c))
-	done
-
-	if [ -z "$command" ]; then
-		__gitcomp "add rm show prune update"
+	local subcommands="add rm show prune update"
+	local subcommand="$(__git_find_subcommand "$subcommands")"
+	if [ -z "$subcommand" ]; then
 		return
 	fi
 
-	case "$command" in
+	case "$subcommand" in
 	rm|show|prune)
 		__gitcomp "$(__git_remotes)"
 		;;
@@ -1129,28 +1127,23 @@ _git_show ()
 
 _git_stash ()
 {
-	__gitcomp 'list show apply clear'
+	local subcommands='list show apply clear'
+	if [ -z "$(__git_find_subcommand "$subcommands")" ]; then
+		__gitcomp "$subcommands"
+	fi
 }
 
 _git_submodule ()
 {
-	local i c=1 command
-	while [ $c -lt $COMP_CWORD ]; do
-		i="${COMP_WORDS[c]}"
-		case "$i" in
-		add|status|init|update) command="$i"; break ;;
-		esac
-		c=$((++c))
-	done
-
-	if [ -z "$command" ]; then
+	local subcommands="add status init update"
+	if [ -z "$(__git_find_subcommand "$subcommands")" ]; then
 		local cur="${COMP_WORDS[COMP_CWORD]}"
 		case "$cur" in
 		--*)
 			__gitcomp "--quiet --cached"
 			;;
 		*)
-			__gitcomp "add status init update"
+			__gitcomp "$subcommands"
 			;;
 		esac
 		return
-- 
1.5.4.4.481.g5075

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH] bash: add new 'git stash' subcommands
  2008-03-10 15:02 ` [PATCH 2/2] bash: refactor searching for subcommands on the command line SZEDER Gábor
@ 2008-03-10 15:02   ` SZEDER Gábor
  2008-03-10 15:02     ` [PATCH] bash: add 'git svn' subcommands and options SZEDER Gábor
  0 siblings, 1 reply; 5+ messages in thread
From: SZEDER Gábor @ 2008-03-10 15:02 UTC (permalink / raw)
  To: Shawn O. Pearce; +Cc: Junio C Hamano, git, SZEDER Gábor

Namely 'save', 'drop', 'pop' and 'create'

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
---
 contrib/completion/git-completion.bash |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 0feed97..c194972 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1127,7 +1127,7 @@ _git_show ()
 
 _git_stash ()
 {
-	local subcommands='list show apply clear'
+	local subcommands='save list show apply clear drop pop create'
 	if [ -z "$(__git_find_subcommand "$subcommands")" ]; then
 		__gitcomp "$subcommands"
 	fi
-- 
1.5.4.4.481.g5075

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH] bash: add 'git svn' subcommands and options
  2008-03-10 15:02   ` [PATCH] bash: add new 'git stash' subcommands SZEDER Gábor
@ 2008-03-10 15:02     ` SZEDER Gábor
  0 siblings, 0 replies; 5+ messages in thread
From: SZEDER Gábor @ 2008-03-10 15:02 UTC (permalink / raw)
  To: Shawn O. Pearce; +Cc: Junio C Hamano, git, SZEDER Gábor

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
---
 contrib/completion/git-completion.bash |   81 +++++++++++++++++++++++++++++++-
 1 files changed, 80 insertions(+), 1 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index c194972..5a844f5 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -392,7 +392,6 @@ __git_commands ()
 		show-index)       : plumbing;;
 		ssh-*)            : transport;;
 		stripspace)       : plumbing;;
-		svn)              : import export;;
 		symbolic-ref)     : plumbing;;
 		tar-tree)         : deprecated;;
 		unpack-file)      : plumbing;;
@@ -1150,6 +1149,84 @@ _git_submodule ()
 	fi
 }
 
+_git_svn ()
+{
+	local subcommands="
+		init fetch clone rebase dcommit log find-rev
+		set-tree commit-diff info create-ignore propget
+		proplist show-ignore show-externals
+		"
+	local subcommand="$(__git_find_subcommand "$subcommands")"
+	if [ -z "$subcommand" ]; then
+		__gitcomp "$subcommands"
+	else
+		local remote_opts="--username= --config-dir= --no-auth-cache"
+		local fc_opts="
+			--follow-parent --authors-file= --repack=
+			--no-metadata --use-svm-props --use-svnsync-props
+			--log-window-size= --no-checkout --quiet
+			--repack-flags --user-log-author $remote_opts
+			"
+		local init_opts="
+			--template= --shared= --trunk= --tags=
+			--branches= --stdlayout --minimize-url
+			--no-metadata --use-svm-props --use-svnsync-props
+			--rewrite-root= $remote_opts
+			"
+		local cmt_opts="
+			--edit --rmdir --find-copies-harder --copy-similarity=
+			"
+
+		local cur="${COMP_WORDS[COMP_CWORD]}"
+		case "$subcommand,$cur" in
+		fetch,--*)
+			__gitcomp "--revision= --fetch-all $fc_opts"
+			;;
+		clone,--*)
+			__gitcomp "--revision= $fc_opts $init_opts"
+			;;
+		init,--*)
+			__gitcomp "$init_opts"
+			;;
+		dcommit,--*)
+			__gitcomp "
+				--merge --strategy= --verbose --dry-run
+				--fetch-all --no-rebase $cmt_opts $fc_opts
+				"
+			;;
+		set-tree,--*)
+			__gitcomp "--stdin $cmt_opts $fc_opts"
+			;;
+		create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
+		show-externals,--*)
+			__gitcomp "--revision="
+			;;
+		log,--*)
+			__gitcomp "
+				--limit= --revision= --verbose --incremental
+				--oneline --show-commit --non-recursive
+				--authors-file=
+				"
+			;;
+		rebase,--*)
+			__gitcomp "
+				--merge --verbose --strategy= --local
+				--fetch-all $fc_opts
+				"
+			;;
+		commit-diff,--*)
+			__gitcomp "--message= --file= --revision= $cmt_opts"
+			;;
+		info,--*)
+			__gitcomp "--url"
+			;;
+		*)
+			COMPREPLY=()
+			;;
+		esac
+	fi
+}
+
 _git_tag ()
 {
 	local i c=1 f=0
@@ -1251,6 +1328,7 @@ _git ()
 	show-branch) _git_log ;;
 	stash)       _git_stash ;;
 	submodule)   _git_submodule ;;
+	svn)         _git_svn ;;
 	tag)         _git_tag ;;
 	whatchanged) _git_log ;;
 	*)           COMPREPLY=() ;;
@@ -1301,6 +1379,7 @@ complete -o default -o nospace -F _git_shortlog git-shortlog
 complete -o default -o nospace -F _git_show git-show
 complete -o default -o nospace -F _git_stash git-stash
 complete -o default -o nospace -F _git_submodule git-submodule
+complete -o default -o nospace -F _git_svn git-svn
 complete -o default -o nospace -F _git_log git-show-branch
 complete -o default -o nospace -F _git_tag git-tag
 complete -o default -o nospace -F _git_log git-whatchanged
-- 
1.5.4.4.481.g5075

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] bash: remove unnecessary conditions when checking for subcommands
  2008-03-10 15:02 [PATCH 1/2] bash: remove unnecessary conditions when checking for subcommands SZEDER Gábor
  2008-03-10 15:02 ` [PATCH 2/2] bash: refactor searching for subcommands on the command line SZEDER Gábor
@ 2008-03-10 23:54 ` Shawn O. Pearce
  1 sibling, 0 replies; 5+ messages in thread
From: Shawn O. Pearce @ 2008-03-10 23:54 UTC (permalink / raw)
  To: SZEDER Gábor; +Cc: Junio C Hamano, git

SZEDER Gbor <szeder@ira.uka.de> wrote:
> Checking emptyness of $command is sufficient.
> 
> Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>

Thanks.  I have your entire series in a branch that I will
be asking Junio to merge.

-- 
Shawn.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-03-10 23:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-03-10 15:02 [PATCH 1/2] bash: remove unnecessary conditions when checking for subcommands SZEDER Gábor
2008-03-10 15:02 ` [PATCH 2/2] bash: refactor searching for subcommands on the command line SZEDER Gábor
2008-03-10 15:02   ` [PATCH] bash: add new 'git stash' subcommands SZEDER Gábor
2008-03-10 15:02     ` [PATCH] bash: add 'git svn' subcommands and options SZEDER Gábor
2008-03-10 23:54 ` [PATCH 1/2] bash: remove unnecessary conditions when checking for subcommands Shawn O. Pearce

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).