[pacman-dev] [PATCH 2/4] makepkg: inline creation of checksum indenting

Dave Reisner dreisner at archlinux.org
Tue Sep 3 23:19:06 EDT 2013


With some simple math and printf formatting tokens, we can create the
whitespace necessary for this without the need for a loop and string
concatentation.

Signed-off-by: Dave Reisner <dreisner at archlinux.org>
---
 scripts/makepkg.sh.in | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index 5a74b3e..2239913 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -1149,12 +1149,6 @@ generate_checksums() {
 		local numsrc=${#source[@]}
 		printf "%s" "${integ}sums=("
 
-		local i
-		local indent=''
-		for (( i = 0; i < ${#integ} + 6; i++ )); do
-			indent="$indent "
-		done
-
 		local netfile
 		for netfile in "${source[@]}"; do
 			local proto sum
@@ -1176,10 +1170,11 @@ generate_checksums() {
 					;;
 			esac
 
-			(( ct )) && printf "%s" "$indent"
-			printf "%s" "'$sum'"
-			ct=$(($ct+1))
-			(( $ct < $numsrc )) && echo
+			# indent checksum on lines after the first
+			printf "%*s%s" $(( ct ? ${#integ} + 6 : 0 )) '' "'$sum'"
+
+			# print a newline on lines before the last
+			(( ++ct < numsrc )) && echo
 		done
 
 		echo ")"
-- 
1.8.4



More information about the pacman-dev mailing list