public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] [PATCH] eapi7-ver.eclass: 'Early adopter' version of EAPI 7 version manip
@ 2017-09-08 11:19 Michał Górny
  2017-09-08 12:48 ` [gentoo-dev] " Martin Vaeth
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Michał Górny @ 2017-09-08 11:19 UTC (permalink / raw
  To: gentoo-dev; +Cc: Michał Górny

EAPI 7 is introducing new version manipulation and comparison functions
that aim to replace versionator.eclass. This eclass provides an 'early
adopter' versions of those routines.

It serves two goals:

a. getting wider review and some real-life testing before
the specification is set in stone, and

b. making it possible to adapt ebuilds to the new routines early,
reducing the future work of EAPI 7 porting.

For more details on the new logic, please see the eclass documentation.
Long story short, we are introducing three functions:

1. ver_cut -- to get substrings of the version string,

2. ver_rs -- to replace version separators via indices,

3. ver_test -- to compare two version numbers.

The third function is not implemented in the eclass. It's meant to reuse
the algorithms from the package manager, and the final implementation
will most likely reuse the code from the package manager (e.g. via IPC).
---
 eclass/eapi7-ver.eclass             | 181 ++++++++++++++++++++++++++++++++++++
 eclass/tests/eapi7-ver.sh           |  65 +++++++++++++
 eclass/tests/eapi7-ver:benchmark.sh |  76 +++++++++++++++
 3 files changed, 322 insertions(+)
 create mode 100644 eclass/eapi7-ver.eclass
 create mode 100755 eclass/tests/eapi7-ver.sh
 create mode 100755 eclass/tests/eapi7-ver:benchmark.sh

diff --git a/eclass/eapi7-ver.eclass b/eclass/eapi7-ver.eclass
new file mode 100644
index 000000000000..c82da6192c94
--- /dev/null
+++ b/eclass/eapi7-ver.eclass
@@ -0,0 +1,181 @@
+# Copyright 1999-2017 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: eapi7-ver.eclass
+# @MAINTAINER:
+# PMS team <pms@gentoo.org>
+# @AUTHOR:
+# Ulrich Müller <ulm@gentoo.org>
+# Michał Górny <mgorny@gentoo.org>
+# @BLURB: Testing implementation of EAPI 7 version manipulators
+# @DESCRIPTION:
+# A stand-alone implementation of the version manipulation functions
+# aimed for EAPI 7. Intended to be used for wider testing of
+# the proposed functions and to allow ebuilds to switch to the new
+# model early, with minimal change needed for actual EAPI 7.
+#
+# https://bugs.gentoo.org/482170
+#
+# Note: version comparison function is not included currently.
+#
+# Version strings
+# ===============
+# The functions support arbitrary version strings consisting of version
+# components interspersed with (possibly empty) version separators.
+#
+# A version component can either consist purely of digits ([0-9]+) or
+# purely of uppercase and lowercase letters ([a-zA-Z]+). Any other
+# character is treated as a version separator.
+#
+# The version is processed left-to-right, and each successive component
+# is assigned numbers starting with 1. The components are either split
+# on version separators or on boundaries between digits and letters
+# (in which case the separator between the components is empty).
+# Version separators are assigned numbers starting with 1 for
+# the separator between 1st and 2nd components. As a special case,
+# if the version string starts with a separator, it is assigned index 0.
+#
+# Examples:
+#
+#   1.2b-alpha4 -> 1 . 2 '' b - alpha '' 4
+#                  c s c s  c s c     s  c
+#                  1 1 2 2  3 3 4     4  5
+#
+#   .11.        -> . 11 .
+#                  s c  s
+#                  0 1  1
+#
+# Ranges
+# ======
+# A range can be specified as 'm' for m-th version component, 'm-'
+# for all components starting with m-th or 'm-n' for components starting
+# at m-th and ending at n-th (inclusive). If the range spans outside
+# the version string, it is truncated silently.
+
+case ${EAPI:-0} in
+	0|1|2|3|4|5)
+		die "${ECLASS}: EAPI=${EAPI:-0} not supported";;
+	6)
+		;;
+	*)
+		die "${ECLASS}: EAPI=${EAPI} unknown";;
+esac
+
+# @FUNCTION: _ver_parse_range
+# @INTERNAL
+# @USAGE: <range> <max>
+# @DESCRIPTION:
+# Parse the range string <range>, setting 'start' and 'end' variables
+# to the appropriate bounds. <min> and <max> specify the appropriate
+# lower and upper bound for the range; the user-specified value is
+# truncated to this range.
+_ver_parse_range() {
+	local range=${1}
+	local max=${2}
+
+	[[ ${range} == [0-9]* ]] || die "${FUNCNAME}: range must start with a number"
+	start=${range%-*}
+	[[ ${range} == *-* ]] && end=${range#*-} || end=${start}
+	if [[ ${end} ]]; then
+		[[ ${start} -le ${end} ]] || die "${FUNCNAME}: end of range must be >= start"
+		[[ ${end} -le ${max} ]] || end=${max}
+	else
+		end=${max}
+	fi
+}
+
+# @FUNCTION: _ver_split
+# @INTERNAL
+# @USAGE: <version>
+# @DESCRIPTION:
+# Split the version string <version> into separator-component array.
+# Sets 'comp' to an array of the form: ( s_0 c_1 s_1 c_2 s_2 c_3... )
+# where s_i are separators and c_i are components.
+_ver_split() {
+	local v=${1} LC_ALL=C
+
+	comp=()
+
+	# get separators and components
+	local s c
+	while [[ ${v} ]]; do
+		# cut the separator
+		s=${v%%[a-zA-Z0-9]*}
+		v=${v:${#s}}
+		# cut the next component; it can be either digits or letters
+		[[ ${v} == [0-9]* ]] && c=${v%%[^0-9]*} || c=${v%%[^a-zA-Z]*}
+		v=${v:${#c}}
+
+		comp+=( "${s}" "${c}" )
+	done
+}
+
+# @FUNCTION: ver_cut
+# @USAGE: <range> [<version>]
+# @DESCRIPTION:
+# Print the substring of the version string containing components
+# defined by the <range> and the version separators between them.
+# Processes <version> if specified, ${PV} otherwise.
+#
+# For the syntax of versions and ranges, please see the eclass
+# description.
+ver_cut() {
+	local range=${1}
+	local v=${2:-${PV}}
+	local start end
+	local -a comp
+
+	_ver_split "${v}"
+	local max=$((${#comp[@]}/2))
+	_ver_parse_range "${range}" "${max}"
+
+	local IFS=
+	if [[ ${start} -gt 0 ]]; then
+		start=$(( start*2 - 1 ))
+	fi
+	echo "${comp[*]:start:end*2-start}"
+}
+
+# @FUNCTION: ver_rs
+# @USAGE: <range> <repl> [<range> <repl>...] [<version>]
+# @DESCRIPTION:
+# Print the version string after substituting the specified version
+# separators at <range> with <repl> (string). Multiple '<range> <repl>'
+# pairs can be specified. Processes <version> if specified,
+# ${PV} otherwise.
+#
+# For the syntax of versions and ranges, please see the eclass
+# description.
+ver_rs() {
+	local v
+	(( ${#} & 1 )) && v=${@: -1} || v=${PV}
+	local start end i
+	local -a comp
+
+	_ver_split "${v}"
+	local max=$((${#comp[@]}/2 - 1))
+
+	while [[ ${#} -ge 2 ]]; do
+		_ver_parse_range "${1}" "${max}"
+		for (( i = start*2; i <= end*2; i+=2 )); do
+			[[ ${i} -eq 0 && -z ${comp[i]} ]] && continue
+			comp[i]=${2}
+		done
+		shift 2
+	done
+
+	local IFS=
+	echo "${comp[*]}"
+}
+
+# @FUNCTION: ver_test
+# @USAGE: [<v1>] <op> <v2>
+# @DESCRIPTION:
+# Check if the relation <v1> <op> <v2> is true. If <v1> is not specified,
+# default to ${PVR}. <op> can be -gt, -ge, -eq, -ne, -le, -lt.
+# Both versions must conform to the PMS version syntax (with optional
+# revision parts), and the comparison is performed according to
+# the algorithm specified in the PMS.
+ver_test() {
+	die "${FUNCNAME}: not implemented"
+}
diff --git a/eclass/tests/eapi7-ver.sh b/eclass/tests/eapi7-ver.sh
new file mode 100755
index 000000000000..8a96e4d29b1b
--- /dev/null
+++ b/eclass/tests/eapi7-ver.sh
@@ -0,0 +1,65 @@
+#!/bin/bash
+# Copyright 1999-2017 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=6
+
+source tests-common.sh
+
+inherit eapi7-ver
+
+teq() {
+	local expected=${1}; shift
+
+	tbegin "${*} -> ${expected}"
+	local got=$("${@}")
+	[[ ${got} == ${expected} ]]
+	tend ${?} "returned: ${got}"
+}
+
+txf() {
+	tbegin "XFAIL: ${*}"
+	local got=$("${@}" 2>&1)
+	[[ ${got} == die:* ]]
+	tend ${?} "function did not die"
+}
+
+teq 1 ver_cut 1 1.2.3
+teq 1 ver_cut 1-1 1.2.3
+teq 1.2 ver_cut 1-2 1.2.3
+teq 2.3 ver_cut 2- 1.2.3
+teq 1.2.3 ver_cut 1- 1.2.3
+teq 3b ver_cut 3-4 1.2.3b_alpha4
+teq alpha ver_cut 5 1.2.3b_alpha4
+teq 1.2 ver_cut 1-2 .1.2.3
+teq .1.2 ver_cut 0-2 .1.2.3
+teq 2.3 ver_cut 2-3 1.2.3.
+teq 2.3. ver_cut 2- 1.2.3.
+teq 2.3. ver_cut 2-4 1.2.3.
+
+teq 1-2.3 ver_rs 1 - 1.2.3
+teq 1.2-3 ver_rs 2 - 1.2.3
+teq 1-2-3.4 ver_rs 1-2 - 1.2.3.4
+teq 1.2-3-4 ver_rs 2- - 1.2.3.4
+teq 1.2.3 ver_rs 2 . 1.2-3
+teq 1.2.3.a ver_rs 3 . 1.2.3a
+teq 1.2-alpha-4 ver_rs 2-3 - 1.2_alpha4
+teq 1.23-b_alpha4 ver_rs 3 - 2 "" 1.2.3b_alpha4
+teq a1b_2-c-3-d4e5 ver_rs 3-5 _ 4-6 - a1b2c3d4e5
+teq .1-2.3 ver_rs 1 - .1.2.3
+teq -1.2.3 ver_rs 0 - .1.2.3
+
+# truncating range
+teq 1.2 ver_cut 0-2 1.2.3
+teq 2.3 ver_cut 2-5 1.2.3
+teq "" ver_cut 4 1.2.3
+teq "" ver_cut 0 1.2.3
+teq "" ver_cut 4- 1.2.3
+teq 1.2.3 ver_rs 0 - 1.2.3
+teq 1.2.3 ver_rs 3 . 1.2.3
+teq 1.2.3 ver_rs 3- . 1.2.3
+teq 1.2.3 ver_rs 3-5 . 1.2.3
+
+txf ver_cut foo 1.2.3
+txf ver_rs -3 _ a1b2c3d4e5
+txf ver_rs 5-3 _ a1b2c3d4e5
diff --git a/eclass/tests/eapi7-ver:benchmark.sh b/eclass/tests/eapi7-ver:benchmark.sh
new file mode 100755
index 000000000000..4b262ab6accb
--- /dev/null
+++ b/eclass/tests/eapi7-ver:benchmark.sh
@@ -0,0 +1,76 @@
+#!/bin/bash
+# Copyright 1999-2017 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=6
+
+source tests-common.sh
+
+inherit eapi7-ver
+
+cutting() {
+	local x
+	for x in {1..1000}; do
+		ver_cut 1 1.2.3
+		ver_cut 1-2 1.2.3
+		ver_cut 2- 1.2.3
+		ver_cut 1- 1.2.3
+		ver_cut 3-4 1.2.3b_alpha4
+		ver_cut 5 1.2.3b_alpha4
+		ver_cut 1-2 .1.2.3
+		ver_cut 0-2 .1.2.3
+		ver_cut 2-3 1.2.3.
+		ver_cut 2- 1.2.3.
+		ver_cut 2-4 1.2.3.
+	done >/dev/null
+}
+
+replacing() {
+	local x
+	for x in {1..1000}; do
+		ver_rs 1 - 1.2.3
+		ver_rs 2 - 1.2.3
+		ver_rs 1-2 - 1.2.3.4
+		ver_rs 2- - 1.2.3.4
+		ver_rs 2 . 1.2-3
+		ver_rs 3 . 1.2.3a
+		ver_rs 2-3 - 1.2_alpha4
+		ver_rs 3 - 2 "" 1.2.3b_alpha4
+		ver_rs 3-5 _ 4-6 - a1b2c3d4e5
+		ver_rs 1 - .1.2.3
+		ver_rs 0 - .1.2.3
+	done >/dev/null
+}
+
+get_times() {
+	echo "${*}"
+	local real=()
+	local user=()
+
+	for x in {1..5}; do
+		while read tt tv; do
+			case ${tt} in
+				real) real+=( ${tv} );;
+				user) user+=( ${tv} );;
+			esac
+		done < <( ( time -p "${@}" ) 2>&1 )
+	done
+
+	[[ ${#real[@]} == 5 ]] || die "Did not get 5 real times"
+	[[ ${#user[@]} == 5 ]] || die "Did not get 5 user times"
+
+	local sum
+	for v in real user; do
+		vr="${v}[*]"
+		sum=$(dc -e "${!vr} + + + + 3 k 5 / p")
+
+		vr="${v}[@]"
+		printf '%s %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f\n' \
+			"${v}" "${!vr}" "${sum}"
+	done
+}
+
+export LC_ALL=C
+
+get_times cutting
+get_times replacing
-- 
2.14.1



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [gentoo-dev] Re: [PATCH] eapi7-ver.eclass: 'Early adopter' version of EAPI 7 version manip
  2017-09-08 11:19 [gentoo-dev] [PATCH] eapi7-ver.eclass: 'Early adopter' version of EAPI 7 version manip Michał Górny
@ 2017-09-08 12:48 ` Martin Vaeth
  2017-09-08 12:54   ` Michał Górny
  2017-09-08 13:26 ` [gentoo-dev] " Ulrich Mueller
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 12+ messages in thread
From: Martin Vaeth @ 2017-09-08 12:48 UTC (permalink / raw
  To: gentoo-dev

Michał Górny <mgorny@gentoo.org> wrote:
> +#   1.2b-alpha4 -> 1 . 2 '' b - alpha '' 4

Is this only to explain the syntax or are there plans to
extend the allowed versions for pms?

There is a reason why pms currently does not allow "-" as separators
within versions (with the exception of -r):

With this general syntax, you would have a hard time to split
into name and version for e.g.
media-fonts/font-bitstream-75dpi-1.0.3

(Currently the version starts at the latest /-[0-9]/ match.)

Also the ordering needs a discussion when version strings are
allowed which are not covered by PMS. Note that e.g.
02 > 1 while 1.02 < 1.1
Is it still "correct" to have 1-02 < 1-1?



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [gentoo-dev] Re: [PATCH] eapi7-ver.eclass: 'Early adopter' version of EAPI 7 version manip
  2017-09-08 12:48 ` [gentoo-dev] " Martin Vaeth
@ 2017-09-08 12:54   ` Michał Górny
  2017-09-08 13:13     ` Ciaran McCreesh
  0 siblings, 1 reply; 12+ messages in thread
From: Michał Górny @ 2017-09-08 12:54 UTC (permalink / raw
  To: gentoo-dev

W dniu pią, 08.09.2017 o godzinie 12∶48 +0000, użytkownik Martin Vaeth
napisał:
> Michał Górny <mgorny@gentoo.org> wrote:
> > +#   1.2b-alpha4 -> 1 . 2 '' b - alpha '' 4
> 
> Is this only to explain the syntax or are there plans to
> extend the allowed versions for pms?
> 

It only explains how the functions parse stuff (except for ver_test
which uses PMS rules). They are by definition supposed to work with
random upstream versions.

-- 
Best regards,
Michał Górny



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [gentoo-dev] Re: [PATCH] eapi7-ver.eclass: 'Early adopter' version of EAPI 7 version manip
  2017-09-08 12:54   ` Michał Górny
@ 2017-09-08 13:13     ` Ciaran McCreesh
  2017-09-08 13:48       ` Ulrich Mueller
  0 siblings, 1 reply; 12+ messages in thread
From: Ciaran McCreesh @ 2017-09-08 13:13 UTC (permalink / raw
  To: gentoo-dev

On Fri, 08 Sep 2017 14:54:10 +0200
Michał Górny <mgorny@gentoo.org> wrote:
> W dniu pią, 08.09.2017 o godzinie 12∶48 +0000, użytkownik Martin Vaeth
> napisał:
> > Michał Górny <mgorny@gentoo.org> wrote:  
> > > +#   1.2b-alpha4 -> 1 . 2 '' b - alpha '' 4  
> > 
> > Is this only to explain the syntax or are there plans to
> > extend the allowed versions for pms?
> 
> It only explains how the functions parse stuff (except for ver_test
> which uses PMS rules). They are by definition supposed to work with
> random upstream versions.

This sounds like the sort of thing that could go horribly wrong... I
didn't design versionator to work with arbitrary messy stuff since the
main use is in manipulating Gentoo PV versions. Where are these other
versions coming from?

-- 
Ciaran McCreesh


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [gentoo-dev] [PATCH] eapi7-ver.eclass: 'Early adopter' version of EAPI 7 version manip
  2017-09-08 11:19 [gentoo-dev] [PATCH] eapi7-ver.eclass: 'Early adopter' version of EAPI 7 version manip Michał Górny
  2017-09-08 12:48 ` [gentoo-dev] " Martin Vaeth
@ 2017-09-08 13:26 ` Ulrich Mueller
  2017-09-09 15:05 ` Kent Fredric
  2017-09-19 13:11 ` Michał Górny
  3 siblings, 0 replies; 12+ messages in thread
From: Ulrich Mueller @ 2017-09-08 13:26 UTC (permalink / raw
  To: gentoo-dev; +Cc: Michał Górny

[-- Attachment #1: Type: text/plain, Size: 820 bytes --]

>>>>> On Fri, 8 Sep 2017, Michał Górny wrote:

> +# A version component can either consist purely of digits ([0-9]+) or
> +# purely of uppercase and lowercase letters ([a-zA-Z]+). Any other
> +# character is treated as a version separator.

Minor documentation nitpick (sorry for not noticing this earlier):
A version separator is not necessarily a single character. So the
wording should be along the lines of:

# A version component can either consist purely of digits ([0-9]+) or
# purely of uppercase and lowercase letters ([A-Za-z]+).  A version
# separator is either a string of any other characters ([^A-Za-z0-9]+),
# or it occurs at the transition between a sequence of letters and a
# sequence of digits, or vice versa.  In the latter case, the version
# separator is an empty string.

Ulrich

[-- Attachment #2: Type: application/pgp-signature, Size: 490 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [gentoo-dev] Re: [PATCH] eapi7-ver.eclass: 'Early adopter' version of EAPI 7 version manip
  2017-09-08 13:13     ` Ciaran McCreesh
@ 2017-09-08 13:48       ` Ulrich Mueller
  0 siblings, 0 replies; 12+ messages in thread
From: Ulrich Mueller @ 2017-09-08 13:48 UTC (permalink / raw
  To: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 1209 bytes --]

>>>>> On Fri, 8 Sep 2017, Ciaran McCreesh wrote:

> On Fri, 08 Sep 2017 14:54:10 +0200
> Michał Górny <mgorny@gentoo.org> wrote:
>> It only explains how the functions parse stuff (except for ver_test
>> which uses PMS rules). They are by definition supposed to work with
>> random upstream versions.

> This sounds like the sort of thing that could go horribly wrong...
> I didn't design versionator to work with arbitrary messy stuff since
> the main use is in manipulating Gentoo PV versions.

If we would strictly follow PMS wording there, then for _alpha, _beta,
_p, etc. the underscore would be part of the component. Also in a
suffix like _p2, _p and 2 would be separate components. However, with
versionator.eclass:

   get_version_components 3.0_p2 -> 3 0 p2

So even there, the underscore is taken as a separator. I don't say
that this behaviour is bad, only that it doesn't strictly follow PMS
rules.

> Where are these other versions coming from?

They occur as output of those functions, and I think that e.g.
splitting 1.2_rc3 into components "1", "2", "rc", and "3" with
separators ".", "_", and "" makes more sense than treating "_rc" as an
atomic block.

Ulrich

[-- Attachment #2: Type: application/pgp-signature, Size: 490 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [gentoo-dev] [PATCH] eapi7-ver.eclass: 'Early adopter' version of EAPI 7 version manip
  2017-09-08 11:19 [gentoo-dev] [PATCH] eapi7-ver.eclass: 'Early adopter' version of EAPI 7 version manip Michał Górny
  2017-09-08 12:48 ` [gentoo-dev] " Martin Vaeth
  2017-09-08 13:26 ` [gentoo-dev] " Ulrich Mueller
@ 2017-09-09 15:05 ` Kent Fredric
  2017-09-09 15:54   ` Michał Górny
  2017-09-19 13:11 ` Michał Górny
  3 siblings, 1 reply; 12+ messages in thread
From: Kent Fredric @ 2017-09-09 15:05 UTC (permalink / raw
  To: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 2511 bytes --]

On Fri,  8 Sep 2017 13:19:23 +0200
Michał Górny <mgorny@gentoo.org> wrote:

> a. getting wider review and some real-life testing before
> the specification is set in stone, and

Any thoughts on a function that would represent a dotted-decimal style version
as a floating point string?

eg: 

  ver_float 0.1.0    -> 0.001
  ver_float 0.10.0   -> 0.010
  ver_float 0.100.0  -> 0.100

That's of course *the most* generic example I can offer, but seeing
this sort of transformation is commonly needed in the world of perl, I
thought maybe now is a good time to mention something.

Sadly, its just the sort of idea that if done wrong, would be no use.

For instance, sometimes you want:

   ver_float 0.1.0  -> 0.0010

Or

   ver_float 0.1.1  -> 0.001001

The two key things here is to know: 

1. How many digits each position represents
2. The maximum number of digits to represent

So, some ideas in that regard are:

   ver_float ${INPUT} ${PRECISION}  

Where the values per position are fixed, so:

    ver_float 0.1 3   -> 0.001
    ver_float 0.1 2   -> INVALD  # fidelity loss by truncation
    ver_float 0.10 2  -> 0.01    # permitted because there's no fidelity loss by truncation
    ver_float 0.100 1 -> 0.1     # permitted because there's no fidelity loss by truncation
    ver_float 0.100 2 -> 0.10
    ver_float 0.100 3 -> 0.100
    ver_float 0.101 1 -> INVALID # fidelity loss by truncation

    ver_float 0.1 5   -> 0.00100
    ver_float 0.1.1 5 -> INVALID, need 6 digits to represent 0.1.1 

    ver_float 0.1.1 6 -> 0.001001


Or say, 

    ver_float ${INPUT} ${PATTERN}

Where "pattern" is a string like 3-3-3 indicating how to map digits to numbers

     ver_float 0.1      3    -> 0.001
     ver_float 0.1      2    -> 0.01 
     ver_float 0.1      1    -> 0.1
     ver_float 0.1.1    3    -> # INVALID, no map for '.1'
     ver_float 0.1.1    3-3  -> 0.001001
     ver_float 0.1.10   3-3  -> 0.001010  
     ver_float 0.1.10   2-2  -> 0.0110
     ver_float 0.10.10  2-2  -> 0.1010
     ver_float 0.100.10 2-2  -> # INVALID, can't map "100" into 2 characters

Though I suspect you'd want both features ...

     ver_float ${INPUT} ${PATTERN} ${TRUNCATION_LENGTH}

Because we do need packages where 

     0.123.10 means 0.1231 

Either way, much of this is probably a time wasting bad idea.

But I thought I'd just 

( •_•)

( •_•)>⌐■-■

(⌐■_■)

Float it by you.











[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [gentoo-dev] [PATCH] eapi7-ver.eclass: 'Early adopter' version of EAPI 7 version manip
  2017-09-09 15:05 ` Kent Fredric
@ 2017-09-09 15:54   ` Michał Górny
  2017-09-09 17:05     ` Kent Fredric
  0 siblings, 1 reply; 12+ messages in thread
From: Michał Górny @ 2017-09-09 15:54 UTC (permalink / raw
  To: gentoo-dev

W dniu nie, 10.09.2017 o godzinie 03∶05 +1200, użytkownik Kent Fredric
napisał:
> On Fri,  8 Sep 2017 13:19:23 +0200
> Michał Górny <mgorny@gentoo.org> wrote:
> 
> > a. getting wider review and some real-life testing before
> > the specification is set in stone, and
> 
> Any thoughts on a function that would represent a dotted-decimal style version
> as a floating point string?
> 
> eg: 
> 
>   ver_float 0.1.0    -> 0.001
>   ver_float 0.10.0   -> 0.010
>   ver_float 0.100.0  -> 0.100
> 
> That's of course *the most* generic example I can offer, but seeing
> this sort of transformation is commonly needed in the world of perl, I
> thought maybe now is a good time to mention something.
> 
> Sadly, its just the sort of idea that if done wrong, would be no use.
> 
> For instance, sometimes you want:
> 
>    ver_float 0.1.0  -> 0.0010
> 
> Or
> 
>    ver_float 0.1.1  -> 0.001001
> 
> The two key things here is to know: 
> 
> 1. How many digits each position represents
> 2. The maximum number of digits to represent
> 
> So, some ideas in that regard are:
> 
>    ver_float ${INPUT} ${PRECISION}  
> 
> Where the values per position are fixed, so:
> 
>     ver_float 0.1 3   -> 0.001
>     ver_float 0.1 2   -> INVALD  # fidelity loss by truncation
>     ver_float 0.10 2  -> 0.01    # permitted because there's no fidelity loss by truncation
>     ver_float 0.100 1 -> 0.1     # permitted because there's no fidelity loss by truncation
>     ver_float 0.100 2 -> 0.10
>     ver_float 0.100 3 -> 0.100
>     ver_float 0.101 1 -> INVALID # fidelity loss by truncation
> 
>     ver_float 0.1 5   -> 0.00100
>     ver_float 0.1.1 5 -> INVALID, need 6 digits to represent 0.1.1 
> 
>     ver_float 0.1.1 6 -> 0.001001
> 
> 
> Or say, 
> 
>     ver_float ${INPUT} ${PATTERN}
> 
> Where "pattern" is a string like 3-3-3 indicating how to map digits to numbers
> 
>      ver_float 0.1      3    -> 0.001
>      ver_float 0.1      2    -> 0.01 
>      ver_float 0.1      1    -> 0.1
>      ver_float 0.1.1    3    -> # INVALID, no map for '.1'
>      ver_float 0.1.1    3-3  -> 0.001001
>      ver_float 0.1.10   3-3  -> 0.001010  
>      ver_float 0.1.10   2-2  -> 0.0110
>      ver_float 0.10.10  2-2  -> 0.1010
>      ver_float 0.100.10 2-2  -> # INVALID, can't map "100" into 2 characters
> 
> Though I suspect you'd want both features ...
> 
>      ver_float ${INPUT} ${PATTERN} ${TRUNCATION_LENGTH}
> 
> Because we do need packages where 
> 
>      0.123.10 means 0.1231 
> 
> Either way, much of this is probably a time wasting bad idea.
> 
> But I thought I'd just 
> 
> ( •_•)
> 
> ( •_•)>⌐■-■
> 
> (⌐■_■)
> 
> Float it by you.
> 

I'm not sure if there's a serious proposal behind all this but I suppose
it's all just perl-specific insanity that is of no value to everyone
else.

-- 
Best regards,
Michał Górny



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [gentoo-dev] [PATCH] eapi7-ver.eclass: 'Early adopter' version of EAPI 7 version manip
  2017-09-09 15:54   ` Michał Górny
@ 2017-09-09 17:05     ` Kent Fredric
  0 siblings, 0 replies; 12+ messages in thread
From: Kent Fredric @ 2017-09-09 17:05 UTC (permalink / raw
  To: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 2102 bytes --]

On Sat, 09 Sep 2017 17:54:52 +0200
Michał Górny <mgorny@gentoo.org> wrote:

> I'm not sure if there's a serious proposal behind all this but I suppose
> it's all just perl-specific insanity that is of no value to everyone
> else.

Yeah, some of the stuff I suggested there are generalisations, because
it doesn't make sense to suggest such a feature and have it be
*excusively* for Perl usage.

Pretty much 100% of our usage would be just the 3-position + truncate form.

So:

  $(ver_fixlen $(ver_3float ${PV}) 3)

Or something would be most of it.

We'd probably just keep doing what we're doing with hard-normalization
+ hard-version-maps, mostly because its more obvious what is going on.

But we do have people who keep wanting something that maps $PV to
upstream, and the existing tools to do that aren't /quite/ ideal.

NB: Above, the simplified tools are:

 ver_fixlen $version $length  

 - ensure everything after first '.' are numbers 
 - make sure there are at most $length characters after '.'
 - if characters over $length limit are not '0', error.
 - truncate extraneous 0's beyond $length limit
 - if the remaining number of digits after the '.' is less than $length, 0-pad


 ver_3float $version

 - assume every group after the first '.' are the range 0-999
 - expand every group to 3 digits , so 0 == 000, 1 == 001, 10 == 010, etc.
 - concatenate all minor groups 
 - emit ${first}.${minor_groups}

I think those two would be all perl people might have a use for.

( Again, wouldn't be something we'd deploy at volume in
perl-module.eclass, would only be for the people who wanted to
simplify their own custom maintenance outside the perl herd )

I really only suggested these sorts of things because I figured "its
going to be in an EAPI? maybe the implementation might be in python?,
doing this sort of thing in python might actually be viable, whereas
its a terrible nightmare to do this kind of string manipulation in bash"

Though I figure its possible to in bash, I'm just not insane enough to
try (yet, getting there)

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [gentoo-dev] [PATCH] eapi7-ver.eclass: 'Early adopter' version of EAPI 7 version manip
  2017-09-08 11:19 [gentoo-dev] [PATCH] eapi7-ver.eclass: 'Early adopter' version of EAPI 7 version manip Michał Górny
                   ` (2 preceding siblings ...)
  2017-09-09 15:05 ` Kent Fredric
@ 2017-09-19 13:11 ` Michał Górny
  2017-09-21 17:47   ` Ulrich Mueller
  3 siblings, 1 reply; 12+ messages in thread
From: Michał Górny @ 2017-09-19 13:11 UTC (permalink / raw
  To: gentoo-dev

W dniu pią, 08.09.2017 o godzinie 13∶19 +0200, użytkownik Michał Górny
napisał:
> EAPI 7 is introducing new version manipulation and comparison functions
> that aim to replace versionator.eclass. This eclass provides an 'early
> adopter' versions of those routines.
> 
> It serves two goals:
> 
> a. getting wider review and some real-life testing before
> the specification is set in stone, and
> 
> b. making it possible to adapt ebuilds to the new routines early,
> reducing the future work of EAPI 7 porting.
> 
> For more details on the new logic, please see the eclass documentation.
> Long story short, we are introducing three functions:
> 
> 1. ver_cut -- to get substrings of the version string,
> 
> 2. ver_rs -- to replace version separators via indices,
> 
> 3. ver_test -- to compare two version numbers.
> 
> The third function is not implemented in the eclass. It's meant to reuse
> the algorithms from the package manager, and the final implementation
> will most likely reuse the code from the package manager (e.g. via IPC).
> 

Merged now, with some documentation fixes and additional benchmark to
compare it with versionator.eclass. Here are the approximate results:

cutting
real 5.64 5.62 5.55 5.57 5.56 => 5.59 avg
user 6.25 6.23 6.24 6.10 6.09 => 6.18 avg
cutting_versionator
real 105.00 104.10 104.40 104.30 104.10 => 104.38 avg
user 71.30 71.40 71.20 70.70 71.80 => 71.28 avg
replacing
real 4.76 4.75 4.79 4.77 4.75 => 4.76 avg
user 5.16 5.48 5.60 5.62 5.11 => 5.39 avg
replacing_versionator
real 68.50 68.60 68.40 68.20 68.40 => 68.42 avg
user 51.60 51.40 51.10 51.60 52.30 => 51.60 avg

Please note that versionator tests were run with 10 times less
repetitions and the results were multiplied by 10 to avoid it taking
forever.

-- 
Best regards,
Michał Górny



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [gentoo-dev] [PATCH] eapi7-ver.eclass: 'Early adopter' version of EAPI 7 version manip
  2017-09-19 13:11 ` Michał Górny
@ 2017-09-21 17:47   ` Ulrich Mueller
  2017-09-26 19:07     ` Ulrich Mueller
  0 siblings, 1 reply; 12+ messages in thread
From: Ulrich Mueller @ 2017-09-21 17:47 UTC (permalink / raw
  To: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 11153 bytes --]

>>>>> On Tue, 19 Sep 2017, Michał Górny wrote:

>> EAPI 7 is introducing new version manipulation and comparison functions
>> that aim to replace versionator.eclass. This eclass provides an 'early
>> adopter' versions of those routines.
>>
>> It serves two goals:
>>
>> a. getting wider review and some real-life testing before
>> the specification is set in stone, and
>>
>> b. making it possible to adapt ebuilds to the new routines early,
>> reducing the future work of EAPI 7 porting.
>>
>> For more details on the new logic, please see the eclass documentation.
>> Long story short, we are introducing three functions:
>>
>> 1. ver_cut -- to get substrings of the version string,
>>
>> 2. ver_rs -- to replace version separators via indices,
>>
>> 3. ver_test -- to compare two version numbers.
>>
>> The third function is not implemented in the eclass. It's meant to reuse
>> the algorithms from the package manager, and the final implementation
>> will most likely reuse the code from the package manager (e.g. via IPC).

Meanwhile the ver_test function has been added to the eclass in the
eapi7-ver branch. Please review the patch included below.

> Merged now, with some documentation fixes and additional benchmark to
> compare it with versionator.eclass. [...]

For completeness, here are benchmark results for ver_test(),
in comparison with version_is_at_least().

comparing
real 6.78 6.80 6.81 6.76 6.75 => 6.78 avg
user 6.73 6.75 6.75 6.71 6.69 => 6.73 avg
comparing_versionator
real 196.60 197.80 197.40 199.10 198.60 => 197.90 avg
user 80.10 80.10 80.00 80.40 80.60 => 80.24 avg

Ulrich

-- 8< --
From 9c4953e2d2bdef1244cff025672489bf9c9ff72b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ulrich=20M=C3=BCller?= <ulm@gentoo.org>
Date: Wed, 20 Sep 2017 21:28:22 +0200
Subject: [PATCH] eapi7-ver.eclass: Implement ver_test().
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This should strictly follow Algorithms 3.1 to 3.7 specified in PMS:
https://projects.gentoo.org/pms/6/pms.html#x1-310003.3

Thanks to Michał Górny for many optimizations, and for pointing out
how much my initial implementation sucked. ;-)
---
 eclass/eapi7-ver.eclass             | 111 +++++++++++++++++++++++++++++++++++-
 eclass/tests/eapi7-ver.sh           | 107 ++++++++++++++++++++++++++++++++++
 eclass/tests/eapi7-ver_benchmark.sh |  34 +++++++++++
 3 files changed, 251 insertions(+), 1 deletion(-)

diff --git a/eclass/eapi7-ver.eclass b/eclass/eapi7-ver.eclass
index 6f8f0c0a1c37..ead9fac5e807 100644
--- a/eclass/eapi7-ver.eclass
+++ b/eclass/eapi7-ver.eclass
@@ -176,6 +176,94 @@ ver_rs() {
 	echo "${comp[*]}"
 }
 
+# @FUNCTION: _ver_compare
+# @USAGE: <va> <vb>
+# @RETURN: 1 if <va> < <vb>, 2 if <va> = <vb>, 3 if <va> > <vb>
+# @INTERNAL
+# @DESCRIPTION:
+# Compare two versions <va> and <vb>.  If <va> is less than, equal to,
+# or greater than <vb>, return 1, 2, or 3 as exit status, respectively.
+_ver_compare() {
+	local va=${1} vb=${2} a an al as ar b bn bl bs br re
+
+	re="^([0-9]+(\.[0-9]+)*)([a-z]?)((_(alpha|beta|pre|rc|p)[0-9]*)*)(-r[0-9]+)?$"
+
+	[[ ${va} =~ ${re} ]] || die "${FUNCNAME}: invalid version: ${va}"
+	an=${BASH_REMATCH[1]}
+	al=${BASH_REMATCH[3]}
+	as=${BASH_REMATCH[4]}
+	ar=${BASH_REMATCH[7]}
+
+	[[ ${vb} =~ ${re} ]] || die "${FUNCNAME}: invalid version: ${vb}"
+	bn=${BASH_REMATCH[1]}
+	bl=${BASH_REMATCH[3]}
+	bs=${BASH_REMATCH[4]}
+	br=${BASH_REMATCH[7]}
+
+	# Compare numeric components (PMS algorithm 3.2)
+	# First component
+	a=${an%%.*}
+	b=${bn%%.*}
+	[[ 10#${a} -gt 10#${b} ]] && return 3
+	[[ 10#${a} -lt 10#${b} ]] && return 1
+
+	while [[ ${an} == *.* && ${bn} == *.* ]]; do
+		# Other components (PMS algorithm 3.3)
+		an=${an#*.}
+		bn=${bn#*.}
+		a=${an%%.*}
+		b=${bn%%.*}
+		if [[ ${a} == 0* || ${b} == 0* ]]; then
+			# Remove trailing zeros
+			while [[ ${a} == *0 ]]; do a=${a::-1}; done
+			while [[ ${b} == *0 ]]; do b=${b::-1}; done
+			[[ ${a} > ${b} ]] && return 3
+			[[ ${a} < ${b} ]] && return 1
+		else
+			[[ ${a} -gt ${b} ]] && return 3
+			[[ ${a} -lt ${b} ]] && return 1
+		fi
+	done
+	[[ ${an} == *.* ]] && return 3
+	[[ ${bn} == *.* ]] && return 1
+
+	# Compare letter components (PMS algorithm 3.4)
+	[[ ${al} > ${bl} ]] && return 3
+	[[ ${al} < ${bl} ]] && return 1
+
+	# Compare suffixes (PMS algorithm 3.5)
+	as=${as#_}${as:+_}
+	bs=${bs#_}${bs:+_}
+	while [[ -n ${as} && -n ${bs} ]]; do
+		# Compare each suffix (PMS algorithm 3.6)
+		a=${as%%_*}
+		b=${bs%%_*}
+		if [[ ${a%%[0-9]*} == "${b%%[0-9]*}" ]]; then
+			[[ 10#${a##*[a-z]} -gt 10#${b##*[a-z]} ]] && return 3
+			[[ 10#${a##*[a-z]} -lt 10#${b##*[a-z]} ]] && return 1
+		else
+			# Check for p first
+			[[ ${a%%[0-9]*} == p ]] && return 3
+			[[ ${b%%[0-9]*} == p ]] && return 1
+			# Hack: Use that alpha < beta < pre < rc alphabetically
+			[[ ${a} > ${b} ]] && return 3 || return 1
+		fi
+		as=${as#*_}
+		bs=${bs#*_}
+	done
+	if [[ -n ${as} ]]; then
+		[[ ${as} == p[_0-9]* ]] && return 3 || return 1
+	elif [[ -n ${bs} ]]; then
+		[[ ${bs} == p[_0-9]* ]] && return 1 || return 3
+	fi
+
+	# Compare revision components (PMS algorithm 3.7)
+	[[ 10#${ar#-r} -gt 10#${br#-r} ]] && return 3
+	[[ 10#${ar#-r} -lt 10#${br#-r} ]] && return 1
+
+	return 2
+}
+
 # @FUNCTION: ver_test
 # @USAGE: [<v1>] <op> <v2>
 # @DESCRIPTION:
@@ -185,5 +273,26 @@ ver_rs() {
 # revision parts), and the comparison is performed according to
 # the algorithm specified in the PMS.
 ver_test() {
-	die "${FUNCNAME}: not implemented"
+	local LC_ALL=C
+	local va op vb
+
+	if [[ $# -eq 3 ]]; then
+		va=${1}
+		shift
+	else
+		va=${PVR}
+	fi
+
+	[[ $# -eq 2 ]] || die "${FUNCNAME}: bad number of arguments"
+
+	op=${1}
+	vb=${2}
+
+	case ${op} in
+		-eq|-ne|-lt|-le|-gt|-ge) ;;
+		*) die "${FUNCNAME}: invalid operator: ${op}" ;;
+	esac
+
+	_ver_compare "${va}" "${vb}"
+	test $? "${op}" 2
 }
diff --git a/eclass/tests/eapi7-ver.sh b/eclass/tests/eapi7-ver.sh
index 8a96e4d29b1b..144bb2bddc3e 100755
--- a/eclass/tests/eapi7-ver.sh
+++ b/eclass/tests/eapi7-ver.sh
@@ -17,6 +17,15 @@ teq() {
 	tend ${?} "returned: ${got}"
 }
 
+teqr() {
+	local expected=$1; shift
+	tbegin "$* -> ${expected}"
+	"$@"
+	local ret=$?
+	[[ ${ret} -eq ${expected} ]]
+	tend $? "returned: ${ret}"
+}
+
 txf() {
 	tbegin "XFAIL: ${*}"
 	local got=$("${@}" 2>&1)
@@ -63,3 +72,101 @@ teq 1.2.3 ver_rs 3-5 . 1.2.3
 txf ver_cut foo 1.2.3
 txf ver_rs -3 _ a1b2c3d4e5
 txf ver_rs 5-3 _ a1b2c3d4e5
+
+# Tests from Portage's test_vercmp.py
+teqr 0 ver_test 6.0 -gt 5.0
+teqr 0 ver_test 5.0 -gt 5
+teqr 0 ver_test 1.0-r1 -gt 1.0-r0
+teqr 0 ver_test 999999999999999999 -gt 999999999999999998 # 18 digits
+teqr 0 ver_test 1.0.0 -gt 1.0
+teqr 0 ver_test 1.0.0 -gt 1.0b
+teqr 0 ver_test 1b -gt 1
+teqr 0 ver_test 1b_p1 -gt 1_p1
+teqr 0 ver_test 1.1b -gt 1.1
+teqr 0 ver_test 12.2.5 -gt 12.2b
+teqr 0 ver_test 4.0 -lt 5.0
+teqr 0 ver_test 5 -lt 5.0
+teqr 0 ver_test 1.0_pre2 -lt 1.0_p2
+teqr 0 ver_test 1.0_alpha2 -lt 1.0_p2
+teqr 0 ver_test 1.0_alpha1 -lt 1.0_beta1
+teqr 0 ver_test 1.0_beta3 -lt 1.0_rc3
+teqr 0 ver_test 1.001000000000000001 -lt 1.001000000000000002
+teqr 0 ver_test 1.00100000000 -lt 1.001000000000000001
+teqr 0 ver_test 999999999999999998 -lt 999999999999999999
+teqr 0 ver_test 1.01 -lt 1.1
+teqr 0 ver_test 1.0-r0 -lt 1.0-r1
+teqr 0 ver_test 1.0 -lt 1.0-r1
+teqr 0 ver_test 1.0 -lt 1.0.0
+teqr 0 ver_test 1.0b -lt 1.0.0
+teqr 0 ver_test 1_p1 -lt 1b_p1
+teqr 0 ver_test 1 -lt 1b
+teqr 0 ver_test 1.1 -lt 1.1b
+teqr 0 ver_test 12.2b -lt 12.2.5
+teqr 0 ver_test 4.0 -eq 4.0
+teqr 0 ver_test 1.0 -eq 1.0
+teqr 0 ver_test 1.0-r0 -eq 1.0
+teqr 0 ver_test 1.0 -eq 1.0-r0
+teqr 0 ver_test 1.0-r0 -eq 1.0-r0
+teqr 0 ver_test 1.0-r1 -eq 1.0-r1
+teqr 1 ver_test 1 -eq 2
+teqr 1 ver_test 1.0_alpha -eq 1.0_pre
+teqr 1 ver_test 1.0_beta -eq 1.0_alpha
+teqr 1 ver_test 1 -eq 0.0
+teqr 1 ver_test 1.0-r0 -eq 1.0-r1
+teqr 1 ver_test 1.0-r1 -eq 1.0-r0
+teqr 1 ver_test 1.0 -eq 1.0-r1
+teqr 1 ver_test 1.0-r1 -eq 1.0
+teqr 1 ver_test 1.0 -eq 1.0.0
+teqr 1 ver_test 1_p1 -eq 1b_p1
+teqr 1 ver_test 1b -eq 1
+teqr 1 ver_test 1.1b -eq 1.1
+teqr 1 ver_test 12.2b -eq 12.2
+
+# A subset of tests from Paludis
+teqr 0 ver_test 1.0_alpha -gt 1_alpha
+teqr 0 ver_test 1.0_alpha -gt 1
+teqr 0 ver_test 1.0_alpha -lt 1.0
+teqr 0 ver_test 1.2.0.0_alpha7-r4 -gt 1.2_alpha7-r4
+teqr 0 ver_test 0001 -eq 1
+teqr 0 ver_test 01 -eq 001
+teqr 0 ver_test 0001.1 -eq 1.1
+teqr 0 ver_test 01.01 -eq 1.01
+teqr 0 ver_test 1.010 -eq 1.01
+teqr 0 ver_test 1.00 -eq 1.0
+teqr 0 ver_test 1.0100 -eq 1.010
+teqr 0 ver_test 1-r00 -eq 1-r0
+
+# Additional tests
+teqr 0 ver_test 0_rc99 -lt 0
+teqr 0 ver_test 011 -eq 11
+teqr 0 ver_test 019 -eq 19
+teqr 0 ver_test 1.2 -eq 001.2
+teqr 0 ver_test 1.2 -gt 1.02
+teqr 0 ver_test 1.2a -lt 1.2b
+teqr 0 ver_test 1.2_pre1 -gt 1.2_pre1_beta2
+teqr 0 ver_test 1.2_pre1 -lt 1.2_pre1_p2
+teqr 0 ver_test 1.00 -lt 1.0.0
+teqr 0 ver_test 1.010 -eq 1.01
+teqr 0 ver_test 1.01 -lt 1.1
+teqr 0 ver_test 1.2_pre08-r09 -eq 1.2_pre8-r9
+
+# Bad number or ordering of arguments
+txf ver_test 1
+txf ver_test 1 -lt 2 3
+txf ver_test -lt 1 2
+
+# Bad operators
+txf ver_test 1 "<" 2
+txf ver_test 1 lt 2
+txf ver_test 1 -foo 2
+
+# Malformed versions
+txf ver_test "" -ne 1
+txf ver_test 1. -ne 1
+txf ver_test 1ab -ne 1
+txf ver_test b -ne 1
+txf ver_test 1-r1_pre -ne 1
+txf ver_test 1-pre1 -ne 1
+txf ver_test 1_foo -ne 1
+txf ver_test 1_pre1.1 -ne 1
+txf ver_test 1-r1.0 -ne 1
diff --git a/eclass/tests/eapi7-ver_benchmark.sh b/eclass/tests/eapi7-ver_benchmark.sh
index 1de26444c9b3..c46713713368 100755
--- a/eclass/tests/eapi7-ver_benchmark.sh
+++ b/eclass/tests/eapi7-ver_benchmark.sh
@@ -76,6 +76,38 @@ replacing_versionator() {
 	done >/dev/null
 }
 
+comparing() {
+	local x
+	for x in {1..1000}; do
+		ver_test 1b_p1 -le 1_p1
+		ver_test 1.1b -le 1.1
+		ver_test 12.2.5 -le 12.2b
+		ver_test 4.0 -le 5.0
+		ver_test 5 -le 5.0
+		ver_test 1.0_pre2 -le 1.0_p2
+		ver_test 1.0_alpha2 -le 1.0_p2
+		ver_test 1.0_alpha1 -le 1.0_beta1
+		ver_test 1.0_beta3 -le 1.0_rc3
+		ver_test 1.001000000000000001 -le 1.001000000000000002
+	done
+}
+
+comparing_versionator() {
+	local x
+	for x in {1..100}; do
+		version_is_at_least 1b_p1 1_p1
+		version_is_at_least 1.1b 1.1
+		version_is_at_least 12.2.5 12.2b
+		version_is_at_least 4.0 5.0
+		version_is_at_least 5 5.0
+		version_is_at_least 1.0_pre2 1.0_p2
+		version_is_at_least 1.0_alpha2 1.0_p2
+		version_is_at_least 1.0_alpha1 1.0_beta1
+		version_is_at_least 1.0_beta3 1.0_rc3
+		version_is_at_least 1.001000000000000001 1.001000000000000002
+	done
+}
+
 get_times() {
 	local factor=${1}; shift
 	echo "${*}"
@@ -111,3 +143,5 @@ get_times 1 cutting
 get_times 10 cutting_versionator
 get_times 1 replacing
 get_times 10 replacing_versionator
+get_times 1 comparing
+get_times 10 comparing_versionator
-- 
2.14.1

[-- Attachment #2: Type: application/pgp-signature, Size: 490 bytes --]

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [gentoo-dev] [PATCH] eapi7-ver.eclass: 'Early adopter' version of EAPI 7 version manip
  2017-09-21 17:47   ` Ulrich Mueller
@ 2017-09-26 19:07     ` Ulrich Mueller
  0 siblings, 0 replies; 12+ messages in thread
From: Ulrich Mueller @ 2017-09-26 19:07 UTC (permalink / raw
  To: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 216 bytes --]

>>>>> On Thu, 21 Sep 2017, Ulrich Mueller wrote:

> Meanwhile the ver_test function has been added to the eclass in the
> eapi7-ver branch. Please review the patch included below.

Merged, with some updates.

Ulrich

[-- Attachment #2: Type: application/pgp-signature, Size: 490 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2017-09-26 19:07 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-08 11:19 [gentoo-dev] [PATCH] eapi7-ver.eclass: 'Early adopter' version of EAPI 7 version manip Michał Górny
2017-09-08 12:48 ` [gentoo-dev] " Martin Vaeth
2017-09-08 12:54   ` Michał Górny
2017-09-08 13:13     ` Ciaran McCreesh
2017-09-08 13:48       ` Ulrich Mueller
2017-09-08 13:26 ` [gentoo-dev] " Ulrich Mueller
2017-09-09 15:05 ` Kent Fredric
2017-09-09 15:54   ` Michał Górny
2017-09-09 17:05     ` Kent Fredric
2017-09-19 13:11 ` Michał Górny
2017-09-21 17:47   ` Ulrich Mueller
2017-09-26 19:07     ` Ulrich Mueller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox