From patchwork Sat Dec 26 07:27:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 1843 Return-Path: Delivered-To: patchwork@archlinux.org Received: from mail.archlinux.org [2a01:4f9:c010:3052::1] by patchwork.archlinux.org with IMAP (fetchmail-6.4.14) for (single-drop); Sat, 26 Dec 2020 07:30:41 +0000 (UTC) Received: from mail.archlinux.org by mail.archlinux.org with LMTP id gJuxFKHm5l/xFgMAK+/4rw (envelope-from ) for ; Sat, 26 Dec 2020 07:30:41 +0000 Received: from luna.archlinux.org (luna.archlinux.org [IPv6:2a01:4f8:160:3033::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits)) (No client certificate requested) by mail.archlinux.org (Postfix) with ESMTPS id 1DE7C32298D; Sat, 26 Dec 2020 07:30:41 +0000 (UTC) Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id BFA772C527; Sat, 26 Dec 2020 07:30:34 +0000 (UTC) Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 5914A2111A for ; Sat, 26 Dec 2020 07:27:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on luna.archlinux.org X-Spam-Level: X-Spam-Status: No, score=0.4 required=5.0 tests=DKIM_SIGNED=0.1, DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,FREEMAIL_FROM=0.5, RCVD_IN_DNSWL_NONE=-0.0001,SPF_HELO_NONE=0.001, T_DMARC_POLICY_NONE=0.01,T_DMARC_SIMPLE_DKIM=0.01 autolearn=no autolearn_force=no version=3.4.4 X-Spam-BL-Results: [127.0.0.10] [127.0.5.0] [127.0.0.10] Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by luna.archlinux.org (Postfix) with ESMTPS for ; Sat, 26 Dec 2020 07:27:42 +0000 (UTC) Received: by mail-pf1-x430.google.com with SMTP id d2so3516416pfq.5 for ; Fri, 25 Dec 2020 23:27:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=DFE3fZfWyX458OLx7moHD1FAEKUtGrSkBBAYFPVey5Y=; b=oMw9GFXMgeZtceDfx8Rbpmfh+tqAbwViy8SJVzQsu5mi3yo1vCMBCt/409nsqpePdo M50Zmmg2Nh3lWBK6nKFqfLyklVjZ1wuSxiwv8AbiU89cHFNTSDU97IOYdESggKrIWukw cSUsgw7/qwbCIVRfj3AGNOjR1pdF+n/o09E0K9aQjoMzmX4T16+k5UElCGOqqhvX8iSN 4e4qf3/zUfv25dvAioYGVRuU6hLXoOmDUViFR4glnNimIK9d+PzJLCyya8TLxNIernG2 6L5wJq87k/CFReJNxUYgF5mQIC5tA04Kuyf1q5FgE2A47SdQjkixA8inQ1iN15iWAXID lxnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DFE3fZfWyX458OLx7moHD1FAEKUtGrSkBBAYFPVey5Y=; b=VPuesln9HljDTpxBfHD7ofewGHJhAfqX3Noqz7LRQH6i3ekaf+06yx4QKCY3AfP/95 t/27lvj/fxycVrbin3s4pu/0b4koqXRIrowgPOThQdqY/IfD7kZXg5nNKP+uMRx2cbe6 1x4mOluLHkkuVFEEZw6lVVtSeZPXMGPyaLu3oslXbrin+0gcCdTZ2YplhFZhbP3ikKnl Merf4SVc9vWhAvgdxNN1UX0LoCmjlD2YWzuaN2UKkmgZy+MHsHDpEIZc9E3EmNq1EOQN is+BdjIDHiVSYFbWlwCLFDS6//tunb1xJ+UB2xYZ588fwlKYbSl4coCt+0JKzFjZVKyU l1IA== X-Gm-Message-State: AOAM533cEo57tyEivO1yQ2LN5yWnBKh87N45lFqpKr1hWvIgypUevqkF pwVs2pEJPsLex9jRNtCSCBJ9XKyhufs= X-Google-Smtp-Source: ABdhPJy1/SfJ06t+2B5FQzjxFPUJ0g69dhqPDOrURRP/vSIECNzMO3ZAwOlhyZndQFHEvcKILc5Jrg== X-Received: by 2002:a63:1e56:: with SMTP id p22mr11074473pgm.70.1608967660406; Fri, 25 Dec 2020 23:27:40 -0800 (PST) Received: from archbookpro.hsd1.ca.comcast.net (c-67-188-114-10.hsd1.ca.comcast.net. [67.188.114.10]) by smtp.gmail.com with ESMTPSA id q35sm7234652pjh.38.2020.12.25.23.27.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Dec 2020 23:27:39 -0800 (PST) From: Denton Liu To: pacman-contrib@lists.archlinux.org Subject: [PATCH 3/4] pacdiff: Reduce repetition in input loop Date: Fri, 25 Dec 2020 23:27:19 -0800 Message-Id: X-Mailer: git-send-email 2.29.2.889.g5298b911bd In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: pacman-contrib@lists.archlinux.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Discussion list for pacman-contrib development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: pacman-contrib-bounces@lists.archlinux.org Sender: "pacman-contrib" Authentication-Results: mail.archlinux.org; dkim=pass header.d=gmail.com header.s=20161025 header.b=oMw9GFXM; dmarc=pass (policy=none) header.from=gmail.com; spf=none (mail.archlinux.org: domain of pacman-contrib-bounces@lists.archlinux.org has no SPF policy when checking 2a01:4f8:160:3033::2) smtp.mailfrom=pacman-contrib-bounces@lists.archlinux.org X-Rspamd-Queue-Id: 1DE7C32298D X-Spamd-Result: default: False [2.99 / 15.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; FREEMAIL_FROM(0.00)[gmail.com]; R_MISSING_CHARSET(2.50)[]; TO_DN_NONE(0.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; DKIM_TRACE(0.00)[gmail.com:+]; DMARC_POLICY_ALLOW(-0.50)[gmail.com,none]; MAILLIST(-0.20)[mailman]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; RECEIVED_SPAMHAUS_PBL(0.00)[67.188.114.10:received]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:24940, ipnet:2a01:4f8::/29, country:DE]; MID_RHS_MATCH_FROM(0.00)[]; TAGGED_FROM(0.00)[]; ARC_NA(0.00)[]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20161025]; RCVD_COUNT_FIVE(0.00)[6]; FROM_HAS_DN(0.00)[]; FROM_NEQ_ENVFROM(0.00)[liudenton@gmail.com,pacman-contrib-bounces@lists.archlinux.org]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[pacman-contrib@lists.archlinux.org]; HAS_LIST_UNSUB(-0.01)[]; RCPT_COUNT_ONE(0.00)[1]; NEURAL_HAM(-0.00)[-1.000]; R_SPF_NA(0.00)[no SPF record]; FORGED_SENDER_MAILLIST(0.00)[] X-Rspamd-Server: mail.archlinux.org 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 --- 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