{"thread":{"id":"9900","subject":"[PATCH] git-commit.sh: Shell script cleanup","startedAt":"2007-09-17T20:56:44Z","lastAt":"2007-09-17T20:56:44Z","messageCount":1,"participants":["David Kastrup"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"53351","messageId":"85ejgx104z.fsf@lola.goethe.zz","threadId":"9900","inReplyTo":null,"subject":"[PATCH] git-commit.sh: Shell script cleanup","fromName":"David Kastrup","fromEmail":"dak@gnu.org","sentAt":"2007-09-17T20:56:44Z","receivedAt":"2007-09-17T20:56:44Z","isPatch":true,"sender":{"key":"dak@gnu.org","avatar":"https://avatars.githubusercontent.com/u/52141349?v=4"},"body":"This moves \"shift\" out of the argument processing \"case\".  It also\nreplaces quite a bit of expr calls with ${parameter#word} constructs,\nand uses ${parameter:+word} for avoiding conditionals where possible.\n\nSigned-off-by: David Kastrup <dak@gnu.org>\n---\nActually, this is almost the same patch as the one posted during the\n1.5.3 semi-freeze.  I just checked that it still applies and works,\nand that nothing has been changed incompatibly in the mean time.\n\nSome might argue that git-commit.sh could be implemented in C soon,\nanyway.  Well, exactly that would be an excellent reason to do this\nsort of cleanup, since then this file would get moved to\ncontrib/examples, and of course we want the examples to look as clean\nand understandable as possible, don't we?\n\nAt more than 4 times as many deletions than insertions, this is a nice\ncleanup, and quite more readable.\n\n git-commit.sh |   72 +++++++++++---------------------------------------------\n 1 files changed, 14 insertions(+), 58 deletions(-)\n\ndiff --git a/git-commit.sh b/git-commit.sh\nindex bb113e8..3e46dbb 100755\n--- a/git-commit.sh\n+++ b/git-commit.sh\n@@ -98,101 +98,71 @@ do\n \t\tno_edit=t\n \t\tlog_given=t$log_given\n \t\tlogfile=\"$1\"\n-\t\tshift\n \t\t;;\n \t-F*|-f*)\n \t\tno_edit=t\n \t\tlog_given=t$log_given\n-\t\tlogfile=`expr \"z$1\" : 'z-[Ff]\\(.*\\)'`\n-\t\tshift\n+\t\tlogfile=\"${1#-[Ff]}\"\n \t\t;;\n \t--F=*|--f=*|--fi=*|--fil=*|--file=*)\n \t\tno_edit=t\n \t\tlog_given=t$log_given\n-\t\tlogfile=`expr \"z$1\" : 'z-[^=]*=\\(.*\\)'`\n-\t\tshift\n+\t\tlogfile=\"${1#*=}\"\n \t\t;;\n \t-a|--a|--al|--all)\n \t\tall=t\n-\t\tshift\n \t\t;;\n \t--au=*|--aut=*|--auth=*|--autho=*|--author=*)\n-\t\tforce_author=`expr \"z$1\" : 'z-[^=]*=\\(.*\\)'`\n-\t\tshift\n+\t\tforce_author=\"${1#*=}\"\n \t\t;;\n \t--au|--aut|--auth|--autho|--author)\n \t\tcase \"$#\" in 1) usage ;; esac\n \t\tshift\n \t\tforce_author=\"$1\"\n-\t\tshift\n \t\t;;\n \t-e|--e|--ed|--edi|--edit)\n \t\tedit_flag=t\n-\t\tshift\n \t\t;;\n \t-i|--i|--in|--inc|--incl|--inclu|--includ|--include)\n \t\talso=t\n-\t\tshift\n \t\t;;\n \t--int|--inte|--inter|--intera|--interac|--interact|--interacti|\\\n \t--interactiv|--interactive)\n \t\tinteractive=t\n-\t\tshift\n \t\t;;\n \t-o|--o|--on|--onl|--only)\n \t\tonly=t\n-\t\tshift\n \t\t;;\n \t-m|--m|--me|--mes|--mess|--messa|--messag|--message)\n \t\tcase \"$#\" in 1) usage ;; esac\n \t\tshift\n \t\tlog_given=m$log_given\n-\t\tif test \"$log_message\" = ''\n-\t\tthen\n-\t\t    log_message=\"$1\"\n-\t\telse\n-\t\t    log_message=\"$log_message\n+\t\tlog_message=\"${log_message:+${log_message}\n \n-$1\"\n-\t\tfi\n+}$1\"\n \t\tno_edit=t\n-\t\tshift\n \t\t;;\n \t-m*)\n \t\tlog_given=m$log_given\n-\t\tif test \"$log_message\" = ''\n-\t\tthen\n-\t\t    log_message=`expr \"z$1\" : 'z-m\\(.*\\)'`\n-\t\telse\n-\t\t    log_message=\"$log_message\n+\t\tlog_message=\"${log_message:+${log_message}\n \n-`expr \"z$1\" : 'z-m\\(.*\\)'`\"\n-\t\tfi\n+}${1#-m}\"\n \t\tno_edit=t\n-\t\tshift\n \t\t;;\n \t--m=*|--me=*|--mes=*|--mess=*|--messa=*|--messag=*|--message=*)\n \t\tlog_given=m$log_given\n-\t\tif test \"$log_message\" = ''\n-\t\tthen\n-\t\t    log_message=`expr \"z$1\" : 'z-[^=]*=\\(.*\\)'`\n-\t\telse\n-\t\t    log_message=\"$log_message\n+\t\tlog_message=\"${log_message:+${log_message}\n \n-`expr \"z$1\" : 'zq-[^=]*=\\(.*\\)'`\"\n-\t\tfi\n+}${1#*=}\"\n \t\tno_edit=t\n-\t\tshift\n \t\t;;\n \t-n|--n|--no|--no-|--no-v|--no-ve|--no-ver|--no-veri|--no-verif|\\\n \t--no-verify)\n \t\tverify=\n-\t\tshift\n \t\t;;\n \t--a|--am|--ame|--amen|--amend)\n \t\tamend=t\n \t\tuse_commit=HEAD\n-\t\tshift\n \t\t;;\n \t-c)\n \t\tcase \"$#\" in 1) usage ;; esac\n@@ -200,15 +170,13 @@ $1\"\n \t\tlog_given=t$log_given\n \t\tuse_commit=\"$1\"\n \t\tno_edit=\n-\t\tshift\n \t\t;;\n \t--ree=*|--reed=*|--reedi=*|--reedit=*|--reedit-=*|--reedit-m=*|\\\n \t--reedit-me=*|--reedit-mes=*|--reedit-mess=*|--reedit-messa=*|\\\n \t--reedit-messag=*|--reedit-message=*)\n \t\tlog_given=t$log_given\n-\t\tuse_commit=`expr \"z$1\" : 'z-[^=]*=\\(.*\\)'`\n+\t\tuse_commit=\"${1#*=}\"\n \t\tno_edit=\n-\t\tshift\n \t\t;;\n \t--ree|--reed|--reedi|--reedit|--reedit-|--reedit-m|--reedit-me|\\\n \t--reedit-mes|--reedit-mess|--reedit-messa|--reedit-messag|\\\n@@ -218,7 +186,6 @@ $1\"\n \t\tlog_given=t$log_given\n \t\tuse_commit=\"$1\"\n \t\tno_edit=\n-\t\tshift\n \t\t;;\n \t-C)\n \t\tcase \"$#\" in 1) usage ;; esac\n@@ -226,15 +193,13 @@ $1\"\n \t\tlog_given=t$log_given\n \t\tuse_commit=\"$1\"\n \t\tno_edit=t\n-\t\tshift\n \t\t;;\n \t--reu=*|--reus=*|--reuse=*|--reuse-=*|--reuse-m=*|--reuse-me=*|\\\n \t--reuse-mes=*|--reuse-mess=*|--reuse-messa=*|--reuse-messag=*|\\\n \t--reuse-message=*)\n \t\tlog_given=t$log_given\n-\t\tuse_commit=`expr \"z$1\" : 'z-[^=]*=\\(.*\\)'`\n+\t\tuse_commit=\"${1#*=}\"\n \t\tno_edit=t\n-\t\tshift\n \t\t;;\n \t--reu|--reus|--reuse|--reuse-|--reuse-m|--reuse-me|--reuse-mes|\\\n \t--reuse-mess|--reuse-messa|--reuse-messag|--reuse-message)\n@@ -243,32 +208,26 @@ $1\"\n \t\tlog_given=t$log_given\n \t\tuse_commit=\"$1\"\n \t\tno_edit=t\n-\t\tshift\n \t\t;;\n \t-s|--s|--si|--sig|--sign|--signo|--signof|--signoff)\n \t\tsignoff=t\n-\t\tshift\n \t\t;;\n \t-t|--t|--te|--tem|--temp|--templ|--templa|--templat|--template)\n \t\tcase \"$#\" in 1) usage ;; esac\n \t\tshift\n \t\ttemplatefile=\"$1\"\n \t\tno_edit=\n-\t\tshift\n \t\t;;\n \t-q|--q|--qu|--qui|--quie|--quiet)\n \t\tquiet=t\n-\t\tshift\n \t\t;;\n \t-v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose)\n \t\tverbose=t\n-\t\tshift\n \t\t;;\n \t-u|--u|--un|--unt|--untr|--untra|--untrac|--untrack|--untracke|\\\n \t--untracked|--untracked-|--untracked-f|--untracked-fi|--untracked-fil|\\\n \t--untracked-file|--untracked-files)\n \t\tuntracked_files=t\n-\t\tshift\n \t\t;;\n \t--)\n \t\tshift\n@@ -281,6 +240,7 @@ $1\"\n \t\tbreak\n \t\t;;\n \tesac\n+\tshift\n done\n case \"$edit_flag\" in t) no_edit= ;; esac\n \n@@ -441,12 +401,8 @@ esac\n \n if test t = \"$verify\" && test -x \"$GIT_DIR\"/hooks/pre-commit\n then\n-\tif test \"$TMP_INDEX\"\n-\tthen\n-\t\tGIT_INDEX_FILE=\"$TMP_INDEX\" \"$GIT_DIR\"/hooks/pre-commit\n-\telse\n-\t\tGIT_INDEX_FILE=\"$USE_INDEX\" \"$GIT_DIR\"/hooks/pre-commit\n-\tfi || exit\n+    GIT_INDEX_FILE=\"${TMP_INDEX:-${USE_INDEX}}\" \"$GIT_DIR\"/hooks/pre-commit \\\n+    || exit\n fi\n \n if test \"$log_message\" != ''\n-- \n1.5.3.1.96.g4568\n"}]}