[Dnsmasq-discuss] Announce: dnsmasq-2.84 - sort and semantic versioning

Simon Kelley simon at thekelleys.org.uk
Fri Jan 29 23:19:46 UTC 2021


On 26/01/2021 16:55, M. Buecher wrote:
> 
> 
> On 2021-01-26 17:41, M. Buecher wrote:
>> On 2021-01-26 00:43, Lonnie Abelbeck wrote:
>>>> On Jan 25, 2021, at 5:21 PM, Lonnie Abelbeck
>>>> <lists at lonnie.abelbeck.com> wrote:
>>>>
>>>>
>>>>> Get it here:
>>>>>
>>>>> http://www.thekelleys.org.uk/dnsmasq/dnsmasq-2.84.tar.gz
>>>>
>>>> The version string generated is "2.84rc2"
>>>>
>>>> $ cat dnsmasq-2.84/VERSION
>>>> (HEAD -> master, tag: v2.84rc2, tag: v2.84, origin/master, origin/HEAD)
>>>
>>> This patch solves the problem:
>>>
>>> --- dnsmasq-2.84/bld/get-version.orig    2021-01-25
>>> 17:35:04.882908877 -0600
>>> +++ dnsmasq-2.84/bld/get-version    2021-01-25 17:35:58.658467974 -0600
>>> @@ -28,7 +28,7 @@
>>>       vers=`cat $1/VERSION | sed 's/[(), ]/,/ g' | tr ',' '\n' | grep
>>> ^v[0-9]`
>>>
>>>       if [ $? -eq 0 ]; then
>>> -         echo "${vers}" | sort -r | head -n 1 | sed 's/^v//'
>>> +         echo "${vers}" | sort | head -n 1 | sed 's/^v//'
>>>       else
>>>           cat $1/VERSION
>>>       fi
>>
>> Actually sort is not good at sorting semantic versions [1].
>> In some cases '-r' will work (2.84, 2.83-post1, 2.83) and in others it
>> won't (2.84-rc1, 2.84, 2.83). Same applies for sort without '-r'.
>>
>> [1] https://semver.org/
>>
>> Just my two cents
>> Maddes
> 
> Forgot to reference the details for sort's -V|--version-sort option at
> https://www.gnu.org/software/coreutils/manual/coreutils.html#Implementation-Details
> 
> Other wrote scripts in other languages like php, Python, etc., e.g.
> https://gist.github.com/andkirby/54204328823febad9d34422427b1937b
> 
> 

Lonnie's patch exactly reverses f4f400776b3c1aa303d1a0fcd500f0ab5bc970f2
from 2015, which I guess was to address a problem with a different set
of version strings.

After a certain amount of trial and error, I've managed to coax sort
into doing the right thing for version strings which dnsmasq uses.

v2.84 sorts before v2.83, but v2.83 sorts before v2.83rc1 and 2.83rc1
sorts before v2.83test1


It's not pretty:

sort -k1.2,1.5r -k 1.6,1.6 -k1.8,1.9r -k1.10,1.11r

I'm assuming that people don't want yet another release just to fix
this, but if I've assumed wrong, let me know.


Cheers,

Simon.



More information about the Dnsmasq-discuss mailing list