Tarantool development patches archive
 help / color / mirror / Atom feed
From: Oleg Babin via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>,
	tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH vshard 2/4] util: introduce Tarantool's semver parser
Date: Wed, 9 Feb 2022 20:53:37 +0300	[thread overview]
Message-ID: <43e7f638-c5da-22d3-2553-113141a786e5@tarantool.org> (raw)
In-Reply-To: <1e64752b75ac76272779b2a3c15c878d65cc20b8.1644366575.git.v.shpilevoy@tarantool.org>

Thanks for your patch.


Looks good. Probably it's worth to move this code into separate module.

There are several modules in Tarantool ecosystem that implement its own 
parsers.

One note below.


On 09.02.2022 03:32, Vladislav Shpilevoy wrote:
> Tarantool's version since recently has semver-like format. It
> made impossible to check for features existence if they were
> introduced not in the first release of one x.x.x triplet.
>
> An alternative would be to test for feature existence by its
> usage, but it is not always possible with ease.
>
> This patch improves version parser in vshard to understand new
> version names.
>
> It will be used by a future commit about netbox's return_raw
> feature adoption to skip its tests for old versions
> (<= 2.10.0-beta2).
>
<stripped>

> +local release_type_weight = {
> +    alpha = 0,
> +    beta = 1,
> +    rc = 2,
> +}
> +
> +local function release_type_cmp(t1, t2)
> +    t1 = release_type_weight[t1]
> +    t2 = release_type_weight[t2]
> +    -- 'No release type' means the greatest.
> +    if not t1 then
> +        if not t2 then
> +            return 0
> +        end
> +        return 1
> +    end
> +    if not t2 then
> +        return -1
> +    end
> +    return t1 - t2
> +end
> +
> +local function version_cmp(ver1, ver2)
> +    if ver1.id_major ~= ver2.id_major then
> +        return ver1.id_major - ver2.id_major
> +    end
> +    if ver1.id_middle ~= ver2.id_middle then
> +        return ver1.id_middle - ver2.id_middle
> +    end
> +    if ver1.id_minor ~= ver2.id_minor then
> +        return ver1.id_minor - ver2.id_minor
> +    end
> +    if ver1.rel_type ~= ver2.rel_type then
> +        return release_type_cmp(ver1.rel_type, ver2.rel_type)
> +    end
> +    if ver1.rel_num ~= ver2.rel_num then
> +        return ver1.rel_num - ver2.rel_num
> +    end
> +    if ver1.id_commit ~= ver2.id_commit then
> +        return ver1.id_commit - ver2.id_commit
> +    end
> +    return 0
> +end
> +
> +local version_mt = {
> +    __eq = function(l, r)
> +        return version_cmp(l, r) == 0
> +    end,
> +    __lt = function(l, r)
> +        return version_cmp(l, r) < 0
> +    end,
> +    __le = function(l, r)
> +        return version_cmp(l, r) <= 0
> +    end,
> +}
> +
> +local function version_new(id_major, id_middle, id_minor, rel_type, rel_num,
> +                           id_commit)

I think we could validate that at least id_major is not nil.

> +    -- There is no any validation - the API is not public.
> +    return setmetatable({
> +        id_major = id_major,
> +        id_middle = id_middle,
> +        id_minor = id_minor,
> +        rel_type = rel_type,
> +        rel_num = rel_num,
> +        id_commit = id_commit,
> +    }, version_mt)
> +end
> +
>

  reply	other threads:[~2022-02-09 17:54 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-09  0:32 [Tarantool-patches] [PATCH vshard 0/4] Router msgpack object and netbox return_raw Vladislav Shpilevoy via Tarantool-patches
2022-02-09  0:32 ` [Tarantool-patches] [PATCH vshard 1/4] test: support luatest Vladislav Shpilevoy via Tarantool-patches
2022-02-09 17:53   ` Oleg Babin via Tarantool-patches
2022-02-10 22:32     ` Vladislav Shpilevoy via Tarantool-patches
2022-02-11 16:38       ` Oleg Babin via Tarantool-patches
2022-02-09  0:32 ` [Tarantool-patches] [PATCH vshard 2/4] util: introduce Tarantool's semver parser Vladislav Shpilevoy via Tarantool-patches
2022-02-09 17:53   ` Oleg Babin via Tarantool-patches [this message]
2022-02-10 22:33     ` Vladislav Shpilevoy via Tarantool-patches
2022-02-11 16:38       ` Oleg Babin via Tarantool-patches
2022-02-09  0:32 ` [Tarantool-patches] [PATCH vshard 3/4] router: support msgpack object args Vladislav Shpilevoy via Tarantool-patches
2022-02-09 17:53   ` Oleg Babin via Tarantool-patches
2022-02-10 22:33     ` Vladislav Shpilevoy via Tarantool-patches
2022-02-11 16:38       ` Oleg Babin via Tarantool-patches
2022-02-09  0:32 ` [Tarantool-patches] [PATCH vshard 4/4] router: support netbox return_raw Vladislav Shpilevoy via Tarantool-patches
2022-02-09 17:53   ` Oleg Babin via Tarantool-patches
2022-02-10 22:34     ` Vladislav Shpilevoy via Tarantool-patches
2022-02-11 16:38       ` Oleg Babin via Tarantool-patches
2022-02-11 23:05 ` [Tarantool-patches] [PATCH vshard 0/4] Router msgpack object and " Vladislav Shpilevoy via Tarantool-patches
2022-02-15 16:55   ` Oleg Babin via Tarantool-patches
2022-02-15 21:16     ` Vladislav Shpilevoy via Tarantool-patches

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=43e7f638-c5da-22d3-2553-113141a786e5@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=olegrok@tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH vshard 2/4] util: introduce Tarantool'\''s semver parser' \
    /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

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