commit: 7a16e3ce17fe7298cd54f76be8bb0270b4233928
Author: Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Wed Jul 24 14:03:37 2024 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Thu May 29 10:01:54 2025 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=7a16e3ce
Eliminate all superfluous uses of has()
The has() function is a somewhat expensive one and is routinely being
used in situations where a conditional expression would perfectly
suffice. Where appropriate, refrain from using it.
See-also: 8640db01f2f2d1c37821c0a6d096ed67a8b734e2
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>
bin/ebuild-helpers/doman | 5 ++---
bin/ebuild.sh | 26 ++++++++++++++++++--------
bin/isolated-functions.sh | 6 +++---
bin/phase-functions.sh | 11 +++++------
bin/phase-helpers.sh | 5 ++---
5 files changed, 30 insertions(+), 23 deletions(-)
diff --git a/bin/ebuild-helpers/doman b/bin/ebuild-helpers/doman
index 67945f48bf..a7825b4705 100755
--- a/bin/ebuild-helpers/doman
+++ b/bin/ebuild-helpers/doman
@@ -30,14 +30,13 @@ for x in "$@" ; do
suffix=${x##*.}
# These will be automatically decompressed by ecompressdir.
- if has ${suffix} Z gz bz2 ; then
+ if [[ ${suffix} == @(Z|gz|bz2) ]]; then
eqawarn "QA Notice: doman argument '${x}' is compressed, this
is not portable"
realname=${x%.*}
suffix=${realname##*.}
fi
- if has "${EAPI:-0}" 2 3 || [[ -z ${i18n} ]] && ! has "${EAPI:-0}" 0 1 \
- && [[ ${x} =~ (.*)\.([a-z][a-z](_[A-Z][A-Z])?)\.(.*) ]]
+ if [[ ${EAPI} == [23] ]] || [[ -z ${i18n} ]] && [[ ${EAPI:-0} != [01]
]] && [[ ${x} =~ (.*)\.([a-z][a-z](_[A-Z][A-Z])?)\.(.*) ]]
then
name=${BASH_REMATCH[1]##*/}.${BASH_REMATCH[4]}
mandir=${BASH_REMATCH[2]}/man${suffix:0:1}
diff --git a/bin/ebuild.sh b/bin/ebuild.sh
index f2cc685b57..63fd0117d8 100755
--- a/bin/ebuild.sh
+++ b/bin/ebuild.sh
@@ -520,15 +520,24 @@ if [[ -n ${QA_INTERCEPTORS} ]] ; then
fi
${BODY}
}"
- elif has ${BIN} autoconf automake aclocal libtoolize ; then
+ elif [[ ${BIN} == @(autoconf|automake|aclocal|libtoolize) ]];
then
FUNC_SRC="${BIN}() {
- if ! has \${FUNCNAME[1]} eautoreconf eaclocal
_elibtoolize \\
- eautoheader eautoconf eautomake
autotools_run_tool \\
- autotools_check_macro
autotools_get_subdirs \\
- autotools_get_auxdir ; then
+ case \${FUNCNAME[1]} in
+ eautoreconf |\\
+ eaclocal |\\
+ _elibtoolize |\\
+ eautoheader |\\
+ eautoconf |\\
+ eautomake |\\
+ autotools_run_tool |\\
+ autotools_check_macro |\\
+ autotools_get_subdirs |\\
+ autotools_get_auxdir )
+ ;;
+ *)
eqawarn \"QA Notice: '${BIN}' called by
\${FUNCNAME[1]}: \${CATEGORY}/\${PF}\"
eqawarn \"Use autotools.eclass instead
of calling '${BIN}' directly.\"
- fi
+ esac
${BODY}
}"
else
@@ -546,7 +555,8 @@ fi
export EBUILD_MASTER_PID=${BASHPID:-$(__bashpid)}
trap 'exit 1' SIGTERM
-if ! has "${EBUILD_PHASE}" clean cleanrm depend && ! [[ ${EMERGE_FROM} =
ebuild && ${EBUILD_PHASE} = setup ]] && [[ -f "${T}"/environment ]]; then
+if [[ ${EBUILD_PHASE} != @(clean|cleanrm|depend) ]] && ! [[ ${EBUILD_PHASE} ==
setup && ${EMERGE_FROM} == ebuild ]] && [[ -f ${T}/environment ]]
+then
# The environment may have been extracted from environment.bz2 or
# may have come from another version of ebuild.sh or something.
# In any case, preprocess it to prevent any potential interference.
@@ -591,7 +601,7 @@ eval
"PORTAGE_ECLASS_LOCATIONS=(${PORTAGE_ECLASS_LOCATIONS})"
# Source the ebuild every time for FEATURES=noauto, so that ebuild
# modifications take effect immediately.
-if ! has "${EBUILD_PHASE}" clean cleanrm ; then
+if [[ ${EBUILD_PHASE} != clean?(rm) ]]; then
if [[ ${EBUILD_PHASE} = setup && ${EMERGE_FROM} = ebuild ]] || \
[[ ${EBUILD_PHASE} = depend || ! -f ${T}/environment || -f
${PORTAGE_BUILDDIR}/.ebuild_changed || " ${FEATURES} " == *" noauto "* ]] ; then
# The bashrcs get an opportunity here to set aliases that will
be expanded
diff --git a/bin/isolated-functions.sh b/bin/isolated-functions.sh
index 40d2132be1..389c5e5af3 100644
--- a/bin/isolated-functions.sh
+++ b/bin/isolated-functions.sh
@@ -173,7 +173,7 @@ die() {
# __dump_trace is useless when the main script is a helper binary
local main_index
(( main_index = ${#BASH_SOURCE[@]} - 1 ))
- if has ${BASH_SOURCE[${main_index}]##*/} ebuild.sh misc-functions.sh ;
then
+ if [[ ${BASH_SOURCE[main_index]##*/} == @(ebuild|misc-functions).sh ]];
then
__dump_trace 2 ${filespacing} ${linespacing}
eerror " $(printf "%${filespacing}s" "${BASH_SOURCE[1]##*/}"), line
$(printf "%${linespacing}s" "${BASH_LINENO[0]}"): Called die"
eerror "The specific snippet of code:"
@@ -207,8 +207,8 @@ die() {
# misc-functions.sh, since those are the only cases where the
environment
# contains the hook functions. When necessary (like for __helpers_die),
die
# hooks are automatically called later by a misc-functions.sh
invocation.
- if has ${BASH_SOURCE[${main_index}]##*/} ebuild.sh misc-functions.sh &&
\
- [[ ${EBUILD_PHASE} != depend ]] ; then
+ if [[ ${EBUILD_PHASE} != depend && ${BASH_SOURCE[main_index]##*/} ==
@(ebuild|misc-functions).sh ]]
+ then
local x
for x in ${EBUILD_DEATH_HOOKS}; do
${x} "$@" >&2 1>&2
diff --git a/bin/phase-functions.sh b/bin/phase-functions.sh
index c68f3c5fcf..fa824b99d5 100644
--- a/bin/phase-functions.sh
+++ b/bin/phase-functions.sh
@@ -929,7 +929,7 @@ __ebuild_phase_funcs() {
src_test() { default; }
# defaults starting with EAPI 4
- if ! has ${eapi} 2 3; then
+ if [[ ${eapi} != [23] ]]; then
[[ ${phase_func} == src_install ]] && \
default_src_install() {
__eapi4_src_install; }
@@ -938,7 +938,7 @@ __ebuild_phase_funcs() {
fi
# defaults starting with EAPI 6
- if ! has ${eapi} 2 3 4 5; then
+ if [[ ${eapi} != [2-5] ]]; then
[[ ${phase_func} == src_prepare ]] && \
default_src_prepare() {
__eapi6_src_prepare; }
[[ ${phase_func} == src_install ]] && \
@@ -949,7 +949,7 @@ __ebuild_phase_funcs() {
fi
# defaults starting with EAPI 8
- if ! has ${eapi} 2 3 4 5 6 7; then
+ if [[ ${eapi} != [2-7] ]]; then
[[ ${phase_func} == src_prepare ]] && \
default_src_prepare() {
__eapi8_src_prepare; }
fi
@@ -1014,8 +1014,7 @@ __ebuild_main() {
__ebuild_phase_with_hooks pkg_nofetch
;;
prerm|postrm|preinst|postinst|config|info)
- if has "${1}" config info && \
- ! declare -F "pkg_${1}" >/dev/null ; then
+ if [[ $1 == @(config|info) ]] && ! declare -F "pkg_${1}"
>/dev/null; then
ewarn "pkg_${1}() is not defined: '${EBUILD##*/}'"
fi
export SANDBOX_ON="0"
@@ -1120,7 +1119,7 @@ __ebuild_main() {
esac
# Save the env only for relevant phases.
- if ! has "${1}" clean help info nofetch ; then
+ if [[ $1 != @(clean|help|info|nofetch) ]]; then
umask 002
# Use safe cwd, avoiding unsafe import for bug #469338.
diff --git a/bin/phase-helpers.sh b/bin/phase-helpers.sh
index 16b5a4a1ca..a4bf8328d9 100644
--- a/bin/phase-helpers.sh
+++ b/bin/phase-helpers.sh
@@ -238,7 +238,7 @@ use() {
# any number of phase hooks, so that global scope eclass
# initialization can by migrated to phase hooks in new EAPIs.
# Example: add_phase_hook before pkg_setup
${ECLASS}_pre_pkg_setup
- #if [[ -n ${EAPI} ]] && ! has "${EAPI}" 0 1 2 3 ; then
+ #if [[ ${EAPI} && ${EAPI} != [0123] ]]; then
# die "use() called during invalid phase: ${EBUILD_PHASE}"
#fi
true
@@ -371,8 +371,7 @@ unpack() {
esac
if ___eapi_unpack_is_case_sensitive \
- && ! has "${suffix}" "${suffix_insensitive}" \
- ZIP Z 7Z RAR LHA LHa; then
+ && [[ ${suffix} !=
@("${suffix_insensitive}"|ZIP|Z|7Z|RAR|LH[Aa]) ]]; then
suffix_known=""
fi