public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Kent Fredric" <kentfredric@gmail.com>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/perl-overlay:master commit in: eclass/
Date: Sun, 21 Jun 2015 00:39:52 +0000 (UTC)	[thread overview]
Message-ID: <1434846208.94b98bb0d11bfda14193cdb9c01c4c10d6e6f7ba.kent@gentoo> (raw)

commit:     94b98bb0d11bfda14193cdb9c01c4c10d6e6f7ba
Author:     Kent Fredric <kentfredric <AT> gmail <DOT> com>
AuthorDate: Sun Jun 21 00:14:19 2015 +0000
Commit:     Kent Fredric <kentfredric <AT> gmail <DOT> com>
CommitDate: Sun Jun 21 00:23:28 2015 +0000
URL:        https://gitweb.gentoo.org/proj/perl-overlay.git/commit/?id=94b98bb0

[eclass] Add perl-version.eclass which can turn normalised forms into floats

 eclass/perl-version.eclass | 91 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 91 insertions(+)

diff --git a/eclass/perl-version.eclass b/eclass/perl-version.eclass
new file mode 100644
index 0000000..97022e2
--- /dev/null
+++ b/eclass/perl-version.eclass
@@ -0,0 +1,91 @@
+# Copyright 1999-2015 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: $
+
+# @ECLASS: perl-versions.eclass
+# @MAINTAINER:
+# perl@gentoo.org
+# Kent Fredric <kentnl@cpan.org>
+# @BLURB: Perl versioning functions
+# @DESCRIPTION:
+# The perl-version eclass contains an assortment of functions for denormalizing versions
+# in order to streamline version bumps and minimise risk of accidental failure to update
+# MODULE_VERSION and unify all the ways of turning arbitrary normalised versions back into
+# a form used upstream.
+
+# expand-tail 5 => 005
+# expand-tail 5.5 => 005005
+perl-version-expand-tail() {
+	local tail=$1
+	if [ -z "${tail}" ]; then
+		echo '000';
+		return;
+	fi
+	# Tail with no segments
+	if [ "${tail%%.*}" = "${tail}" ]; then
+		printf "%03d" "$tail"
+		return;
+	fi
+	local head="${tail%%.*}"
+	local rest=$( perl-version-expand-tail "${tail#*.}" )
+	printf "%03d%s" $head $rest;
+	return;
+}
+
+# float 5.1   => 5.001
+# float 5.10  => 5.010
+# float 5.100 => 5.100
+# float 5.1.1 => 5.001001
+perl-version-float() {
+	local version=$1
+	local major=${version%%.*}
+	local tail=${version#*.}
+	if [ "$tail" = "$version" ]; then
+		tail=000;
+	else
+		tail=$( perl-version-expand-tail "${tail}" )
+	fi
+	printf "%s.%s" "$major" "$tail";
+	return;
+}
+
+# float_n 5.201.505.200 8 => 5.20150520
+perl-version-float_n() {
+	local version=$1
+	local mantissa=$2
+	local major=${version%%.*}
+	if [ "$mantissa" -lt 1 ]; then
+		printf "%s" $major;
+		return;
+	fi
+	local tail=${version#*.}
+	if [ "$tail" = "$version" ]; then
+		tail=000;
+	else
+		tail=$( perl-version-expand-tail "${tail}" )
+	fi
+	if [ "${#tail}" -lt $mantissa ]; then
+		local pad=$(( $mantissa - ${#tail} ));
+		printf "%s.%s%0${pad}d" "${major}" "${tail}" 0
+		return
+	fi
+	printf "%s.%s" "${major}" "${tail:0:$mantissa}"
+}
+
+# denormalize 5.201.505.200 float_n 8 => 5.20150520
+perl-version-denormalize() {
+	local version=$1;
+	local scheme=$2;
+	shift
+	shift
+	case "${scheme}" in
+		"float_n")
+			perl-version-float_n $version "$@"
+			return
+			;;
+		*)
+			die "Unknown version scheme ${scheme}"
+			;;
+	esac
+}
+


             reply	other threads:[~2015-06-21  0:39 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-21  0:39 Kent Fredric [this message]
  -- strict thread matches above, loose matches on Subject: below --
2017-09-17  0:51 [gentoo-commits] proj/perl-overlay:master commit in: eclass/ Kent Fredric
2017-09-17  0:51 Kent Fredric
2017-09-17  0:51 Kent Fredric
2017-09-17  0:51 Kent Fredric
2017-09-17  0:51 Kent Fredric
2017-09-17  0:51 Kent Fredric
2017-09-17  0:51 Kent Fredric
2017-09-17  0:51 Kent Fredric
2017-09-17  0:51 Kent Fredric
2017-09-17  0:51 Kent Fredric
2017-09-17  0:51 Kent Fredric
2017-09-17  0:51 Kent Fredric
2017-09-17  0:51 Kent Fredric
2017-09-17  0:51 Kent Fredric
2017-09-17  0:51 Kent Fredric
2017-09-17  0:51 Kent Fredric
2017-09-17  0:51 Kent Fredric
2017-09-17  0:51 Kent Fredric
2017-09-17  0:51 Kent Fredric
2017-09-17  0:51 Kent Fredric
2017-09-17  0:51 Kent Fredric
2017-09-17  0:51 Kent Fredric
2017-09-17  0:51 Kent Fredric
2017-09-17  0:51 Kent Fredric
2017-09-17  0:51 Kent Fredric
2015-06-25  1:26 Kent Fredric
2015-06-21  0:39 Kent Fredric
2015-06-20 22:13 Kent Fredric
2015-06-20 22:13 Kent Fredric
2015-06-20 22:13 Kent Fredric
2015-06-20 22:13 Kent Fredric
2015-03-26 12:14 Kent Fredric
2015-03-15 17:06 Kent Fredric
2015-03-15  5:10 Kent Fredric
2015-03-15  5:10 Kent Fredric
2014-12-23 18:19 Kent Fredric
2014-12-23 18:19 Kent Fredric
2014-12-23 14:43 Kent Fredric
2014-10-11 18:46 Kent Fredric
2014-10-11 18:46 Kent Fredric
2014-10-11 18:46 Kent Fredric
2014-08-26 19:06 Kent Fredric
2014-08-24 13:56 Kent Fredric
2014-08-20 13:24 Kent Fredric
2014-04-04 23:09 Kent Fredric
2013-09-17  4:35 Kent Fredric
2013-09-17  4:28 Kent Fredric
2013-04-28 16:53 Kent Fredric
2012-09-15 16:58 Torsten Veller
2012-06-07  6:06 Torsten Veller
2012-06-05 18:22 Torsten Veller
2012-06-05 18:22 Torsten Veller
2012-04-23 13:04 Torsten Veller
2012-04-23 13:04 Torsten Veller
2012-04-23 13:04 Torsten Veller
2011-08-16 17:02 Torsten Veller
2011-04-24  8:37 Torsten Veller
2011-02-04  8:15 tove

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=1434846208.94b98bb0d11bfda14193cdb9c01c4c10d6e6f7ba.kent@gentoo \
    --to=kentfredric@gmail.com \
    --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