commit:     393449d07379893db6ba433c089aa76c66b65912
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Fri Jun 27 07:29:26 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sat Jun 28 02:30:22 2025 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=393449d0

phase-functions.sh: hoist locals to the top of __filter_readonly_variables()

Local variables are not lexically scoped in bash and it has been my
experience that declaring them up-front can help to identify undue
complexity. Do so for the __filter_readonly_variables() function.

Also, drop the 'x' variable, for the function makes no use of it.

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

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

diff --git a/bin/phase-functions.sh b/bin/phase-functions.sh
index b1bfa4a24e..ec1e1e03a8 100644
--- a/bin/phase-functions.sh
+++ b/bin/phase-functions.sh
@@ -86,19 +86,20 @@ PORTAGE_MUTABLE_FILTERED_VARS="AA HOSTNAME"
 # builtin command. To avoid this problem, this function filters those
 # variables out and discards them. See bug #190128.
 __filter_readonly_variables() {
-       local x filtered_vars
-       local readonly_bash_vars="BASHOPTS BASHPID DIRSTACK EUID
+       local 
{binpkg_untrusted,filtered_sandbox,readonly_bash,misc_garbage,bash_misc}_vars
+
+       readonly_bash_vars="BASHOPTS BASHPID DIRSTACK EUID
                FUNCNAME GROUPS PIPESTATUS PPID SHELLOPTS UID"
-       local bash_misc_vars="BASH BASH_.* COLUMNS COMP_WORDBREAKS HISTCMD
+       bash_misc_vars="BASH BASH_.* COLUMNS COMP_WORDBREAKS HISTCMD
                HISTFILE HOSTNAME HOSTTYPE IFS LINENO MACHTYPE OLDPWD
                OPTERR OPTIND OSTYPE POSIXLY_CORRECT PS4 PWD RANDOM
                SECONDS SHLVL _"
-       local filtered_sandbox_vars="SANDBOX_ACTIVE SANDBOX_BASHRC
+       filtered_sandbox_vars="SANDBOX_ACTIVE SANDBOX_BASHRC
                SANDBOX_DEBUG_LOG SANDBOX_DISABLED SANDBOX_LIB
                SANDBOX_LOG SANDBOX_ON"
        # Untrusted due to possible application of package renames to binpkgs
-       local binpkg_untrusted_vars="CATEGORY P PF PN PR PV PVR"
-       local misc_garbage_vars="_portage_filter_opts"
+       binpkg_untrusted_vars="CATEGORY P PF PN PR PV PVR"
+       misc_garbage_vars="_portage_filter_opts"
        filtered_vars="___.* ${readonly_bash_vars} ${bash_misc_vars}
                ${PORTAGE_READONLY_VARS} ${misc_garbage_vars}"
 

Reply via email to