Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit f026c75

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7904af1 commit f026c75

File tree

5 files changed

+7
-2
lines changed

5 files changed

+7
-2
lines changed

builtin/rev-list.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ static void show_commit(struct commit *commit, void *data)
104104
struct pretty_print_context ctx = {0};
105105
ctx.abbrev = revs->abbrev;
106106
ctx.date_mode = revs->date_mode;
107+
ctx.date_mode_explicit = revs->date_mode_explicit;
107108
ctx.fmt = revs->commit_format;
108109
pretty_print_commit(&ctx, commit, &buf);
109110
if (revs->graph) {

commit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ struct pretty_print_context {
8282
const char *after_subject;
8383
int preserve_subject;
8484
enum date_mode date_mode;
85+
unsigned date_mode_explicit:1;
8586
int need_8bit_cte;
8687
int show_notes;
8788
struct reflog_walk_info *reflog_info;

log-tree.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,7 @@ void show_log(struct rev_info *opt)
511511
if (ctx.need_8bit_cte >= 0)
512512
ctx.need_8bit_cte = has_non_ascii(opt->add_signoff);
513513
ctx.date_mode = opt->date_mode;
514+
ctx.date_mode_explicit = opt->date_mode_explicit;
514515
ctx.abbrev = opt->diffopt.abbrev;
515516
ctx.after_subject = extra_headers;
516517
ctx.preserve_subject = opt->preserve_subject;

pretty.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,9 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,
956956
if (c->pretty_ctx->reflog_info)
957957
get_reflog_selector(sb,
958958
c->pretty_ctx->reflog_info,
959-
c->pretty_ctx->date_mode,
959+
c->pretty_ctx->date_mode_explicit ?
960+
c->pretty_ctx->date_mode :
961+
DATE_NORMAL,
960962
(placeholder[1] == 'd'));
961963
return 2;
962964
case 's': /* reflog message */

t/t1411-reflog-show.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ test_expect_success 'log.date does not invoke "--date" magic (oneline)' '
121121
cat >expect <<'EOF'
122122
HEAD@{0}
123123
EOF
124-
test_expect_failure 'log.date does not invoke "--date" magic (format=%gd)' '
124+
test_expect_success 'log.date does not invoke "--date" magic (format=%gd)' '
125125
test_config log.date raw &&
126126
git log -g -1 --format=%gd >actual &&
127127
test_cmp expect actual

0 commit comments

Comments
 (0)