From patchwork Sun Apr 2 08:10:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Shumaker X-Patchwork-Id: 86 Return-Path: Delivered-To: patchwork@archlinux.org Received: from nymeria.archlinux.org by nymeria.archlinux.org (Dovecot) with LMTP id qepvAgmy4FgnUAAAtiB/HQ for ; Sun, 02 Apr 2017 10:10:49 +0200 Received: from nymeria.archlinux.org (localhost.localdomain [127.0.0.1]) by nymeria.archlinux.org (Postfix) with ESMTP id 1A38040662; Sun, 2 Apr 2017 10:10:47 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on nymeria.archlinux.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.5 tests=BAYES_00,RCVD_IN_DNSWL_MED shortcircuit=no autolearn=unavailable autolearn_force=no version=3.4.1 Received: from luna.archlinux.org (luna.archlinux.org [IPv6:2a01:4f8:160:3033::2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by nymeria.archlinux.org (Postfix) with ESMTPS; Sun, 2 Apr 2017 10:10:46 +0200 (CEST) Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 435852C0B5; Sun, 2 Apr 2017 08:10:25 +0000 (UTC) Authentication-Results: luna.archlinux.org; dkim=none Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 64E662C08B for ; Sun, 2 Apr 2017 08:10:23 +0000 (UTC) Received: from mav.lukeshu.com (team4272.com [IPv6:2001:19f0:5c00:8069:5400:ff:fe26:6a86]) by luna.archlinux.org (Postfix) with ESMTPS for ; Sun, 2 Apr 2017 08:10:23 +0000 (UTC) Received: from build64-par (unknown [IPv6:2601:803:202:9275:21f:e2ff:fe4d:191b]) by mav.lukeshu.com (Postfix) with ESMTPSA id D961A83EC0; Sun, 2 Apr 2017 04:10:19 -0400 (EDT) From: lukeshu@lukeshu.com To: arch-projects@lists.archlinux.org Date: Sun, 2 Apr 2017 04:10:02 -0400 Message-Id: <20170402081002.28176-9-lukeshu@lukeshu.com> X-Mailer: git-send-email 2.12.1 In-Reply-To: <20170402081002.28176-1-lukeshu@lukeshu.com> References: <20170402081002.28176-1-lukeshu@lukeshu.com> Subject: [arch-projects] [devtools] [PATCH 8/8] lib/common.sh: Make it safe to include multiple times. X-BeenThere: arch-projects@archlinux.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Arch Linux projects development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Arch Linux projects development discussion Cc: Luke Shumaker Errors-To: arch-projects-bounces@archlinux.org Sender: "arch-projects" X-UID: 217 Status: X-Keywords: Content-Length: 849 From: Luke Shumaker This is similar to common C #ifdef guards. I was tempted to wrap the entire thing in the if/fi, rather than use 'return' to bail early. However, that means it won't execute anything until after it reaches 'fi'. And if `shopt -s extglob` isn't executed before parsing, then it will syntax-error on the extended globs. One solution would have been to move `shopt -s extglob` up above the include-guard. But the committed solution is all-around simpler. --- lib/common.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/common.sh b/lib/common.sh index 4536668..c9afc36 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -3,6 +3,9 @@ # License: Unspecified +[[ -z ${_INCLUDE_COMMON_SH:-} ]] || return 0 +_INCLUDE_COMMON_SH=true + # Avoid any encoding problems export LANG=C