chiark / gitweb /
Revert "Rewrite fd-commit in POSIX Shell"
authorDaniel Martí <mvdan@mvdan.cc>
Sun, 6 Jul 2014 09:29:31 +0000 (11:29 +0200)
committerDaniel Martí <mvdan@mvdan.cc>
Sun, 6 Jul 2014 09:29:31 +0000 (11:29 +0200)
This reverts commit 62ba9dc07e989ce75b6bd9f971bbb1cec04c4da0.

fd-commit

index 20c84895fd1d8097ab3e3e84e7c52bcada45ae96..678f402a1a27a0e7ccb0a97dbef25eb840c34b96 100755 (executable)
--- a/fd-commit
+++ b/fd-commit
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 #
 # fd-commit - part of the FDroid server tools
 # Commits updates to apps, allowing you to edit the commit messages
@@ -18,7 +18,7 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-commands=""
+commands=()
 
 if [ ! -d metadata ]; then
        if [ -d ../metadata ]; then
@@ -30,17 +30,15 @@ if [ ! -d metadata ]; then
 fi
 
 while read line; do
-       [ -z "$line" ] && continue
-
-       case "$line" in
-               *\?\?*metadata/*.txt) new=true ;;
-               *M*metadata/*.txt) new=false ;;
-       esac
-
+       if [[ "$line" == *\?\?*metadata/*.txt ]]; then
+               new=true
+       elif [[ "$line" == *M*metadata/*.txt ]]; then
+               new=false
+       fi
        file=${line##* }
+
        id=${file##*/}
        id=${id%.txt*}
-
        if [ $# -gt 0 ]; then
                case "$@" in
                        *" $id "*) ;;  # Middle
@@ -55,10 +53,11 @@ while read line; do
 
        name= autoname=
        while read l; do
-               case "$l" in
-                       'Auto Name:'*) autoname=${l#*:} ;;
-                       'Name:'*) name=${l#*:} ;;
-               esac
+               if [[ "$l" == "Auto Name:"* ]]; then
+                       autoname=${l#*:}
+               elif [[ "$l" == "Name:"* ]]; then
+                       name=${l#*:}
+               fi
        done < "$file"
 
        if [ -n "$name" ]; then
@@ -75,26 +74,25 @@ while read line; do
                onlybuild=true
                newbuild=false
                disable=false
-
                while read l; do
-                       case "$l" in
-                               *"Maintainer Notes:"*) break ;;
-                               "-Build:"*) onlybuild=false ;;
-                               "+Build:"*)
-                                       $newbuild && onlybuild=false
-                                       newbuild=true
-                                       build=${l#*:}
-                                       version=${build%%,*}
-                                       build=${build#*,}
-                                       vercode=${build%%,*}
-                                       ;;
-                               '+'*"disable="*)
-                                       $newbuild && $onlybuild && disable=true
-                                       ;;
-                       esac
-               done << EOF
-               $(git diff HEAD -- "$file")
-EOF
+                       if [[ "$l" == *"Maintainer Notes:"* ]]; then
+                               break
+                       fi
+                       if [[ "$l" == "-Build:"* ]]; then
+                               onlybuild=false
+                       elif [[ "$l" == "+Build:"* ]]; then
+                               if $newbuild; then
+                                       onlybuild=false
+                               fi
+                               newbuild=true
+                               build=${l#*:}
+                               version=${build%%,*}
+                               build=${build#*,}
+                               vercode=${build%%,*}
+                       elif $newbuild && $onlybuild && [[ "$l" == "+"*"disable="* ]]; then
+                               disable=true
+                       fi
+               done < <(git diff HEAD -- "$file")
 
                if $newbuild && $onlybuild; then
                        if $disable; then
@@ -108,18 +106,13 @@ EOF
        fi
 
        message=${message//\"/\\\"}
-       commands="$commands%%git add -- $file $extra && git commit -m \"$message\" -e -v"
-
-done << EOF
-$(git status --porcelain metadata)
-EOF
+       commands+=("git add -- $file $extra && git commit -m \"$message\" -e -v")
+done < <(git status --porcelain metadata)
 
-[ -z "$commands" ] && exit 0
+[[ -z $commands ]] && exit 0
 
 git reset >/dev/null
-IFS='%%'
-for cmd in $commands; do
-       [ -z "$cmd" ] && continue
-       eval $cmd
+for cmd in "${commands[@]}"; do
+       eval "$cmd"
        git reset >/dev/null
 done