From patchwork Thu Mar 4 11:55:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 1880 Return-Path: Delivered-To: patchwork@archlinux.org Received: from mail.archlinux.org [95.216.189.61] by patchwork.archlinux.org with IMAP (fetchmail-6.4.16) for (single-drop); Thu, 04 Mar 2021 11:56:05 +0000 (UTC) Received: from mail.archlinux.org by mail.archlinux.org with LMTP id 4In3OdPKQGCn8wgAK+/4rw (envelope-from ) for ; Thu, 04 Mar 2021 11:56:03 +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 7B1E244316E; Thu, 4 Mar 2021 11:56:03 +0000 (UTC) Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 2CD6E2D8BB; Thu, 4 Mar 2021 11:56:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=lists.archlinux.org; s=luna; t=1614858963; bh=lTzPENbnm9ovsmQPD69CZUsDh1SH+KEZxydOIDKkdvY=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc; b=bnY7zXZ8D+m7iluDDnOCDVBSyl9NCreLbKNEwHfsOpQOkMZK4UJbxHtXv+0v3bDA3 xriv+jrOrYKTQdNQMaKuxD4OzyEOB0R9j9ZTn5OrBu2QUvC4BP9xv3xmO0SsjN2iFf A+6QgCfr6YawK7yFvbwlfzROoN1TuRTYrbWWdsLOD/on5/dF53DGKVO2Djpm+sxVOO 3bKfrNp0LiZ9VdnNSyjn3aA/f/2Kot0tr6ORjy6tAxqhOlu1685HDt+xfrisfG1/5q 5uAbNa4fQTEcNp2ATXaskFJEPR0b+hXy91LiX3pEPUVOo+XQmB9HZ498+6et3ciGGF SKSt+EKJP7pwroilCeBawkfVec9R1LRXXmpiAfEnnEE+7YERteVGza2div/Hivs+Hp ln4617t283WTEzipvJD3YKKj00/1vQ4c1MJksThfy4ovqBnZAJDYWPWdUGq6royw38 AD1vayxLrarypb75sVnyOSSx3yHXi0FMlGiMdvmT1+ES+2oI3opNUgdnsRmjl/oYkn a8fZQVbkyomIV8Rile+Fo+76RqZx81wpe8DXRq5FZWQDbJOVwyP/xOlRa4KOdun+3t FPFN0NKEHXaiytykqvFRc/ebLDJ3sWtylqHgKGpGXbAvxE2ZVAghTLbXhVpX2xwfb4 hjUEzenF89mMSk3JNzsbl520= Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 6727A2D8A8 for ; Thu, 4 Mar 2021 11:55:59 +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.5.0] Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by luna.archlinux.org (Postfix) with ESMTPS for ; Thu, 4 Mar 2021 11:55:59 +0000 (UTC) Received: by mail-pl1-x635.google.com with SMTP id s16so16002012plr.9 for ; Thu, 04 Mar 2021 03:55:59 -0800 (PST) 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=xjNccaHXOVUqgp7e2LkY6cSgjAzl6MrmCtPAOpWLYqU=; b=hqwasHIHOprx4kLhPxWqYy9Xgv6ovwOG1zLz0mbDg3ijBX8rLxsxkM+eh7N2jj4K2A ku84aYqs5dCkwvMoAs6qHWuJCpwK2lWOXp9k2mBFPAJ6kDUx9D8mljqPJccg0JDOvvo0 WSSO0ihyRTmqPsv4J9xJ9MjC3m6T3N2xuH8jsdsHwcQcvkEIbPOlpKH7CZLfoWYrTtNm 1T2fhl3A3Di1jYKZF6OvGL5AgR9WxtExyOu0TJ6CkyhfNAJ1oI13/bsJ14Llxxlj5diE ykOKkJ6GM6ud2F5WGPYri0kOkoMrv1Y7FDVx0nngUxzSEiHDNTOLgNIdO5LtYvsKM98n UGYg== X-Gm-Message-State: AOAM5332RMzx5wqZGgph5Y2l5VrA7I59+1XMBOr1RU/PHcJ5SuSJyYtx Vl7XfeDfaZj6v97V7fI3z/XXhJw/MpE= X-Google-Smtp-Source: ABdhPJym2lz1CA9M7DtJZQ9Mtmya57A4r5KG6GzjUuV9lr30EHH66WrYI2i/ewpbJk/6RbmQsDfcDQ== X-Received: by 2002:a17:902:fe96:b029:e4:2f39:9083 with SMTP id x22-20020a170902fe96b02900e42f399083mr3665588plm.47.1614858957270; Thu, 04 Mar 2021 03:55:57 -0800 (PST) Received: from archbookpro.localdomain ([172.92.165.181]) by smtp.gmail.com with ESMTPSA id 188sm27620300pfz.119.2021.03.04.03.55.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Mar 2021 03:55:56 -0800 (PST) To: pacman-contrib@lists.archlinux.org Subject: [PATCH v2 2/3] pacdiff: Reduce repetition in input loop Date: Thu, 4 Mar 2021 03:55:46 -0800 Message-Id: <0a5381660a69293260dd94a85b20415e9901a6f8.1614858901.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.31.0.rc1.228.gb75b4e4ce2 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: , X-Patchwork-Original-From: Denton Liu via pacman-contrib From: Denton Liu Reply-To: Discussion list for pacman-contrib development Cc: Denton Liu Errors-To: pacman-contrib-bounces@lists.archlinux.org Sender: "pacman-contrib" Authentication-Results: mail.archlinux.org; dkim=pass header.d=lists.archlinux.org header.s=luna header.b=bnY7zXZ8; dmarc=pass (policy=none) header.from=archlinux.org; spf=pass (mail.archlinux.org: domain of pacman-contrib-bounces@lists.archlinux.org designates 2a01:4f8:160:3033::2 as permitted sender) smtp.mailfrom=pacman-contrib-bounces@lists.archlinux.org X-Rspamd-Queue-Id: 7B1E244316E X-Spamd-Result: default: False [2.79 / 15.00]; HAS_REPLYTO(0.00)[pacman-contrib@lists.archlinux.org]; RCVD_VIA_SMTP_AUTH(0.00)[]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(-0.20)[+ip6:2a01:4f8:160:3033::2:c]; R_MISSING_CHARSET(2.50)[]; REPLYTO_ADDR_EQ_FROM(0.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; DKIM_TRACE(0.00)[lists.archlinux.org:+]; RCPT_COUNT_TWO(0.00)[2]; DMARC_POLICY_ALLOW(-0.50)[archlinux.org,none]; MAILLIST(-0.20)[mailman]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:24940, ipnet:2a01:4f8::/29, country:DE]; FROM_NEQ_ENVFROM(0.00)[pacman-contrib@lists.archlinux.org,pacman-contrib-bounces@lists.archlinux.org]; ARC_NA(0.00)[]; R_DKIM_ALLOW(-0.20)[lists.archlinux.org:s=luna]; RCVD_COUNT_FIVE(0.00)[6]; FROM_HAS_DN(0.00)[]; TAGGED_RCPT(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[pacman-contrib@lists.archlinux.org]; MIME_GOOD(-0.10)[text/plain]; HAS_LIST_UNSUB(-0.01)[]; NEURAL_HAM(-0.00)[-1.000]; FREEMAIL_CC(0.00)[gmail.com]; 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