public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
From: <rsbecker@nexbridge.com>
To: "'brian m. carlson'" <sandals@crustytoothpaste.net>,
	"'Thaina Yu'" <thainayu@gmail.com>
Cc: <git@vger.kernel.org>
Subject: RE: [feature request] Is it possible to have git tag can be sorted and filtered by semver?
Date: Mon, 22 Jul 2024 19:14:03 -0400	[thread overview]
Message-ID: <031701dadc8c$db6d3370$92479a50$@nexbridge.com> (raw)
In-Reply-To: <Zp7Pg7ZOlBZcfJei@tapette.crustytoothpaste.net>

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


  reply	other threads:[~2024-07-22 23:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-22 16:58 [feature request] Is it possible to have git tag can be sorted and filtered by semver? Thaina Yu
2024-07-22 21:30 ` brian m. carlson
2024-07-22 23:14   ` rsbecker [this message]
2024-07-22 23:40     ` Junio C Hamano
2024-07-23  0:05     ` brian m. carlson
2024-07-23  3:06       ` Thaina Yu

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='031701dadc8c$db6d3370$92479a50$@nexbridge.com' \
    --to=rsbecker@nexbridge.com \
    --cc=git@vger.kernel.org \
    --cc=sandals@crustytoothpaste.net \
    --cc=thainayu@gmail.com \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox