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

Re: Bugreport: Prefix - is ignored when sorting (on committerdate)

From
MÅMartin Ågren <martin.agren@gmail.com>
Date
Jan 10, 2023, 10:54 UTC
Message-ID
<CAN0heSprKD35P-D7GTVQ20eRsj0AriYEA7iCDnrA9GuiwX0snw@mail.gmail.com>
In-Reply-To
<CALDp=1EVmQE2NZAd7ccAT0z=R=2S8FvyJzsPNrDeXwdJkEW3Lg@mail.gmail.com>
Hej Fredrik,
On Tue, 10 Jan 2023 at 10:50, Fredrik Öberg <fredrik@bakskuru.se> wrote:
Show 13 quoted lines
> - Create a new repository
> - Add a new file to the repository and commit
> - Create a tag
> $ git tag -a TagOne -m ""
> - Update the file and commit the change
> - Create a tag
> $ git tag -a TagTwo -m ""
> - List tags by committerdate:
> $ git tag -l --sort=committerdate
> (oldest tag is listed first)
> - List tags by reversed committerdate:
> $ git tag -l --sort=-committerdate
> (oldest tag it still listed first)
Show 6 quoted lines
> Anything else you want to add:
> The correct behaviour (reversing sort-order by using the minus-prefix)
> has been verified in
> version 2.11.0, 2.11.1, 2.14.2, 2.19.1, 2.19.2, 2.23.0 on CentOS 7.4
> version 2.31.1 and 2.35.1 on CentOS 7.4 contains the error
> version 2.34.1.windows.1 contains the error

This bisects to 7c5045fc18 ("ref-filter: apply fallback refname sort only after all user sorts", 2020-05-03). I've cc-ed the author. That commit does change the behavior for the kind of test repo you describe.

That said, you're using "committerdate" here. If you use "taggerdate" (or "creatordate") I think you'll get the output you expect, even for newer Git versions. Does that help?

Since you just have two commits in the reproducer, there's a strong correlation between tag names and the timestamps involved. You actually end up sorting by refname: because there is no committerdate for these tags, the refnames are compared as a fallback. While the old code then applied the reversal ('-') to *that*, the new code first fails to find any difference, so doesn't have anything to reverse, then falls back to comparing the refnames, at which point it doesn't consider reversing the result.

All of this is based on my understanding. I could obviously be wrong.

I suppose it could be argued that the '-' should be applied to the fallback as well, e.g., to uphold some sort of "using '-' should give the same result as piping the whole thing through tac" (i.e., respecting `s->reverse` in `compare_refs()`, if you're following along in 7c5045fc18). With multiple sort keys, some with '-' and some without, we'd grab the '-' from the first key. It seems like that could make sense, actually.

I might post such a patch, but as noted above, I think what you really want to use is "taggerdate". I hope that helps.

Martin
Previous: Fredrik ÖbergNext: Jeff King
Message 2 of 6 in “Bugreport: Prefix - is ignored when sorting (on committerdate)”
  1. Fredrik ÖbergJan 10, 2023
  2. Martin ÅgrenJan 10, 2023
  3. Jeff KingJan 10, 2023
  4. Martin ÅgrenJan 10, 2023
  5. Fredrik ÖbergJan 10, 2023
  6. Jeff KingJan 10, 2023

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.