Skip to contentSkip to conversation

Simplified the invocation of command action in submodule

PATCH In review [email protected] 4 participants 12 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Simplified the invocation of command action in submodule

From: Imran M Yousuf <[email protected]>

- Simplified the invocation of action.
- Changed switch case based action invoke rather more direct command invocation. Previously first switch case was used to go through $@ and determine the action, i.e. add, init, update etc, and second switch case just to invoke the action. It is modified to determine the action name in the first case structure instead and later just invoke it.

---
 git-submodule.sh |   32 ++++++++++++--------------------
 1 files changed, 12 insertions(+), 20 deletions(-)
git-submodule.sh +12 -20
index ad9fe62..8a29382 100755
@@ -16,6 +16,7 @@ update=
 status=
 quiet=
 cached=
+command=
 
 #
 # print stuff on stdout unless -q was specified
@@ -293,20 +294,23 @@ modules_list()
 	done
 }
 
+# command specifies the whole function name since 
+# one of theirs prefix is module not modules
 while test $# != 0
 do
 	case "$1" in
 	add)
 		add=1
+		command="module_$1"
 		;;
 	init)
-		init=1
+		command="modules_$1"
 		;;
 	update)
-		update=1
+		command="modules_$1"
 		;;
 	status)
-		status=1
+		command="modules_list"
 		;;
 	-q|--quiet)
 		quiet=1
@@ -320,7 +324,7 @@ do
 		branch="$2"; shift
 		;;
 	--cached)
-		cached=1
+		command="modules_list"
 		;;
 	--)
 		break
@@ -345,20 +349,8 @@ case "$add,$branch" in
 	;;
 esac
 
-case "$add,$init,$update,$status,$cached" in
-1,,,,)
-	module_add "$@"
-	;;
-,1,,,)
-	modules_init "$@"
-	;;
-,,1,,)
-	modules_update "$@"
-	;;
-,,,*,*)
-	modules_list "$@"
-	;;
-*)
+if [ -z $command ]; then 
 	usage
-	;;
-esac
+else
+	"$command" "$@"
+fi
Signature · 1 line
1.5.3.7
#1 lore raw
Quoted 36 lines · [email protected] schrieb:
git-submodule.sh +7 -3
@@ -16,6 +16,7 @@ update=
 status=
 quiet=
 cached=
+command=
 
 #
 # print stuff on stdout unless -q was specified
@@ -293,20 +294,23 @@ modules_list()
 	done
 }
 
+# command specifies the whole function name since
+# one of theirs prefix is module not modules
 while test $# != 0
 do
 	case "$1" in
 	add)
 		add=1
+		command="module_$1"
 		;;
 	init)
-		init=1
+		command="modules_$1"
 		;;
 	update)
-		update=1
+		command="modules_$1"
 		;;
 	status)
-		status=1
+		command="modules_list"
 		;;
 	-q|--quiet)
 		quiet=1

git-submodule.sh do · line 327

Quoted 5 lines
git-submodule.sh +1 -1
@@ -320,7 +324,7 @@ do
 		branch="$2"; shift
 		;;
 	--cached)
-		cached=1
+		command="modules_list"

Don't remove cached=1 because otherwise --cached is effectively ignored.

Quoted 18 lines
git-submodule.sh +0 -11
 		;;
 	--)
 		break
@@ -345,20 +349,8 @@ case "$add,$branch" in
 	;;
 esac
 
-case "$add,$init,$update,$status,$cached" in
-1,,,,)
-	module_add "$@"
-	;;
-,1,,,)
-	modules_init "$@"
-	;;
-,,1,,)
-	modules_update "$@"
-	;;
-,,,*,*)

git-submodule.sh case "$add,$branch" in · line 356

Quoted 10 lines
git-submodule.sh +4 -5
-	modules_list "$@"
-	;;
-*)
+if [ -z $command ]; then
 	usage
-	;;
-esac
+else
+	"$command" "$@"
+fi

- Previously 'git submodule' was equvalent to 'git submodule status', now it is an error.

- Previously, passing --cached to add, init, or update was an error, now it is not.

-- Hannes

#2 lore raw

I already saw that mistake Johannes, thank you for pointing it out.

Quoted 83 lines · Johannes Sixt
Quoted 36 lines · [email protected] schrieb:
git-submodule.sh +7 -3
@@ -16,6 +16,7 @@ update=
 status=
 quiet=
 cached=
+command=
 
 #
 # print stuff on stdout unless -q was specified
@@ -293,20 +294,23 @@ modules_list()
      done
 }
 
+# command specifies the whole function name since
+# one of theirs prefix is module not modules
 while test $# != 0
 do
      case "$1" in
      add)
              add=1
+             command="module_$1"
              ;;
      init)
-             init=1
+             command="modules_$1"
              ;;
      update)
-             update=1
+             command="modules_$1"
              ;;
      status)
-             status=1
+             command="modules_list"
              ;;
      -q|--quiet)
              quiet=1

git-submodule.sh do · line 327

Quoted 5 lines
git-submodule.sh +1 -1
@@ -320,7 +324,7 @@ do
              branch="$2"; shift
              ;;
      --cached)
-             cached=1
+             command="modules_list"

Don't remove cached=1 because otherwise --cached is effectively ignored.

Quoted 18 lines
git-submodule.sh +0 -11
              ;;
      --)
              break
@@ -345,20 +349,8 @@ case "$add,$branch" in
      ;;
 esac
 
-case "$add,$init,$update,$status,$cached" in
-1,,,,)
-     module_add "$@"
-     ;;
-,1,,,)
-     modules_init "$@"
-     ;;
-,,1,,)
-     modules_update "$@"
-     ;;
-,,,*,*)

git-submodule.sh case "$add,$branch" in · line 356

Quoted 10 lines
git-submodule.sh +4 -5
-     modules_list "$@"
-     ;;
-*)
+if [ -z $command ]; then
      usage
-     ;;
-esac
+else
+     "$command" "$@"
+fi

- Previously 'git submodule' was equvalent to 'git submodule status', now it is an error.

- Previously, passing --cached to add, init, or update was an error, now it is not.

-- Hannes

Signature · 6 lines
Imran M Yousuf
Entrepreneur & Software Engineer
Smart IT Engineering
Dhaka, Bangladesh
Email: [email protected]
Mobile: +880-1711402557
#3 lore raw

-- Hannes

of them.
"that mistake" with no clue on which one you mean when I pointed out three BTW, on this list we don't top-post. In particular not when you write only

Quoted 5 lines · Imran M Yousuf

I already saw that mistake Johannes, thank you for pointing it out.

Quoted 2 lines · Johannes Sixt

[email protected] schrieb:

[...]

#4 lore raw
In reply to Johannes Sixt
Quoted 69 lines · Johannes Sixt
Quoted 36 lines · [email protected] schrieb:
git-submodule.sh +7 -3
@@ -16,6 +16,7 @@ update=
 status=
 quiet=
 cached=
+command=
 
 #
 # print stuff on stdout unless -q was specified
@@ -293,20 +294,23 @@ modules_list()
      done
 }
 
+# command specifies the whole function name since
+# one of theirs prefix is module not modules
 while test $# != 0
 do
      case "$1" in
      add)
              add=1
+             command="module_$1"
              ;;
      init)
-             init=1
+             command="modules_$1"
              ;;
      update)
-             update=1
+             command="modules_$1"
              ;;
      status)
-             status=1
+             command="modules_list"
              ;;
      -q|--quiet)
              quiet=1

git-submodule.sh do · line 327

Quoted 5 lines
git-submodule.sh +1 -1
@@ -320,7 +324,7 @@ do
              branch="$2"; shift
              ;;
      --cached)
-             cached=1
+             command="modules_list"

Don't remove cached=1 because otherwise --cached is effectively ignored.

Quoted 23 lines
git-submodule.sh +1 -14
              ;;
      --)
              break
@@ -345,20 +349,8 @@ case "$add,$branch" in
      ;;
 esac
 
-case "$add,$init,$update,$status,$cached" in
-1,,,,)
-     module_add "$@"
-     ;;
-,1,,,)
-     modules_init "$@"
-     ;;
-,,1,,)
-     modules_update "$@"
-     ;;
-,,,*,*)
-     modules_list "$@"
-     ;;
-*)
+if [ -z $command ]; then
      usage
Quoted 8 lines

git-submodule.sh case "$add,$branch" in · line 356

Quoted 5 lines
git-submodule.sh +3 -2
-     ;;
-esac
+else
+     "$command" "$@"
+fi

- Previously 'git submodule' was equvalent to 'git submodule status', now it is an error.

Yes, I forgot to add that status is the default command. Thanks for pointing it out.

Quoted 3 lines

- Previously, passing --cached to add, init, or update was an error, now it is not.

The usage statement and this behaviour is rather contradicting. The usage says that --cached can be used with all commands; so I am not sure whether using --cached with add should be an error or not. IMHO, if the previous implementation was right than the USAGE has to be changed, and if the previous implementation was incorrect, than if the default command is set to status than current implementation is right.

I would like to get comment on this until I fix the patch and resend it.

Quoted 3 lines

-- Hannes

Thank you,

Signature · 1 line
Imran M Yousuf
#5 lore raw
Quoted 10 lines · Imran M Yousuf
Quoted 2 lines · Johannes Sixt

- Previously, passing --cached to add, init, or update was an error, now it is not.

The usage statement and this behaviour is rather contradicting. The usage says that --cached can be used with all commands; so I am not sure whether using --cached with add should be an error or not. IMHO, if the previous implementation was right than the USAGE has to be changed, and if the previous implementation was incorrect, than if the default command is set to status than current implementation is right.

I prefer that the usage statement lists one line per sub-command with the flags that apply only to the sub-command. IOW, a usage statement that suggests that a flag applies to all sub-commands when in reality it doesn't is bogus, IMHO.

-- Hannes

#6 lore raw
Quoted 12 lines · Johannes Sixt
Quoted 10 lines · Imran M Yousuf
Quoted 2 lines · Johannes Sixt

- Previously, passing --cached to add, init, or update was an error, now it is not.

The usage statement and this behaviour is rather contradicting. The usage says that --cached can be used with all commands; so I am not sure whether using --cached with add should be an error or not. IMHO, if the previous implementation was right than the USAGE has to be changed, and if the previous implementation was incorrect, than if the default command is set to status than current implementation is right.

Quoted 5 lines

I prefer that the usage statement lists one line per sub-command with the flags that apply only to the sub-command. IOW, a usage statement that suggests that a flag applies to all sub-commands when in reality it doesn't is bogus, IMHO.

I think for this patch I will keep the usage intact and keep the implementation coherent with the current usage and add a comment in that place so that if required it can be changed in future.

Quoted 3 lines

-- Hannes

Signature · 1 line
Imran M Yousuf
#7 lore raw
In reply to Johannes Sixt
Quoted 12 lines · Johannes Sixt
Quoted 10 lines · Imran M Yousuf
Quoted 2 lines · Johannes Sixt

- Previously, passing --cached to add, init, or update was an error, now it is not.

The usage statement and this behaviour is rather contradicting. The usage says that --cached can be used with all commands; so I am not sure whether using --cached with add should be an error or not. IMHO, if the previous implementation was right than the USAGE has to be changed, and if the previous implementation was incorrect, than if the default command is set to status than current implementation is right.

Quoted 4 lines

I prefer that the usage statement lists one line per sub-command with the flags that apply only to the sub-command. IOW, a usage statement that suggests that a flag applies to all sub-commands when in reality it doesn't is bogus, IMHO.

I view the usage emitted by a command primarily as a quick reminder for people who are _already_ familiar with the command to help "was the option this command takes --foo or --bar? I can never remember which X-<" situation. The usage string is not a replacement of the manual page. For that reason, I generally prefer short and sweet one line usage for the whole command, even if it does not exactly capture mutually incompatible option combinations, _as long as_ the command itself is simple enough.

As you said, however, git-submodule is a command dispatcher on its own, and what its subcommands do are quite different, to the point that they probably should not even be sharing the option parser. One line per subcommand feels more appropriate.

By the way, Imran, if the current implementation declares a combination of "add" and "--cached" an error, and a new implementation does not, that's called a regression. Unless you can prove that the combination makes sense and the existing behaviour is a bug, in which case you can say the new implementation fixes the bug.

In this case, module_add does not even pay attention to $cached in the existing code. The choice is between (1) silently ignore user's expectation that "add --cached" would do something different from "add" without "--cached", or (2) tell the user that the combination does not make sense and error out. To people who _know_ what the command does, the choice between the two does not make much difference (they do not give ignored option, nor trigger the error), but to new people the latter is often easier to use.

#8 lore raw
In reply to Imran M Yousuf
Quoted 5 lines · Imran M Yousuf
Quoted 3 lines · Johannes Sixt

- Previously, passing --cached to add, init, or update was an error, now it is not.

Quoted 8 lines

The usage statement and this behaviour is rather contradicting. The usage says that --cached can be used with all commands; so I am not sure whether using --cached with add should be an error or not. IMHO, if the previous implementation was right than the USAGE has to be changed, and if the previous implementation was incorrect, than if the default command is set to status than current implementation is right.

I would like to get comment on this until I fix the patch and resend it.

--cached only makes sense for the status subcommand, so the usage/manpage probably should have looked like this (except for the whitespace mangling...):

Documentation/git-submodule.txt +4 -1
index cffc6d4..331e806 100644
@@ -10,7 +10,10 @@ SYNOPSIS
 --------
 [verse]
 'git-submodule' [--quiet] [-b branch] add <repository> [<path>]
-'git-submodule' [--quiet] [--cached] [status|init|update] [--] [<path>...]
+'git-submodule' [--quiet] [--cached] [status] [--] [<path>...]
+'git-submodule' [--quiet] init [--] [<path>...]
+'git-submodule' [--quiet] update [--] [<path>...]
+
 
 
 COMMANDS
Signature · 1 line
1.5.3.7.1141.g4eb39
#9 lore raw
Quoted 24 lines · Lars Hjemli
Quoted 5 lines · Imran M Yousuf
Quoted 3 lines · Johannes Sixt

- Previously, passing --cached to add, init, or update was an error, now it is not.

Quoted 8 lines

The usage statement and this behaviour is rather contradicting. The usage says that --cached can be used with all commands; so I am not sure whether using --cached with add should be an error or not. IMHO, if the previous implementation was right than the USAGE has to be changed, and if the previous implementation was incorrect, than if the default command is set to status than current implementation is right.

I would like to get comment on this until I fix the patch and resend it.

--cached only makes sense for the status subcommand, so the usage/manpage probably should have looked like this (except for the whitespace mangling...):

Documentation/git-submodule.txt +0 -0
index cffc6d4..331e806 100644

Documentation/git-submodule.txt SYNOPSIS · line 17

Quoted 9 lines
Documentation/git-submodule.txt +4 -1
@@ -10,7 +10,10 @@ SYNOPSIS
 --------
 [verse]
 'git-submodule' [--quiet] [-b branch] add <repository> [<path>]
-'git-submodule' [--quiet] [--cached] [status|init|update] [--] [<path>...]
+'git-submodule' [--quiet] [--cached] [status] [--] [<path>...]
+'git-submodule' [--quiet] init [--] [<path>...]
+'git-submodule' [--quiet] update [--] [<path>...]
+
 

This change makes a lot sense. Thus I will make sure that it is used in this manner :). Thanks a lot for clarifying it Lars. I wanted to know what is the purpose of '--'? If it is simply meant to be a separator than fine; else I would be grateful if you would please explain its purpose, so that I do not again implement wrongly :).

Quoted 5 lines
Documentation/git-submodule.txt +0 -1
 COMMANDS
--

1.5.3.7.1141.g4eb39

Signature · 1 line
Imran M Yousuf
#10 lore raw
In reply to [email protected]

git-submodule.sh update= · line 19

Quoted 9 lines · [email protected] writes:
git-submodule.sh +1 -0
index ad9fe62..8a29382 100755
@@ -16,6 +16,7 @@ update=
 status=
 quiet=
 cached=
+command=

Doesn't the patch make some if not all of the above variables unused?

git-submodule.sh modules_list() · line 308

Quoted 9 lines
git-submodule.sh +2 -1
 	case "$1" in
 	add)
 		add=1
+		command="module_$1"
 		;;
 	init)
-		init=1
+		command="modules_$1"
 		;;

Does the remaining code still use $add?

#11 lore raw

Hi Junio,

Firstly, $add is still used later in the code.
Secondly, yes the variables should be deleted. Will make the change and send the patch again; I forgot to clean the unused variables from the declaration, sorry.

Best regards,

Imran

Quoted 27 lines · Junio C Hamano

git-submodule.sh update= · line 19

Quoted 9 lines · [email protected] writes:
git-submodule.sh +1 -0
index ad9fe62..8a29382 100755
@@ -16,6 +16,7 @@ update=
 status=
 quiet=
 cached=
+command=

Doesn't the patch make some if not all of the above variables unused?

git-submodule.sh modules_list() · line 308

Quoted 9 lines
git-submodule.sh +2 -1
      case "$1" in
      add)
              add=1
+             command="module_$1"
              ;;
      init)
-             init=1
+             command="modules_$1"
              ;;

Does the remaining code still use $add?

Signature · 1 line
Imran M Yousuf