[pacman-dev] [PATCH 09/10] makepkg: do not expand for loop variables twice

Andres P aepd87 at gmail.com
Fri Jun 25 19:16:44 EDT 2010


Here's how for loops work in bash and just about any language out there. If
$var expands to nothing, `for i in $var` does *not* iterate.

Taking this in mind, wrapping the whole loop in a "[[ -n $var ]]" conditional
is unnecesary, expands the variable twice, indents the whole block for no good
reason, and shows that there's no fluency.

Signed-off-by: Andres P <aepd87 at gmail.com>
---
 scripts/makepkg.sh.in |   29 ++++++++++++-----------------
 1 files changed, 12 insertions(+), 17 deletions(-)

diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index 50cdae7..59519a6 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -1253,24 +1253,19 @@ check_sanity() {
 		return 1
 	fi
 
-	local pkg
-	if (( ${#pkgname[@]} > 1 )); then
-		for pkg in ${pkgname[@]}; do
-			if ! declare -f package_${pkg} >/dev/null; then
-				error "$(gettext "missing package function for split package '%s'")" "$pkg"
-				return 1
-			fi
-		done
-	fi
+	for i in ${pkgname[@]}; do
+		if ! declare -f package_${i} >/dev/null; then
+			error "$(gettext "missing package function for split package '%s'")" "$i"
+			return 1
+		fi
+	done
 
-	if [[ -n "${PKGLIST[@]}" ]]; then
-		for pkg in ${PKGLIST[@]}; do
-			if ! in_array $pkg ${pkgname[@]}; then
-				error "$(gettext "requested package %s is not provided in %s")" "$pkg" "$BUILDFILE"
-				return 1
-			fi
-		done
-	fi
+	for i in ${PKGLIST[@]}; do
+		if ! in_array $i ${pkgname[@]}; then
+			error "$(gettext "requested package %s is not provided in %s")" "$i" "$BUILDFILE"
+			return 1
+		fi
+	done
 
 	return 0
 }
-- 
1.7.1



More information about the pacman-dev mailing list