Support multiple arguments in set_unless_changed() and unset_unless_changed().
authorArfrever Frehtes Taifersar Arahesis <Arfrever@Gentoo.Org>
Sun, 1 May 2011 14:50:30 +0000 (16:50 +0200)
committerArfrever Frehtes Taifersar Arahesis <Arfrever@Gentoo.Org>
Sun, 1 May 2011 14:50:30 +0000 (16:50 +0200)
Use VARIABLE=VALUE syntax for arguments of set_unless_changed().

bin/ebuild.sh
man/portage.5

index e652cb55b81d21955351dcb4ebfa9d733f4ae73e..6593755cdc0666a1dabdb0119e3d0f9eac5e8339 100755 (executable)
@@ -1639,32 +1639,39 @@ _ebuild_phase_funcs() {
        esac
 }
 
-# Set given variable unless this variable has been already set (e.g. during emerge
-# invocation) to a value different than value set in make.conf.
+# Set given variables unless these variable have been already set (e.g. during emerge
+# invocation) to values different than values set in make.conf.
 set_unless_changed() {
-       if [[ $# -ne 2 ]]; then
-               die "${FUNCNAME}() requires 2 arguments: VARIABLE VALUE"
+       if [[ $# -lt 1 ]]; then
+               die "${FUNCNAME}() requires at least 1 argument: VARIABLE=VALUE"
        fi
 
-       local variable="$1" value="$2"
-
-       if eval "[[ \${${variable}} == \$(env -u ${variable} portageq envvar ${variable}) ]]"; then
-               eval "${variable}=\"${value}\""
-       fi
+       local argument value variable
+       for argument in "$@"; do
+               if [[ ${argument} != *=* ]]; then
+                       die "${FUNCNAME}(): Argument '${argument}' has incorrect syntax"
+               fi
+               variable="${argument%%=*}"
+               value="${argument#*=}"
+               if eval "[[ \${${variable}} == \$(env -u ${variable} portageq envvar ${variable}) ]]"; then
+                       eval "${variable}=\"${value}\""
+               fi
+       done
 }
 
-# Unset given variable unless this variable has been set (e.g. during emerge
-# invocation) to a value different than value set in make.conf.
+# Unset given variables unless these variable have been set (e.g. during emerge
+# invocation) to values different than values set in make.conf.
 unset_unless_changed() {
-       if [[ $# -ne 1 ]]; then
-               die "${FUNCNAME}() requires 1 argument: VARIABLE"
+       if [[ $# -lt 1 ]]; then
+               die "${FUNCNAME}() requires at least 1 argument: VARIABLE"
        fi
 
-       local variable="$1"
-
-       if eval "[[ \${${variable}} == \$(env -u ${variable} portageq envvar ${variable}) ]]"; then
-               unset ${variable}
-       fi
+       local variable
+       for variable in "$@"; do
+               if eval "[[ \${${variable}} == \$(env -u ${variable} portageq envvar ${variable}) ]]"; then
+                       unset ${variable}
+               fi
+       done
 }
 
 PORTAGE_BASHRCS_SOURCED=0
index a210e8d2dc685713cc347a969d914961ed3de39d..ece47e5a424154b93e24e899b3f3f82e59c98d59 100644 (file)
@@ -679,12 +679,12 @@ set_unless_changed and unset_unless_changed functions can be used to set or
 unset given variables only if these variable have not been set to values
 different than values set in make.conf. This functionality can be useful for
 temporary overriding of these variables during emerge invocation. Variables
-set in the usual VARIABLE=VALUE style will unconditionally override variables
+set without using set_unless_changed will unconditionally override variables
 set during emerge invocation.
 
 .I Syntax:
 .nf
-set_unless_changed VARIABLE VALUE
+set_unless_changed VARIABLE=VALUE
 unset_unless_changed VALUE
 .fi