commit:     d79d6606f375989cd40379a8e88c660ca68a1820
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Tue May 27 23:39:40 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri May 30 08:14:26 2025 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=d79d6606

phase-helpers.sh: refine the implementation of use()

Refrain from assigning a value to IFS in the course of localising it. To
localise IFS without assignment incurs the behaviour associated with IFS
being unset, which is wholly adequate.

Jettison the 'prev_shopts' and 'ret' variables. Instead, localise the -
parameter. Such is acceptable, given a target of >=bash-4.4.

Employ pattern matching to determine whether the flag begins with "!".

Rename the 'found' variable to 'invert'.

Use declare -F to probe for the existence of the ___in_portage_iuse
function so that no time is wasted printing out the entirety of the
function's body to /dev/null.

Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>

 bin/phase-helpers.sh | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)

diff --git a/bin/phase-helpers.sh b/bin/phase-helpers.sh
index 4c76d385ed..baf0f697ea 100644
--- a/bin/phase-helpers.sh
+++ b/bin/phase-helpers.sh
@@ -233,13 +233,12 @@ if ___eapi_has_usex; then
 fi
 
 use() {
-       local u=$1
-       local found=0
+       local - IFS invert u=$1
 
        # If we got something like '!flag', then invert the return value
-       if [[ ${u:0:1} == "!" ]] ; then
+       if [[ ${u} == !* ]] ; then
                u=${u:1}
-               found=1
+               invert=1
        fi
 
        if [[ ${EBUILD_PHASE} = depend ]] ; then
@@ -255,7 +254,7 @@ use() {
        # Make sure we have this USE flag in IUSE, but exempt binary
        # packages for API consumers like Entropy which do not require
        # a full profile with IUSE_IMPLICIT and stuff (see bug #456830).
-       elif declare -f ___in_portage_iuse >/dev/null &&
+       elif declare -F ___in_portage_iuse >/dev/null &&
                [[ -n ${EBUILD_PHASE} && -n ${PORTAGE_INTERNAL_CALLER} ]] ; then
                if ! ___in_portage_iuse "${u}"; then
                        if [[ ${EMERGE_FROM} != binary &&
@@ -270,15 +269,9 @@ use() {
                fi
        fi
 
-       local IFS=$' \t\n' prev_shopts=$- ret
        set -f
-       if has ${u} ${USE} ; then
-               ret=${found}
-       else
-               ret=$((!found))
-       fi
-       [[ ${prev_shopts} == *f* ]] || set +f
-       return ${ret}
+       has ${u} ${USE}
+       (( $? == invert ? 1 : 0 ))
 }
 
 use_with() {

Reply via email to