git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 22, 2024, 23:40 UTC
Message-ID
<xmqqy15t6lmz.fsf@gitster.g>
In-Reply-To
<031701dadc8c$db6d3370$92479a50$@nexbridge.com>
<rsbecker@nexbridge.com> writes:
Show 14 quoted lines
> 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

Without implemeting anything, wouldn't "--sort=version:refname" suggested by Brian work just fine?

In the git repository:
    $ git tag --sort=version:refname | grep -e 'v2\.[0-9][0-9]*\.[0-9][0-9]*$'
    v2.0.0
    ...
    v2.0.5
    v2.1.0
    v2.1.1
    v2.1.2
    v2.1.3
    v2.1.4
    v2.2.0
    ...
    v2.9.0
    ...
    v2.9.5
    v2.10.0
    v2.10.1
    v2.10.2
    v2.10.3
    v2.10.4
    v2.10.5
    v2.11.0
    ...
    v2.45.1
    v2.45.2

sorting 2.1.x series a lot earlier than 2.10.x series that is sorted after 2.9.x series.

Isn't it exactly what the original requester wants to see?

One mechanism I find it lacking is a mechanism to tell the tool that -preW in X.Y.Z-preW is a suffix that signals that X.Y.Z-preW comes before X.Y.Z, while -postW in X.Y.Z-postW is a suffix that signals that X.Y.Z-postW comes after X.Y.Z. Using such a mechanism, we could say v2.1.0-rc0 comes before v2.1.0-rc1, which in turn comes before v2.1.0-rc2, which in turn comes before v2.1.0 proper.

But other than the ordering of the final release and -rcX, I think "--sort=version:refname" does the right thing already.

Previous: rsbecker@nexbridge.comNext: brian m. carlson
Message 4 of 6 in “[feature request] Is it possible to have git tag can be sorted and filtered by semver?”
  1. Thaina YuJul 22, 2024
  2. brian m. carlsonJul 22, 2024
  3. rsbecker@nexbridge.comJul 22, 2024
  4. Junio C HamanoJul 22, 2024
  5. brian m. carlsonJul 23, 2024
  6. Thaina YuJul 23, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.