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

Re: git for-each-ref - sorting by multiple keys

From
clime <clime7@gmail.com>
Date
May 3, 2020, 10:16 UTC
Message-ID
<CAGqZTUvaiDQbiQ1dOoqLcy+GHZg+BuXY=Z+S=Dpsq=wm44dGaQ@mail.gmail.com>
In-Reply-To
<20200503090952.GA170768@coredump.intra.peff.net>
Awesome, thanks!
On Sun, 3 May 2020 at 11:09, Jeff King <peff@peff.net> wrote:
Show 36 quoted lines
>
> On Sat, May 02, 2020 at 10:31:50PM +0200, clime wrote:
>
> > I have the following command:
> >
> > /usr/bin/git for-each-ref --merged="${GIT_HEAD-HEAD}"
> > --sort='-taggerdate' --sort='-*committerdate'
> > --format="%(*committerdate)|%(taggerdate)|%(tag)" refs/tags
> >
> > I thought this will use: -*commiterdate as a primary key and
> > -taggerdate as a secondary. According to man page for --sort: "You may
> > use the --sort=<key> option multiple times, in which case the last key
> > becomes the primary key."
> >
> > But that doesn't seem to be the case. I created a repo with a single
> > commit and created annotated tags on the commit in the following
> > order:
>
> It looks like this has been quite broken since 2015 and nobody noticed. :(
>
> Thanks for your reproduction recipe; using times is a critical part of
> the bug. Here's a fix, plus a fix for a related bug I noticed while
> working on it (the second one fixes your bug).
>
>   [1/2]: ref-filter: apply --ignore-case to all sorting keys
>   [2/2]: ref-filter: apply fallback refname sort only after all user sorts
>
>  builtin/branch.c        |  2 +-
>  builtin/for-each-ref.c  |  2 +-
>  builtin/tag.c           |  2 +-
>  ref-filter.c            | 13 +++++-
>  ref-filter.h            |  2 +
>  t/t6300-for-each-ref.sh | 94 ++++++++++++++++++++++++++++++++++++++---
>  6 files changed, 104 insertions(+), 11 deletions(-)
>
> -Peff
Previous: Taylor Blau
Message 21 of 21 in “git for-each-ref - sorting by multiple keys”
  1. climeMay 2, 2020
  2. Jeff KingMay 3, 2020
  3. 1/2 ref-filter: apply --ignore-case to all sorting keysJeff King, May 3, 2020
  4. Danh DoanMay 3, 2020
  5. Jeff KingMay 4, 2020
  6. Junio C HamanoMay 4, 2020
  7. CodingGuidelines: drop arithmetic expansion advice to use "$x"Jeff King, May 4, 2020
  8. Carlo Marcelo Arenas BelónMay 4, 2020
  9. Jeff KingMay 4, 2020
  10. Junio C HamanoMay 4, 2020
  11. Danh DoanMay 4, 2020
  12. Junio C HamanoMay 5, 2020
  13. Jeff KingMay 5, 2020
  14. Junio C HamanoMay 5, 2020
  15. Junio C HamanoMay 4, 2020
  16. Jeff KingMay 5, 2020
  17. Taylor BlauMay 5, 2020
  18. 2/2 ref-filter: apply fallback refname sort only after all user sortsJeff King, May 3, 2020
  19. Junio C HamanoMay 4, 2020
  20. Taylor BlauMay 5, 2020
  21. climeMay 3, 2020

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.