commit:     393b8445925585a5ce192f9fde89720e8b37055a
Author:     Ulrich Müller <ulm <AT> gentoo <DOT> org>
AuthorDate: Thu Sep 21 07:34:19 2017 +0000
Commit:     Ulrich Müller <ulm <AT> gentoo <DOT> org>
CommitDate: Thu Sep 21 07:37:14 2017 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=393b8445

eapi7-ver.eclass: Simplify version validation.

This also speeds ver_test up by about 20%.

 eclass/eapi7-ver.eclass | 82 +++----------------------------------------------
 1 file changed, 4 insertions(+), 78 deletions(-)

diff --git a/eclass/eapi7-ver.eclass b/eclass/eapi7-ver.eclass
index e0eede869d4..7cfbf7e88d2 100644
--- a/eclass/eapi7-ver.eclass
+++ b/eclass/eapi7-ver.eclass
@@ -176,81 +176,6 @@ ver_rs() {
        echo "${comp[*]}"
 }
 
-# @FUNCTION: _ver_validate
-# @USAGE: <comp[0]>...
-# @DESCRIPTION:
-# Verify that the version component array passed as the argument
-# validates according to the PMS version rules. Returns 0 if it does,
-# 1 otherwise.
-_ver_validate() {
-       local prev=start
-
-       while [[ ${1} || ${2} ]]; do
-               local s=${1}
-               local c=${2}
-
-               if [[ -z ${s} ]]; then
-                       if [[ ${c} == [0-9]* ]]; then
-                               # number without preceding sep may be either:
-                               case ${prev} in
-                                       # a. 1st version number
-                                       start) prev=numeric;;
-                                       # b. _foo suffix number
-                                       suffix) prev=suffix_num;;
-                                       # c. -rN revision number
-                                       revision) prev=revision_num;;
-                                       *) return 1;;
-                               esac
-                       elif [[ -n ${c} ]]; then
-                               # letter without preceding sep = letter after 
version
-                               [[ ${prev} == numeric ]] || return 1
-                               [[ ${#c} -eq 1 ]] || return 1
-                               prev=letter
-                       fi
-               elif [[ -z ${c} ]]; then
-                       # trailing suffix?
-                       return 1
-               elif [[ ${s} == . ]]; then
-                       # number preceded by dot = numeric component
-                       [[ ${prev} == numeric ]] || return 1
-               elif [[ ${s} == _ ]]; then
-                       # _ implies _foo suffix
-                       case ${prev} in
-                               numeric|letter|suffix|suffix_num) ;;
-                               *) return 1;;
-                       esac
-
-                       case ${c} in
-                               alpha) ;;
-                               beta) ;;
-                               rc) ;;
-                               pre) ;;
-                               p) ;;
-                               *) return 1;;
-                       esac
-                       prev=suffix
-               elif [[ ${s} == - ]]; then
-                       # - implies revision
-                       case ${prev} in
-                               numeric|letter|suffix|suffix_num) ;;
-                               *) return 1;;
-                       esac
-
-                       [[ ${c} == r ]] || return 1
-                       prev=revision
-               else
-                       return 1
-               fi
-
-               shift 2
-       done
-
-       # empty version string?
-       [[ ${prev} != start ]] || return 1
-
-       return 0
-}
-
 # @FUNCTION: ver_test
 # @USAGE: [<v1>] <op> <v2>
 # @DESCRIPTION:
@@ -280,6 +205,10 @@ ver_test() {
                *) die "${FUNCNAME}: invalid operator: ${op}" ;;
        esac
 
+       local 
re="^[0-9]+(\.[0-9]+)*[a-z]?((_alpha|_beta|_pre|_rc|_p)[0-9]*)*(-r[0-9]+)?$"
+       [[ ${va} =~ ${re} ]] || die "${FUNCNAME}: invalid version: ${va}"
+       [[ ${vb} =~ ${re} ]] || die "${FUNCNAME}: invalid version: ${vb}"
+
        # explicitly strip -r0[00000...] to avoid overcomplexifying the algo
        [[ ${va} == *-r0* && 10#${va#*-r} -eq 0 ]] && va=${va%-r*}
        [[ ${vb} == *-r0* && 10#${vb#*-r} -eq 0 ]] && vb=${vb%-r*}
@@ -289,9 +218,6 @@ ver_test() {
        compb=( "${comp[@]}" )
        _ver_split "${va}"
 
-       _ver_validate "${comp[@]}" || die "${FUNCNAME}: invalid version: ${va}"
-       _ver_validate "${compb[@]}" || die "${FUNCNAME}: invalid version: ${vb}"
-
        local i sa sb ca cb wa wb result=0
        for (( i = 0;; i += 2 )); do
                sa=${comp[i]}

Reply via email to