From dd3c3f2e27013fd1fb87bd1f2ad8989b17f39727 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Sat, 3 Nov 2007 07:20:47 -0600 Subject: [PATCH] Adjust version comparison to account for git snapshot numbers. * lib/m4sugar/m4sugar.m4 (_m4_version_unletter): Also treat - as a component separator. * doc/autoconf.texi (Number processing Macros) : Document this change. * tests/m4sugar.at (m4@&t@_version_compare): Test it. Signed-off-by: Eric Blake --- ChangeLog | 9 +++++++++ doc/autoconf.texi | 21 +++++++++++++++++---- lib/m4sugar/m4sugar.m4 | 16 +++++++++------- tests/m4sugar.at | 6 +++++- 4 files changed, 40 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index e48da1fd..8124d3dc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2007-11-03 Eric Blake + + Adjust version comparison to account for git snapshot numbers. + * lib/m4sugar/m4sugar.m4 (_m4_version_unletter): Also treat - as a + component separator. + * doc/autoconf.texi (Number processing Macros) + : Document this change. + * tests/m4sugar.at (m4@&t@_version_compare): Test it. + 2007-10-30 Bruno Haible * lib/autoconf/types.m4 (_AC_TYPE_LONG_LONG_SNIPPET): New macro, diff --git a/doc/autoconf.texi b/doc/autoconf.texi index f05b2ec4..73077a03 100644 --- a/doc/autoconf.texi +++ b/doc/autoconf.texi @@ -11182,10 +11182,19 @@ usability limitations that were not lifted until Autoconf 2.62. Compare the version strings @var{version-1} and @var{version-2}, and expand to @samp{-1} if @var{version-1} is smaller, @samp{0} if they are the same, or @samp{1} @var{version-2} is smaller. Version strings must be a list -of elements separated by @samp{.}, where each element is a number along -with optional case-insensitive letters designating beta releases. The -comparison stops at the leftmost element that contains a difference, -although a 0 element compares equal to a missing element. +of elements separated by @samp{.}, @samp{,} or @samp{-}, where each +element is a number along with optional case-insensitive letters +designating beta releases. The comparison stops at the leftmost element +that contains a difference, although a 0 element compares equal to a +missing element. + +It is permissible to include commit identifiers in @var{version}, such +as an abbreviated SHA1 of the commit, provided there is still a +monotonically increasing prefix to allow for accurate version-based +comparisons. For example, this paragraph was written when the +development snapshot of autoconf claimed to be at version +@samp{2.61a-248-dc51}, or 248 commits after the 2.61a release, with an +abbreviated commit identification of @samp{dc51}. @example m4_version_compare([1.1], [2.0]) @@ -11202,6 +11211,10 @@ m4_version_compare([1.1pre], [1.1PRE]) @result{}0 m4_version_compare([1.1a], [1,10]) @result{}-1 +m4_version_compare([2.61a], [2.61a-248-dc51]) +@result{}-1 +m4_version_compare([2.61b], [2.61a-248-dc51]) +@result{}1 @end example @end defmac diff --git a/lib/m4sugar/m4sugar.m4 b/lib/m4sugar/m4sugar.m4 index e4bf9b29..e048dc2c 100644 --- a/lib/m4sugar/m4sugar.m4 +++ b/lib/m4sugar/m4sugar.m4 @@ -2129,18 +2129,20 @@ m4_define([m4_sign], # [2.61aa.b] -> [2.61+1.-1.[0r36:aa],+1.-1.[0r36:b]] -> 2.62.-1.370.1.-1.11 # # This macro expects reasonable version numbers, but can handle double -# letters and does not expand one-letter macros. Inline constant expansions, -# to avoid m4_defn overhead. _m4_version_unletter is the real workhorse -# used by m4_version_compare, but since [0r36:a] is less readable than 10, -# we provide a wrapper for human use. +# letters and does not expand any macros. Original version strings can +# use both `.' and `-' separators. +# +# Inline constant expansions, to avoid m4_defn overhead. +# _m4_version_unletter is the real workhorse used by m4_version_compare, +# but since [0r36:a] is less readable than 10, we provide a wrapper for +# human use. m4_define([m4_version_unletter], [m4_map_sep([m4_eval], [.], m4_dquote(m4_dquote_elt(m4_unquote(_$0([$1])))))]) m4_define([_m4_version_unletter], -[m4_translit(m4_bpatsubst([[[$1]]], ]dnl +[m4_bpatsubst(m4_translit([[[$1]]], [.-], [,,]),]dnl m4_dquote(m4_dquote(m4_defn([m4_cr_Letters])))[[+], - [+1.-1.[0r36:\&]]), - [.], [,])]) + [+1,-1,[0r36:\&]])]) # m4_version_compare(VERSION-1, VERSION-2) diff --git a/tests/m4sugar.at b/tests/m4sugar.at index 9b1dc0ee..163dea1f 100644 --- a/tests/m4sugar.at +++ b/tests/m4sugar.at @@ -368,10 +368,12 @@ m4_version_compare([1.0], [1]) m4_version_compare([1.0a], [1.0a]) m4_version_compare([1.1a], [1.1a.1]) m4_version_compare([1.10], [1.1a]) -m4_version_compare([1.1a], [1.1A]) +m4_version_compare([1-1a], [1,1A]) m4_define([a], [oops])dnl m4_version_compare([1.1a], [1.1A]) m4_version_compare([1z], [1aa]) +m4_version_compare([2.61a], [2.61a-248-dc51]) +m4_version_compare([2.61b], [2.61a-248-dc51]) ]], [[-1 1 @@ -385,6 +387,8 @@ m4_version_compare([1z], [1aa]) 0 0 -1 +-1 +1 ]]) AT_CLEANUP -- 2.11.4.GIT