commit:     8dd01b6820e62f84f1703370ccd146d83b917347
Author:     Ulrich Müller <ulm <AT> gentoo <DOT> org>
AuthorDate: Wed Sep 20 21:18:24 2017 +0000
Commit:     Ulrich Müller <ulm <AT> gentoo <DOT> org>
CommitDate: Wed Sep 20 21:18:24 2017 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=8dd01b68

eapi7-ver.eclass: Get rid of versions array.

 eclass/eapi7-ver.eclass | 42 +++++++++++++++++++++---------------------
 1 file changed, 21 insertions(+), 21 deletions(-)

diff --git a/eclass/eapi7-ver.eclass b/eclass/eapi7-ver.eclass
index 83777a1f129..53563e326e5 100644
--- a/eclass/eapi7-ver.eclass
+++ b/eclass/eapi7-ver.eclass
@@ -185,8 +185,8 @@ ver_rs() {
 # revision parts), and the comparison is performed according to
 # the algorithm specified in the PMS.
 ver_test() {
-       local op result cur tail i j
-       local -a v vcomp
+       local v1 v2 op i tail result
+       local -a v1comp v2comp
        local match=(
                "+([0-9])*(.+([0-9]))"                                          
# numeric components
                "[a-z]"                                                         
                # letter component
@@ -198,14 +198,14 @@ ver_test() {
        shopt -s extglob
 
        if [[ $# -eq 2 ]]; then
-               v=("${PVR}" "$2")
-               op=$1
+               v1=${PVR}
        elif [[ $# -eq 3 ]]; then
-               v=("$1" "$3")
-               op=$2
+               v1=$1; shift
        else
                die "${FUNCNAME}: bad number of arguments"
        fi
+       op=$1
+       v2=$2
 
        case ${op} in
                -eq|-ne|-lt|-le|-gt|-ge) ;;
@@ -213,18 +213,18 @@ ver_test() {
        esac
 
        # Test for both versions being valid, and split them into parts
-       for (( i=0; i<2; i++ )); do
-               cur=${v[i]}
-               for (( j=0; j<4; j++ )); do
-                       tail=${cur##${match[j]}}
-                       vcomp[i*4+j]=${cur%"${tail}"}
-                       cur=${tail}
-               done
-               # There must not be any remaining tail, and the numeric part
-               # must be non-empty.  All other parts are optional.
-               [[ -z ${cur} ]] || die "${FUNCNAME}: could not parse version: 
${v[i]}"
-               [[ -n ${vcomp[i*4]} ]] || die "${FUNCNAME}: invalid version: 
${v[i]}"
+       for (( i=0; i<4; i++ )); do
+               tail=${v1##${match[i]}}
+               v1comp[i]=${v1%"${tail}"}
+               v1=${tail}
+               tail=${v2##${match[i]}}
+               v2comp[i]=${v2%"${tail}"}
+               v2=${tail}
        done
+       # There must not be any remaining tail, and the numeric part
+       # must be non-empty.  All other parts are optional.
+       [[ -z ${v1} && -z ${v2} && -n ${v1comp[0]} && -n ${v2comp[0]} ]] \
+               || die "${FUNCNAME}: invalid version"
 
        # Compare numeric components (PMS algorithm 3.2)
        _ver_cmp_num() {
@@ -293,10 +293,10 @@ ver_test() {
        }
 
        # Version comparison top-level logic (PMS algorithm 3.1)
-       _ver_cmp_num "${vcomp[0]}" "${vcomp[4]}" &&
-       _ver_cmp_let "${vcomp[1]}" "${vcomp[5]}" &&
-       _ver_cmp_suf "${vcomp[2]}" "${vcomp[6]}" &&
-       _ver_cmp_rev "${vcomp[3]}" "${vcomp[7]}"
+       _ver_cmp_num "${v1comp[0]}" "${v2comp[0]}" &&
+       _ver_cmp_let "${v1comp[1]}" "${v2comp[1]}" &&
+       _ver_cmp_suf "${v1comp[2]}" "${v2comp[2]}" &&
+       _ver_cmp_rev "${v1comp[3]}" "${v2comp[3]}"
 
        case $? in
                0) result=0  ;;                 # a = b

Reply via email to