RE: [feature request] Is it possible to have git tag can be sorted and filtered by semver?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Monday, July 22, 2024 5:31 PM, brian m. carlson wrote:
>On 2024-07-22 at 16:58:11, Thaina Yu wrote:
>> Currently there is `ls-remote` and `tag` that has option to
>> --sort=version:refname which is really useful when we have tag as
>> version format and let it sort as numeric version
>>
>> But it could be better if we can also sort and filter the version in
>> the range of semver format. So we can use git system as dependency
>> management system natively
>>
>> So I would like to propose a new sort option semver:refname
>>
>> `git ls-remote --sort=semver:refname myRepoUrl refs/tags/v{^0.*.*}`
>> where brace {} can be used to define semver versioning ranges for the
>> patterns in addition to glob filter
>
>Assuming we add such a feature, how does sorting by SemVer differ from the
>current version sorting?  That is, where is the current version sorting deficient for
>SemVer?  Also, what do you want to happen when a tag doesn't meet SemVer
>requirements (note that the "v" prefix is not allowed in SemVer, although it's
>customary in tags)?

Currently, tags would be sorted as follows (simple example):
1.10.0
1.2.0
1.9.1

With semver, the tags would be:
1.2.0
1.9.1
1.10.0

My take is that this, if implemented, would need to be more general, and include prefix and suffix handling, so:
v1.2.0
v1.9.0
v1.10.0

should sort as appropriate. We might need something like v({semver}), or a more general regex-like (prefix){0,1}(semver){1}(suffix){0,1}.

While at it, having a reverse sort would also be useful. For platforms that have semver-util, this can be trivially scripted. For exotics, no such luck, as semver-util is not especially portable, not for lack of trying.

>As for the special range syntax, I think the typical suggestion is to filter the output of
>ls-remote or for-each-ref by piping it to a suitable program.  Perl or Ruby are
>common choices here, and both could easily parse SemVer tags.  For example:
>
>  git for-each-ref --sort=v:refname refs/tags/ |
>  ruby -ne 'if %r[\trefs/tags/v(\d+)\.(\d+)\.(\d+)$]; ver =
>Regexp.last_match[1..3].map(&:to_i); puts $_ if [[2, 6, 3], ver, [2, 15, 2]].sort[1] ==
>ver; end'
>
>Git is intentionally designed to support this kind of shell scripting.

I think implementing both wrapped semver and reverse sort in git tag might be useful for large projects, like git and OpenSSL where the number of tags is large. It would make finding time-ordered releases somewhat easier.

--Randall






[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux