git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Shell script cleanups/style changes?
@ 2007-08-02 10:44 David Kastrup
  2007-08-02 14:00 ` Robert Schiele
                   ` (2 more replies)
  0 siblings, 3 replies; 42+ messages in thread
From: David Kastrup @ 2007-08-02 10:44 UTC (permalink / raw)
  To: git

[-- Attachment #1: Type: text/plain, Size: 742 bytes --]


Hi, I wanted to ask what the general stance towards shell script
cleanups and simplifications would be.  For example, I find the expr
usage quite inscrutable in commit, and there is no necessity of
putting "shift" in every case branch instead of once behind it, and a
lot of conditionals and other manipulations can be made much easier on
the eye by using parameter expansion patterns that are, as far as I
can see, available with every reasonable Bourne Shell and clones.

Here is an example context diff (in this case, I find it more readable
than unified) to illustrate (untested!, please don't apply without a
regular formatted git patch).

Should I bother doing such cleanups as I read up on code, or should I
just leave things alone?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 6998 bytes --]

diff --git a/git-commit.sh b/git-commit.sh
index d7e7028..bdf20be 100755
*** a/git-commit.sh
--- b/git-commit.sh
***************
*** 97,101 ****
  		no_edit=t
  		log_given=t$log_given
  		logfile="$1"
- 		shift
  		;;
--- 97,100 ----
***************
*** 102,107 ****
  	-F*|-f*)
  		no_edit=t
  		log_given=t$log_given
! 		logfile=`expr "z$1" : 'z-[Ff]\(.*\)'`
! 		shift
  		;;
--- 101,105 ----
  	-F*|-f*)
  		no_edit=t
  		log_given=t$log_given
! 		logfile="${1#-?}"
  		;;
***************
*** 108,113 ****
  	--F=*|--f=*|--fi=*|--fil=*|--file=*)
  		no_edit=t
  		log_given=t$log_given
! 		logfile=`expr "z$1" : 'z-[^=]*=\(.*\)'`
! 		shift
  		;;
--- 106,110 ----
  	--F=*|--f=*|--fi=*|--fil=*|--file=*)
  		no_edit=t
  		log_given=t$log_given
! 		logfile="${1#*=}"
  		;;
***************
*** 114,117 ****
  	-a|--a|--al|--all)
  		all=t
- 		shift
  		;;
--- 111,113 ----
***************
*** 118,127 ****
  	--au=*|--aut=*|--auth=*|--autho=*|--author=*)
! 		force_author=`expr "z$1" : 'z-[^=]*=\(.*\)'`
! 		shift
  		;;
  	--au|--aut|--auth|--autho|--author)
  		case "$#" in 1) usage ;; esac
  		shift
  		force_author="$1"
- 		shift
  		;;
--- 114,121 ----
  	--au=*|--aut=*|--auth=*|--autho=*|--author=*)
! 		force_author="${1#*=}"
  		;;
  	--au|--aut|--auth|--autho|--author)
  		case "$#" in 1) usage ;; esac
  		shift
  		force_author="$1"
  		;;
***************
*** 128,144 ****
  	-e|--e|--ed|--edi|--edit)
  		edit_flag=t
- 		shift
  		;;
  	-i|--i|--in|--inc|--incl|--inclu|--includ|--include)
  		also=t
- 		shift
  		;;
  	--int|--inte|--inter|--intera|--interac|--interact|--interacti|\
  	--interactiv|--interactive)
  		interactive=t
- 		shift
  		;;
  	-o|--o|--on|--onl|--only)
  		only=t
- 		shift
  		;;
--- 122,134 ----
***************
*** 145,159 ****
  	-m|--m|--me|--mes|--mess|--messa|--messag|--message)
  		case "$#" in 1) usage ;; esac
- 		shift
  		log_given=m$log_given
! 		if test "$log_message" = ''
! 		then
! 		    log_message="$1"
! 		else
! 		    log_message="$log_message
  
! $1"
! 		fi
  		no_edit=t
- 		shift
  		;;
--- 135,142 ----
  	-m|--m|--me|--mes|--mess|--messa|--messag|--message)
  		case "$#" in 1) usage ;; esac
  		log_given=m$log_given
! 		log_message="${log_message}${log_message:+
  
! }$1"
  		no_edit=t
  		;;
***************
*** 160,172 ****
  	-m*)
  		log_given=m$log_given
! 		if test "$log_message" = ''
! 		then
! 		    log_message=`expr "z$1" : 'z-m\(.*\)'`
! 		else
! 		    log_message="$log_message
  
! `expr "z$1" : 'z-m\(.*\)'`"
! 		fi
  		no_edit=t
- 		shift
  		;;
--- 143,149 ----
  	-m*)
  		log_given=m$log_given
! 		log_message="${log_message}${log_message:+
  
! }${1#-m}"
  		no_edit=t
  		;;
***************
*** 173,185 ****
  	--m=*|--me=*|--mes=*|--mess=*|--messa=*|--messag=*|--message=*)
  		log_given=m$log_given
! 		if test "$log_message" = ''
! 		then
! 		    log_message=`expr "z$1" : 'z-[^=]*=\(.*\)'`
! 		else
! 		    log_message="$log_message
  
! `expr "z$1" : 'zq-[^=]*=\(.*\)'`"
! 		fi
  		no_edit=t
- 		shift
  		;;
--- 150,156 ----
  	--m=*|--me=*|--mes=*|--mess=*|--messa=*|--messag=*|--message=*)
  		log_given=m$log_given
! 		log_message="${log_message}${log_message:+
  
! }${1#*=}"
  		no_edit=t
  		;;
***************
*** 186,197 ****
  	-n|--n|--no|--no-|--no-v|--no-ve|--no-ver|--no-veri|--no-verif|\
  	--no-verify)
  		verify=
- 		shift
  		;;
  	--a|--am|--ame|--amen|--amend)
  		amend=t
  		use_commit=HEAD
- 		shift
  		;;
  	-c)
  		case "$#" in 1) usage ;; esac
--- 157,166 ----
***************
*** 199,203 ****
  		log_given=t$log_given
  		use_commit="$1"
  		no_edit=
- 		shift
  		;;
--- 168,171 ----
***************
*** 204,213 ****
  	--ree=*|--reed=*|--reedi=*|--reedit=*|--reedit-=*|--reedit-m=*|\
  	--reedit-me=*|--reedit-mes=*|--reedit-mess=*|--reedit-messa=*|\
  	--reedit-messag=*|--reedit-message=*)
  		log_given=t$log_given
! 		use_commit=`expr "z$1" : 'z-[^=]*=\(.*\)'`
  		no_edit=
- 		shift
  		;;
  	--ree|--reed|--reedi|--reedit|--reedit-|--reedit-m|--reedit-me|\
  	--reedit-mes|--reedit-mess|--reedit-messa|--reedit-messag|\
--- 172,180 ----
  	--ree=*|--reed=*|--reedi=*|--reedit=*|--reedit-=*|--reedit-m=*|\
  	--reedit-me=*|--reedit-mes=*|--reedit-mess=*|--reedit-messa=*|\
  	--reedit-messag=*|--reedit-message=*)
  		log_given=t$log_given
! 		use_commit="${1#*=}"
  		no_edit=
  		;;
  	--ree|--reed|--reedi|--reedit|--reedit-|--reedit-m|--reedit-me|\
  	--reedit-mes|--reedit-mess|--reedit-messa|--reedit-messag|\
***************
*** 217,223 ****
  		log_given=t$log_given
  		use_commit="$1"
  		no_edit=
- 		shift
  		;;
  	-C)
  		case "$#" in 1) usage ;; esac
--- 184,189 ----
***************
*** 225,229 ****
  		log_given=t$log_given
  		use_commit="$1"
  		no_edit=t
- 		shift
  		;;
--- 191,194 ----
***************
*** 230,239 ****
  	--reu=*|--reus=*|--reuse=*|--reuse-=*|--reuse-m=*|--reuse-me=*|\
  	--reuse-mes=*|--reuse-mess=*|--reuse-messa=*|--reuse-messag=*|\
  	--reuse-message=*)
  		log_given=t$log_given
! 		use_commit=`expr "z$1" : 'z-[^=]*=\(.*\)'`
  		no_edit=t
- 		shift
  		;;
  	--reu|--reus|--reuse|--reuse-|--reuse-m|--reuse-me|--reuse-mes|\
  	--reuse-mess|--reuse-messa|--reuse-messag|--reuse-message)
--- 195,203 ----
  	--reu=*|--reus=*|--reuse=*|--reuse-=*|--reuse-m=*|--reuse-me=*|\
  	--reuse-mes=*|--reuse-mess=*|--reuse-messa=*|--reuse-messag=*|\
  	--reuse-message=*)
  		log_given=t$log_given
! 		use_commit="${1#*=}"
  		no_edit=t
  		;;
  	--reu|--reus|--reuse|--reuse-|--reuse-m|--reuse-me|--reuse-mes|\
  	--reuse-mess|--reuse-messa|--reuse-messag|--reuse-message)
***************
*** 242,273 ****
  		log_given=t$log_given
  		use_commit="$1"
  		no_edit=t
- 		shift
  		;;
  	-s|--s|--si|--sig|--sign|--signo|--signof|--signoff)
  		signoff=t
- 		shift
  		;;
  	-t|--t|--te|--tem|--temp|--templ|--templa|--templat|--template)
  		case "$#" in 1) usage ;; esac
  		shift
  		templatefile="$1"
  		no_edit=
- 		shift
  		;;
  	-q|--q|--qu|--qui|--quie|--quiet)
  		quiet=t
- 		shift
  		;;
  	-v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose)
  		verbose=t
- 		shift
  		;;
  	-u|--u|--un|--unt|--untr|--untra|--untrac|--untrack|--untracke|\
  	--untracked|--untracked-|--untracked-f|--untracked-fi|--untracked-fil|\
  	--untracked-file|--untracked-files)
  		untracked_files=t
- 		shift
  		;;
  	--)
  		shift
--- 206,231 ----
***************
*** 280,285 ****
--- 238,244 ----
  		break
  		;;
  	esac
+ 	shift
  done
  case "$edit_flag" in t) no_edit= ;; esac
  
***************
*** 437,448 ****
  
  if test t = "$verify" && test -x "$GIT_DIR"/hooks/pre-commit
  then
! 	if test "$TMP_INDEX"
! 	then
! 		GIT_INDEX_FILE="$TMP_INDEX" "$GIT_DIR"/hooks/pre-commit
! 	else
! 		GIT_INDEX_FILE="$USE_INDEX" "$GIT_DIR"/hooks/pre-commit
! 	fi || exit
  fi
  
  if test "$log_message" != ''
--- 396,403 ----
  
  if test t = "$verify" && test -x "$GIT_DIR"/hooks/pre-commit
  then
!     GIT_INDEX_FILE="${TMP_INDEX:-${USE_INDEX}}" "$GIT_DIR"/hooks/pre-commit \
!     || exit
  fi
  
  if test "$log_message" != ''

[-- Attachment #3: Type: text/plain, Size: 20 bytes --]



-- 
David Kastrup

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

end of thread, other threads:[~2007-08-04 20:39 UTC | newest]

Thread overview: 42+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-02 10:44 Shell script cleanups/style changes? David Kastrup
2007-08-02 14:00 ` Robert Schiele
2007-08-02 14:20   ` David Kastrup
2007-08-02 16:19     ` Robert Schiele
2007-08-02 17:05       ` Johannes Schindelin
2007-08-02 17:22         ` Robert Schiele
2007-08-03 19:29     ` Uwe Kleine-König
2007-08-02 14:48 ` Bradford Smith
2007-08-02 18:13   ` Sam Ravnborg
2007-08-02 20:37 ` Junio C Hamano
2007-08-02 20:56   ` Nguyen Thai Ngoc Duy
2007-08-02 21:02     ` David Kastrup
2007-08-02 21:12     ` Junio C Hamano
2007-08-02 20:57   ` David Kastrup
2007-08-02 21:21     ` Junio C Hamano
2007-08-02 21:29       ` Junio C Hamano
2007-08-02 22:02         ` David Kastrup
2007-08-02 21:41       ` Robert Schiele
2007-08-02 22:14         ` David Kastrup
2007-08-02 23:05           ` Junio C Hamano
2007-08-02 23:17             ` David Kastrup
2007-08-03  0:12               ` Junio C Hamano
2007-08-03  0:24                 ` David Kastrup
2007-08-03  0:48                   ` Junio C Hamano
2007-08-03  6:06                     ` David Kastrup
2007-08-03  7:41                       ` Junio C Hamano
2007-08-03  8:41                         ` David Kastrup
2007-08-03  6:13                     ` David Kastrup
2007-08-03  2:28                   ` Robert Schiele
2007-08-03  6:08                     ` David Kastrup
2007-08-02 23:21             ` Robert Schiele
2007-08-02 23:32               ` David Kastrup
2007-08-02 23:45                 ` Robert Schiele
2007-08-02 23:52                   ` David Kastrup
2007-08-03  0:01                     ` Robert Schiele
2007-08-03  0:11                       ` David Kastrup
2007-08-03  7:11                         ` Junio C Hamano
2007-08-02 23:27           ` Robert Schiele
2007-08-04  7:10         ` Florian Weimer
2007-08-04 20:32           ` Robert Schiele
2007-08-04 20:39             ` Junio C Hamano
2007-08-02 21:42       ` David Kastrup

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).