Skip to content

Commit

Permalink
tg: case cleanup
Browse files Browse the repository at this point in the history
Using ":;;" is unnecessary as the shell grammar explicitly permits
just a bare ";;" with no statement preceding it after a case selector.

Replace all ":;;" with ";;" and remove some other whitespace too.

Signed-off-by: Kyle J. McKay <[email protected]>
  • Loading branch information
mackyle committed Jan 4, 2017
1 parent f0fbf0a commit 8c7f300
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 33 deletions.
4 changes: 2 additions & 2 deletions tg-create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ if [ -z "$nodeps" ]; then
[ -z "$sr" ] || git rev-parse --verify --quiet "$sr" -- ||
die "refusing to depend on unborn branch (use --no-deps)"
[ -n "$sr" ] || die "cannot depend on a detached HEAD"
case "$sr" in refs/heads/*) :;; *)
case "$sr" in refs/heads/*);;*)
die "HEAD is a symref to other than refs/heads/..."
esac
d="${sr#refs/heads/}"
Expand Down Expand Up @@ -399,7 +399,7 @@ EOT
subj="$(get_subject <"$git_dir/TG_EDITMSG")"
if [ -z "$subj" ]; then
subj="$(sed -n "s/^[ $tab][ $tab]*//; 1p" <"$git_dir/TG_EDITMSG")";
case "$subj" in "["*) :;; *) subj="[$branchtype] $subj"; esac
case "$subj" in "["*);;*) subj="[$branchtype] $subj"; esac
printf '%s\n' "Subject: $subj" "" >"$git_dir/TG_EDITMSG"+
sed -n '2,$p' <"$git_dir/TG_EDITMSG" | git stripspace >>"$git_dir/TG_EDITMSG"+
mv -f "$git_dir/TG_EDITMSG"+ "$git_dir/TG_EDITMSG"
Expand Down
2 changes: 1 addition & 1 deletion tg-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ else
if [ "$name" = "HEAD" ]; then
sr="$(git symbolic-ref --quiet HEAD || :)"
[ -n "$sr" ] || die "cannot push a detached HEAD"
case "$sr" in refs/heads/*) :;; *)
case "$sr" in refs/heads/*);;*)
die "HEAD is a symref to other than refs/heads/..."
esac
branches="${branches:+$branches }${sr#refs/heads/}"
Expand Down
10 changes: 5 additions & 5 deletions tg-revert.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ case "$tagname" in --stash"@{"*"}")
tagname="refs/tgstash@{$strip}"
esac
refname="$tagname"
case "$refname" in HEAD|refs/*) :;; *)
case "$refname" in HEAD|refs/*);;*)
suffix="${refname%@*}"
suffix="${refname#$suffix}"
refname="${refname%$suffix}"
Expand Down Expand Up @@ -184,7 +184,7 @@ for b; do
exp=
case "$b" in refs/*) exp=1; rn="$b";; *) rn="refs/heads/$b"; esac
ref_exists "$rn" || die "not present in tag data (try --list): $rn"
case " $refs " in *" $rn "*) :;; *)
case " $refs " in *" $rn "*);;*)
refs="${refs:+$refs }$rn"
if [ -z "$list" ] && [ -z "$nodeps" -o -z "$exp" ] && is_tgish "$rn"; then
case "$rn" in
Expand Down Expand Up @@ -275,7 +275,7 @@ if [ -n "$list" ]; then
if [ -z "$deps$rdeps" ]; then
while read -r name rev; do
case "$exclude" in *" $name "*) continue; esac
[ -z "$refs" ] || case " $refs " in *" $name "*) :;; *) continue; esac
[ -z "$refs" ] || case " $refs " in *" $name "*);;*) continue; esac
[ -z "$tgish" ] || is_tgish "$name" || continue
printf '%s %s\n' "$(git rev-parse --verify --quiet --short "$rev" --)" "$name"
done <"$trf"
Expand All @@ -302,7 +302,7 @@ get_short() {
if [ -n "$nodeps" -o -z "$refs" ]; then
while read -r name rev; do
case "$exclude" in *" $name "*) continue; esac
[ -z "$refs" ] || case " $refs " in *" $name "*) :;; *) continue; esac
[ -z "$refs" ] || case " $refs " in *" $name "*);;*) continue; esac
[ -z "$tgish" ] || is_tgish "$name" || continue
printf 'revert %s %s\n' "$(get_short "$rev")" "$name"
done <"$trf" | LC_ALL=C sort -u -b -k3,3 >"$insn"
Expand Down Expand Up @@ -336,7 +336,7 @@ EOT
while read -r op hash ref; do
[ "$op" = "r" -o "$op" = "revert" ] ||
die "invalid op in instruction: $op $hash $ref"
case "$ref" in refs/?*) :;; *)
case "$ref" in refs/?*);;*)
die "invalid ref in instruction: $op $hash $ref"
esac
ref_exists "$ref" ||
Expand Down
28 changes: 14 additions & 14 deletions tg-tag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ case "$refname" in [!@]*"@{"*"}")
refname="${refname%@*}"
sfx="${sfx#$refname}"
esac
case "$refname" in HEAD|refs/*) :;; *)
case "$refname" in HEAD|refs/*);;*)
if reftest="$(git rev-parse --revs-only --symbolic-full-name "$refname" -- 2>/dev/null)" &&
[ -n "$reftest" ]; then
if [ -n "$reflog$drop$clear$delete" ]; then
Expand Down Expand Up @@ -393,7 +393,7 @@ while read -r obj typ ref && [ -n "$obj" -a -n "$typ" ]; do
ignore="${ignore:+$ignore }$ref"
continue
fi
case " $newlist " in *" $ref "*) :;; *)
case " $newlist " in *" $ref "*);;*)
newlist="${newlist:+$newlist }$ref"
esac
if [ "$typ" = "tag" ]; then
Expand All @@ -416,7 +416,7 @@ for b; do
[ -n "$sfn" ] || {
[ -n "$anyrefok" ] || die "no such symbolic ref name: $b"
fullhash="$(git rev-parse --verify --quiet "$b" --)" || die "no such ref: $b"
case " $extrarefs " in *" $b "*) :;; *)
case " $extrarefs " in *" $b "*);;*)
warn "including non-symbolic ref only in parents calculation: $b"
extrarefs="${extrarefs:+$extrarefs }$fullhash"
esac
Expand All @@ -429,18 +429,18 @@ for b; do
ref_exists "refs/$topbases/${sfn#refs/heads/}" || tgish=
[ -n "$anyrefok" ] || [ -n "$tgish" ] ||
die "not a TopGit branch: ${sfn#refs/heads/} (use --allow-any option)"
case " $allrefs " in *" $b "*) :;; *)
case " $allrefs " in *" $b "*);;*)
allrefs="${allrefs:+$allrefs }$sfn"
esac
case " $branches " in *" ${sfn#refs/heads/} "*) :;; *)
case " $branches " in *" ${sfn#refs/heads/} "*);;*)
branches="${branches:+$branches }${sfn#refs/heads/}"
added=1
esac
if [ -n "$tgish" ]; then
case " $allrefs " in *" refs/$topbases/${sfn#refs/heads/} "*) :;; *)
case " $allrefs " in *" refs/$topbases/${sfn#refs/heads/} "*);;*)
allrefs="${allrefs:+$allrefs }refs/$topbases/${sfn#refs/heads/}"
esac
case " $tgbranches " in *" ${sfn#refs/heads/} "*) :;; *)
case " $tgbranches " in *" ${sfn#refs/heads/} "*);;*)
tgbranches="${tgbranches:+$tgbranches }${sfn#refs/heads/}"
added=1
esac
Expand All @@ -455,18 +455,18 @@ for b; do
ref_exists "refs/heads/${sfn#refs/$topbases/}" || tgish=
[ -n "$anyrefok" ] || [ -n "$tgish" ] ||
warn "including TopGit base that's missing its head: $sfn"
case " $allrefs " in *" $sfn "*) :;; *)
case " $allrefs " in *" $sfn "*);;*)
allrefs="${allrefs:+$allrefs }$sfn"
esac
case " $branches " in *" ${sfn#refs/$topbases/} "*) :;; *)
case " $branches " in *" ${sfn#refs/$topbases/} "*);;*)
branches="${branches:+$branches }${sfn#refs/$topbases/}"
added=1
esac
if [ -n "$tgish" ]; then
case " $allrefs " in *" refs/heads/${sfn#refs/$topbases/} "*) :;; *)
case " $allrefs " in *" refs/heads/${sfn#refs/$topbases/} "*);;*)
allrefs="${allrefs:+$allrefs }refs/heads/${sfn#refs/$topbases/}"
esac
case " $tgbranches " in *" ${sfn#refs/$topbases/} "*) :;; *)
case " $tgbranches " in *" ${sfn#refs/$topbases/} "*);;*)
tgbranches="${tgbranches:+$tgbranches }${sfn#refs/$topbases/}"
added=1
esac
Expand All @@ -477,10 +477,10 @@ for b; do
;;
*)
[ -n "$anyrefok" ] || die "refusing to include without --allow-any: $sfn"
case " $allrefs " in *" $sfn "*) :;; *)
case " $allrefs " in *" $sfn "*);;*)
allrefs="${allrefs:+$allrefs }$sfn"
esac
case " $branches " in *" ${sfn#refs/} "*) :;; *)
case " $branches " in *" ${sfn#refs/} "*);;*)
branches="${branches:+$branches }${sfn#refs/}"
othercount=$(( $othercount + 1 ))
esac
Expand Down Expand Up @@ -532,7 +532,7 @@ out_of_date=
if [ -n "$outofdateok" ]; then
if [ -n "$tgbranches" ]; then
while read -r dep && [ -n "$dep" ]; do
case " $allrefs " in *" $dep "*) :;; *)
case " $allrefs " in *" $dep "*);;*)
! ref_exists "$dep" ||
allrefs="${allrefs:+$allrefs }$dep"
esac
Expand Down
20 changes: 9 additions & 11 deletions tg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,8 @@ precheck() {
if ! git_version="$(git version)"; then
die "'git version' failed"
fi
case "$git_version" in
[Gg]"it version "*) :;;
*)
die "'git version' output does not start with 'git version '"
case "$git_version" in [Gg]"it version "*);;*)
die "'git version' output does not start with 'git version '"
esac
git_vernum="$(echo "$git_version" | sed -ne 's/^[^0-9]*\([0-9][0-9]*\(\.[0-9][0-9]*\)*\).*$/\1/p')"

Expand Down Expand Up @@ -275,7 +273,7 @@ make_empty_commit()
else
case "$ZONE" in
-[01][0-9][0-5][0-9]|+[01][0-9][0-5][0-9])
:;;
;;
[01][0-9][0-5][0-9])
ZONE="+$ZONE"
;;
Expand Down Expand Up @@ -429,7 +427,7 @@ ref_exists_rev()
{
case "$1" in
refs/*)
:;;
;;
$octet20)
printf '%s' "$1"
return;;
Expand All @@ -455,9 +453,9 @@ ref_exists_rev_short()
{
case "$1" in
refs/*)
:;;
;;
$octet20)
:;;
;;
*)
die "ref_exists_rev_short requires fully-qualified ref name"
esac
Expand Down Expand Up @@ -537,7 +535,7 @@ verify_topgit_branch()
HEAD)
_verifyname="$(git symbolic-ref HEAD 2>/dev/null || :)"
[ -n "$_verifyname" -o "$2" = "-f" ] || die "HEAD is not a symbolic ref"
case "$_verifyname" in refs/heads/*) :;; *)
case "$_verifyname" in refs/heads/*);;*)
[ "$2" != "-f" ] || return 1
die "HEAD is not a symbolic ref to the refs/heads namespace"
esac
Expand Down Expand Up @@ -752,7 +750,7 @@ recurse_deps()
_dep_missing=
if [ "$_ismissing" != "0" ]; then
_dep_missing=1
case " $missing_deps " in *" $_dep "*) :;; *)
case " $missing_deps " in *" $_dep "*);;*)
missing_deps="${missing_deps:+$missing_deps }$_dep"
esac
fi
Expand Down Expand Up @@ -1211,7 +1209,7 @@ else

# If tg contains a '/' but does not start with one then replace it with an absolute path

case "$0" in /*) :;; */*)
case "$0" in /*) ;; */*)
tgdir="$(cd "$(dirname "$0")" && pwd -P)/"
tg="$tgdir$tgname"
esac
Expand Down

0 comments on commit 8c7f300

Please sign in to comment.