From 7904af1c10d2feb2f6d1dcb22454d93168a88c49 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 4 May 2012 01:23:14 -0400 Subject: t1411: add more selector index/date tests We already check that @{now} and "--date" cause the displayed selector to use the date for both the multiline and oneline formats. However, we miss several cases: 1. The --format=%gd selector is not tested at all. 2. We do not check how the log.date config interacts with the "--date" magic (according to f4ea32f, it should not impact the output). Doing so reveals that the combination of both (log.date combined with the %gd format) does not behave as expected. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/t1411-reflog-show.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 't') diff --git a/t/t1411-reflog-show.sh b/t/t1411-reflog-show.sh index caa687b5b4..4706f4c50c 100755 --- a/t/t1411-reflog-show.sh +++ b/t/t1411-reflog-show.sh @@ -64,6 +64,14 @@ test_expect_success 'using @{now} syntax shows reflog date (oneline)' ' test_cmp expect actual ' +cat >expect <<'EOF' +HEAD@{Thu Apr 7 15:13:13 2005 -0700} +EOF +test_expect_success 'using @{now} syntax shows reflog date (format=%gd)' ' + git log -g -1 --format=%gd HEAD@{now} >actual && + test_cmp expect actual +' + cat >expect <<'EOF' Reflog: HEAD@{1112911993 -0700} (C O Mitter ) Reflog message: commit (initial): one @@ -82,6 +90,43 @@ test_expect_success 'using --date= shows reflog date (oneline)' ' test_cmp expect actual ' +cat >expect <<'EOF' +HEAD@{1112911993 -0700} +EOF +test_expect_success 'using --date= shows reflog date (format=%gd)' ' + git log -g -1 --format=%gd --date=raw >actual && + test_cmp expect actual +' + +cat >expect <<'EOF' +Reflog: HEAD@{0} (C O Mitter ) +Reflog message: commit (initial): one +EOF +test_expect_success 'log.date does not invoke "--date" magic (multiline)' ' + test_config log.date raw && + git log -g -1 >tmp && + grep ^Reflog actual && + test_cmp expect actual +' + +cat >expect <<'EOF' +e46513e HEAD@{0}: commit (initial): one +EOF +test_expect_success 'log.date does not invoke "--date" magic (oneline)' ' + test_config log.date raw && + git log -g -1 --oneline >actual && + test_cmp expect actual +' + +cat >expect <<'EOF' +HEAD@{0} +EOF +test_expect_failure 'log.date does not invoke "--date" magic (format=%gd)' ' + test_config log.date raw && + git log -g -1 --format=%gd >actual && + test_cmp expect actual +' + : >expect test_expect_success 'empty reflog file' ' git branch empty && -- cgit v1.2.3 From f026c7563a249da9279e664fed16fcd5f55c62db Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 4 May 2012 01:25:18 -0400 Subject: log: respect date_mode_explicit with --format:%gd When we show a reflog selector (e.g., via "git log -g"), we perform some DWIM magic: while we normally show the entry's index (e.g., HEAD@{1}), if the user has given us a date with "--date", then we show a date-based select (e.g., HEAD@{yesterday}). However, we don't want to trigger this magic if the alternate date format we got was from the "log.date" configuration; that is not sufficiently strong context for us to invoke this particular magic. To fix this, commit f4ea32f (improve reflog date/number heuristic, 2009-09-24) introduced a "date_mode_explicit" flag in rev_info. This flag is set only when we see a "--date" option on the command line, and we a vanilla date to the reflog code if the date was not explicit. Later, commit 8f8f547 (Introduce new pretty formats %g[sdD] for reflog information, 2009-10-19) added another way to show selectors, and it did not respect the date_mode_explicit flag from f4ea32f. This patch propagates the date_mode_explicit flag to the pretty-print code, which can then use it to pass the appropriate date field to the reflog code. This brings the behavior of "%gd" in line with the other formats, and means that its output is independent of any user configuration. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/t1411-reflog-show.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't') diff --git a/t/t1411-reflog-show.sh b/t/t1411-reflog-show.sh index 4706f4c50c..88247f874e 100755 --- a/t/t1411-reflog-show.sh +++ b/t/t1411-reflog-show.sh @@ -121,7 +121,7 @@ test_expect_success 'log.date does not invoke "--date" magic (oneline)' ' cat >expect <<'EOF' HEAD@{0} EOF -test_expect_failure 'log.date does not invoke "--date" magic (format=%gd)' ' +test_expect_success 'log.date does not invoke "--date" magic (format=%gd)' ' test_config log.date raw && git log -g -1 --format=%gd >actual && test_cmp expect actual -- cgit v1.2.3 From 794151e9b595ddc2700c0801caabfd27be763e12 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 4 May 2012 01:27:25 -0400 Subject: reflog-walk: always make HEAD@{0} show indexed selectors 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 Signed-off-by: Junio C Hamano --- t/t1411-reflog-show.sh | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 't') diff --git a/t/t1411-reflog-show.sh b/t/t1411-reflog-show.sh index 88247f874e..7d9b5e33df 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 && -- cgit v1.2.3 From 55ccf85a524f6a2d8cb5582d80a2927ff11dfb64 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 7 May 2012 14:11:32 -0700 Subject: reflog-walk: tell explicit --date=default from not having --date at all Introduction of opt->date_mode_explicit was a step in the right direction, but lost that crucial bit at the very end of the callchain, and the callee could not tell an explicitly specified "I want *date* but in default format" from the built-in default value passed when there was no --date specified. Signed-off-by: Junio C Hamano --- t/t1411-reflog-show.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 't') diff --git a/t/t1411-reflog-show.sh b/t/t1411-reflog-show.sh index 7d9b5e33df..9a105fe21f 100755 --- a/t/t1411-reflog-show.sh +++ b/t/t1411-reflog-show.sh @@ -73,20 +73,20 @@ test_expect_success 'using @{now} syntax shows reflog date (format=%gd)' ' ' cat >expect <<'EOF' -Reflog: HEAD@{1112911993 -0700} (C O Mitter ) +Reflog: HEAD@{Thu Apr 7 15:13:13 2005 -0700} (C O Mitter ) Reflog message: commit (initial): one EOF test_expect_success 'using --date= shows reflog date (multiline)' ' - git log -g -1 --date=raw >tmp && + git log -g -1 --date=default >tmp && grep ^Reflog actual && test_cmp expect actual ' cat >expect <<'EOF' -e46513e HEAD@{1112911993 -0700}: commit (initial): one +e46513e HEAD@{Thu Apr 7 15:13:13 2005 -0700}: commit (initial): one EOF test_expect_success 'using --date= shows reflog date (oneline)' ' - git log -g -1 --oneline --date=raw >actual && + git log -g -1 --oneline --date=default >actual && test_cmp expect actual ' -- cgit v1.2.3