commit:     d631e3e833aca4f35e86029dc564743c3e3aed0f
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Sun Jul 20 07:48:28 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Tue Jul 22 22:30:57 2025 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=d631e3e8

isolated-functions.sh: render the control flow of __repo_attr() clear

Presently, the way in which the __repo_attr() function is written
renders its control flow obscure. Address this issue by employing a
nicely structured if command and treating the 'appropriate_section'
variable as a quasi-boolean that is evaluated in the arithmetic context.

Further, remove a comment pointing out that bash-3.2 may not handle
extended globs in conditional expressions, if presented in their raw
form. While such is true of 3.2 - and all versions of bash prior to 4.1
- it is irrelevant at this juncture.

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

 bin/isolated-functions.sh | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/bin/isolated-functions.sh b/bin/isolated-functions.sh
index 55053f5d32..d429e83feb 100644
--- a/bin/isolated-functions.sh
+++ b/bin/isolated-functions.sh
@@ -540,21 +540,21 @@ has() {
 }
 
 __repo_attr() {
-       local appropriate_section=0 exit_status=1 line 
saved_extglob_shopt=$(shopt -p extglob)
+       local appropriate_section exit_status=1 line 
saved_extglob_shopt=$(shopt -p extglob)
        shopt -s extglob
+
        while read -r line; do
-               [[ ${appropriate_section} == 0 && ${line} == "[$1]" ]] && 
appropriate_section=1 && continue
-               [[ ${appropriate_section} == 1 && ${line} == "["*"]" ]] && 
appropriate_section=0 && continue
-               # If a conditional expression like [[ ${line} == $2*( )=* ]] is 
used
-               # then bash-3.2 produces an error like the following when the 
file is
-               # sourced: syntax error in conditional expression: unexpected 
token `('
-               # Therefore, use a regular expression for compatibility.
-               if [[ ${appropriate_section} == 1 && ${line} =~ 
^${2}[[:space:]]*= ]]; then
+               if (( ! appropriate_section )) && [[ ${line} == "[$1]" ]]; then
+                       appropriate_section=1
+               elif (( appropriate_section )) && [[ ${line} == "["*"]" ]]; then
+                       appropriate_section=0
+               elif (( appropriate_section )) && [[ ${line} =~ 
^${2}[[:space:]]*= ]]; then
                        echo "${line##$2*( )=*( )}"
                        exit_status=0
                        break
                fi
        done <<< "${PORTAGE_REPOSITORIES}"
+
        eval "${saved_extglob_shopt}"
        return ${exit_status}
 }

Reply via email to