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

Re: [PATCH] for-each-ref: delay parsing of --sort=<atom> options

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 20, 2021, 21:32 UTC
Message-ID
<xmqqpmrzo00q.fsf@gitster.g>
In-Reply-To
<YXCAuAwZenM6EPug@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
> Yeah, I faced something similar with 7c5045fc18 (ref-filter: apply
> fallback refname sort only after all user sorts, 2020-05-03). I suspect
> you could use the same keys as those tests, though I am OK if we simply
> leave it as a quietly-fixed bug.
Ah, I guess I can cheat and add a new test after these.

If --no-sort weren't taking effect, the expected outcome would be the asme as the previous step this copied from, but with --no-sort clearing the sort keys, we sort by taggerdate and then tiebreak with the refname, and taggeremail does not get into the picture (other than being repeated at the end of the refname).

 t/t6300-for-each-ref.sh | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
diff --git c/t/t6300-for-each-ref.sh w/t/t6300-for-each-ref.sh
index 83921502a4..9f2c706c12 100755
--- c/t/t6300-for-each-ref.sh
+++ w/t/t6300-for-each-ref.sh
@@ -1024,6 +1024,27 @@ test_expect_success 'equivalent sorts fall back on refname' '
 	test_cmp expected actual
 '
 
+test_expect_success '--no-sort cancels the previous sort keys' '
+	cat >expected <<-\EOF &&
+	100000 <user1@example.com> refs/tags/multi-ref1-100000-user1
+	100000 <user2@example.com> refs/tags/multi-ref1-100000-user2
+	100000 <user1@example.com> refs/tags/multi-ref2-100000-user1
+	100000 <user2@example.com> refs/tags/multi-ref2-100000-user2
+	200000 <user1@example.com> refs/tags/multi-ref1-200000-user1
+	200000 <user2@example.com> refs/tags/multi-ref1-200000-user2
+	200000 <user1@example.com> refs/tags/multi-ref2-200000-user1
+	200000 <user2@example.com> refs/tags/multi-ref2-200000-user2
+	EOF
+	git for-each-ref \
+		--format="%(taggerdate:unix) %(taggeremail) %(refname)" \
+		--sort=-refname \
+		--sort=taggeremail \
+		--no-sort \
+		--sort=taggerdate \
+		"refs/tags/multi-*" >actual &&
+	test_cmp expected actual
+'
+
 test_expect_success 'do not dereference NULL upon %(HEAD) on unborn branch' '
 	test_when_finished "git checkout main" &&
 	git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual &&
Previous: Jeff KingNext: Jeff King
Message 19 of 20 in “for-each-ref: delay parsing of --sort=<atom> options”
  1. for-each-ref: delay parsing of --sort=<atom> optionsJunio C Hamano, Oct 18, 2021
  2. Jeff KingOct 19, 2021
  3. Jeff KingOct 20, 2021
  4. Ævar Arnfjörð BjarmasonOct 20, 2021
  5. 0/4 for-each-ref: delay parsing of --sort=<atom> options + linux-leaks fixesÆvar Arnfjörð Bjarmason, Oct 20, 2021
  6. 1/4 tag: use a "goto cleanup" pattern, leak less memoryÆvar Arnfjörð Bjarmason, Oct 20, 2021
  7. Junio C HamanoOct 20, 2021
  8. 2/4 ref-filter API user: add and use a ref_sorting_release()Ævar Arnfjörð Bjarmason, Oct 20, 2021
  9. Junio C HamanoOct 20, 2021
  10. 3/4 for-each-ref: delay parsing of --sort=<atom> optionsÆvar Arnfjörð Bjarmason, Oct 20, 2021
  11. 4/4 branch: use ref_sorting_release()Ævar Arnfjörð Bjarmason, Oct 20, 2021
  12. Junio C HamanoOct 20, 2021
  13. 0/3 ref-filter: add a ref_sorting_release()Ævar Arnfjörð Bjarmason, Oct 20, 2021
  14. 1/3 tag: use a "goto cleanup" pattern, leak less memoryÆvar Arnfjörð Bjarmason, Oct 20, 2021
  15. 2/3 ref-filter API user: add and use a ref_sorting_release()Ævar Arnfjörð Bjarmason, Oct 20, 2021
  16. 3/3 branch: use ref_sorting_release()Ævar Arnfjörð Bjarmason, Oct 20, 2021
  17. Junio C HamanoOct 20, 2021
  18. Jeff KingOct 20, 2021
  19. Junio C HamanoOct 20, 2021
  20. Jeff KingOct 21, 2021

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.