Re: [exim-dev] [exim-cvs] Changed version comparison to be s…

Top Page
Delete this message
Reply to this message
Author: Alain Williams
Date:  
To: exim-dev
Subject: Re: [exim-dev] [exim-cvs] Changed version comparison to be string based
On Sat, Oct 27, 2012 at 10:32:50AM +0100, Nigel Metheringham wrote:

> Problem is version numbers are hard, and people tend to have, say,
> 5.00_RC1 5.00 5.00.01 - and they need to sort in that order; and thats
> before you go completely pathological.
>
> I'll hack together a better version comparison - there is a decent CPAN
> module that I think will do the right thing, but probably don't want to
> bloat the dependancies.
>
>     Nigel.


Recent versions of the commands 'sort' & 'ls' support version sorting (-V,
--version-sort and -v respectively). It might be worth being compatible:

10.1.4 Details about version sort
---------------------------------

Version sorting handles the fact that file names frequently include
indices or version numbers. Standard sorting usually does not produce
the order that one expects because comparisons are made on a
character-by-character basis. Version sorting is especially useful
when browsing directories that contain many files with indices/version
numbers in their names:

     $ ls -1            $ ls -1v
     abc.zml-1.gz       abc.zml-1.gz
     abc.zml-12.gz      abc.zml-2.gz
     abc.zml-2.gz       abc.zml-12.gz


Version-sorted strings are compared such that if VER1 and VER2 are
version numbers and PREFIX and SUFFIX (SUFFIX matching the regular
expression `(\.[A-Za-z~][A-Za-z0-9~]*)*') are strings then VER1 < VER2
implies that the name composed of "PREFIX VER1 SUFFIX" sorts before
"PREFIX VER2 SUFFIX".

Note also that leading zeros of numeric parts are ignored:

     $ ls -1            $ ls -1v
     abc-1.007.tgz      abc-1.01a.tgz
     abc-1.012b.tgz     abc-1.007.tgz
     abc-1.01a.tgz      abc-1.012b.tgz


This functionality is implemented using gnulib's `filevercmp'
function, which has some caveats worth noting.


--
Alain Williams
Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer.
+44 (0) 787 668 0256 http://www.phcomp.co.uk/
Parliament Hill Computers Ltd. Registration Information: http://www.phcomp.co.uk/contact.php
#include <std_disclaimer.h>