[PATCH 3/4] pacdiff: Reduce repetition in input loop

Denton Liu liu.denton at gmail.com
Sat Dec 26 07:27:19 UTC 2020


The input loop repeats the `ask` code twice. In a future commit, we will
be introducing another instance of the `ask` code. This makes it
possible to mistakenly make the code to get out of sync.

Refactor the loop so that the `ask` code happens once at the top of the
loop. This introduces one functional change in the "Invalid answer" case
but it also makes it more consistent with the remaining cases.

Signed-off-by: Denton Liu <liu.denton at gmail.com>
---
 src/pacdiff.sh.in | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/src/pacdiff.sh.in b/src/pacdiff.sh.in
index 46a5adf..a50cb93 100644
--- a/src/pacdiff.sh.in
+++ b/src/pacdiff.sh.in
@@ -180,8 +180,9 @@ while IFS= read -u 3 -r -d '' pacfile; do
 		msg2 "Files are identical, removing..."
 		rm -v "$pacfile"
 	else
-		ask "(V)iew, (S)kip, (R)emove %s, (O)verwrite with %s, (Q)uit: [v/s/r/o/q] " "$file_type" "$file_type"
-		while read c; do
+		while :; do
+			ask "(V)iew, (S)kip, (R)emove %s, (O)verwrite with %s, (Q)uit: [v/s/r/o/q] " "$file_type" "$file_type"
+			read c || break
 			case $c in
 				q|Q) exit 0;;
 				r|R) rm -v "$pacfile"; break ;;
@@ -192,11 +193,9 @@ while IFS= read -u 3 -r -d '' pacfile; do
 						msg2 "Files are identical, removing..."
 						rm -v "$pacfile"
 						break
-					fi
-					ask "(V)iew, (S)kip, (R)emove %s, (O)verwrite with %s, (Q)uit: [v/s/r/o/q] " "$file_type" "$file_type";
-					continue ;;
+					fi ;;
 				s|S) break ;;
-				*) ask "Invalid answer. Try again: [v/s/r/o/q] "; continue ;;
+				*) msg2 "Invalid answer." ;;
 			esac
 		done
 	fi
-- 
2.29.2.889.g5298b911bd


More information about the pacman-contrib mailing list