From: "Ulrich Müller" <ulm@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] repo/gentoo:eapi7-ver commit in: eclass/
Date: Thu, 21 Sep 2017 07:38:35 +0000 (UTC) [thread overview]
Message-ID: <1505979434.393b8445925585a5ce192f9fde89720e8b37055a.ulm@gentoo> (raw)
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]}
next reply other threads:[~2017-09-21 7:38 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-21 7:38 Ulrich Müller [this message]
-- strict thread matches above, loose matches on Subject: below --
2017-09-23 5:46 [gentoo-commits] repo/gentoo:eapi7-ver commit in: eclass/ Ulrich Müller
2017-09-22 21:28 Ulrich Müller
2017-09-22 16:10 Ulrich Müller
2017-09-21 14:04 Michał Górny
2017-09-21 14:04 Michał Górny
2017-09-21 13:26 Ulrich Müller
2017-09-21 12:57 Ulrich Müller
2017-09-21 7:04 Michał Górny
2017-09-20 21:19 Ulrich Müller
2017-09-12 16:37 Ulrich Müller
2017-09-12 16:37 Ulrich Müller
2017-09-08 11:11 Michał Górny
2017-09-08 11:11 Michał Górny
2017-09-06 15:31 Michał Górny
2017-09-06 15:22 Michał Górny
2017-09-06 13:45 Michał Górny
2017-09-06 13:45 Michał Górny
2017-09-06 13:40 Michał Górny
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1505979434.393b8445925585a5ce192f9fde89720e8b37055a.ulm@gentoo \
--to=ulm@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox