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

[PATCH 4/4] reflog-walk: always make HEAD@{0} show indexed selectors

From
JKJeff King <peff-adepduraxsq@public.gmane.org>
Date
May 4, 2012, 05:27 UTC
Message-ID
<20120504052725.GD16107@sigill.intra.peff.net>
In-Reply-To
<20120504052106.GA15970-bBVMEuqLR+SYVEpFpFwlB0AkDMvbqDRI@public.gmane.org>

When we are showing reflog selectors during a walk, we infer from context whether the user wanted to see the index in each selector, or the reflog date. The current rules are:

  1. if the user asked for an explicit date format in the
     output, show the date
  2. if the user asked for ref@{now}, show the date
  3. if neither is true, show the index

However, if we see "ref@{0}", that should be a strong clue that the user wants to see the counted version. In fact, it should be much stronger than the date format in (1). The user may have been setting the date format to use in another part of the output (e.g., in --format="%gd (%ad)", they may have wanted to influence the author date).

This patch flips the rules to:
  1. if the user asked for ref@{0}, always show the index
  2. if the user asked for ref@{now}, always show the date
  3. otherwise, we have just "ref"; show them counted by
     default, but respect the presence of "--date" as a clue
     that the user wanted them date-based
Signed-off-by: Jeff King <peff-AdEPDUrAXsQ@public.gmane.org>
---
 reflog-walk.c          | 3 ++-
 t/t1411-reflog-show.sh | 8 ++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/reflog-walk.c b/reflog-walk.c
index 3549318..b974258 100644
--- a/reflog-walk.c
+++ b/reflog-walk.c
@@ -276,7 +276,8 @@ void get_reflog_selector(struct strbuf *sb,
 	}
 
 	strbuf_addf(sb, "%s@{", printed_ref);
-	if (commit_reflog->selector == SELECTOR_DATE || dmode) {
+	if (commit_reflog->selector == SELECTOR_DATE ||
+	    (commit_reflog->selector == SELECTOR_NONE && dmode)) {
 		info = &commit_reflog->reflogs->items[commit_reflog->recno+1];
 		strbuf_addstr(sb, show_date(info->timestamp, info->tz, dmode));
 	} else {
diff --git a/t/t1411-reflog-show.sh b/t/t1411-reflog-show.sh
index 88247f8..7d9b5e3 100755
--- a/t/t1411-reflog-show.sh
+++ b/t/t1411-reflog-show.sh
@@ -127,6 +127,14 @@ test_expect_success 'log.date does not invoke "--date" magic (format=%gd)' '
 	test_cmp expect actual
 '
 
+cat >expect <<'EOF'
+HEAD@{0}
+EOF
+test_expect_success '--date magic does not override explicit @{0} syntax' '
+	git log -g -1 --format=%gd --date=raw HEAD@{0} >actual &&
+	test_cmp expect actual
+'
+
 : >expect
 test_expect_success 'empty reflog file' '
 	git branch empty &&
-- 
1.7.10.1.10.ge534bc3
Previous: Jeff KingNext: Junio C Hamano
Message 18 of 26 in “Bug in git-stash(.sh) ?”
  1. Eli BarzilayApr 27, 2012
  2. Junio C HamanoApr 27, 2012
  3. Eli BarzilayApr 28, 2012
  4. Andreas SchwabApr 28, 2012
  5. Yann HodiqueApr 28, 2012
  6. Eli BarzilayApr 28, 2012
  7. Jeff KingApr 29, 2012
  8. Junio C HamanoApr 29, 2012
  9. Eli BarzilayApr 29, 2012
  10. Jeff KingMay 1, 2012
  11. Eli BarzilayApr 29, 2012
  12. Jeff KingMay 1, 2012
  13. [git] Re: Bug in git-stash(.sh) ?Eli Barzilay, May 3, 2012
  14. Jeff KingMay 4, 2012
  15. 3/4 reflog-walk: clean up "flag" field of commit_reflog structJeff King, May 4, 2012
  16. 1/4 t1411: add more selector index/date testsJeff King, May 4, 2012
  17. 2/4 log: respect date_mode_explicit with --format:%gdJeff King, May 4, 2012
  18. 4/4 reflog-walk: always make HEAD@{0} show indexed selectorsJeff King, May 4, 2012
  19. Junio C HamanoMay 4, 2012
  20. Eli BarzilayMay 4, 2012
  21. Eli BarzilayMay 4, 2012
  22. Jeff KingMay 7, 2012
  23. Jeff KingMay 10, 2012
  24. Junio C HamanoMay 10, 2012
  25. OT: gmane address mangling selectorsJeff King, May 10, 2012
  26. Eli BarzilayMay 10, 2012

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.