builtin/blame.c | 1 + cache.h | 3 ++- date.c | 10 +++++++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/builtin/blame.c b/builtin/blame.c index 21f42b0b62b8..4d87181dc6cd 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -2640,6 +2640,7 @@ parse_done: fewer display columns. */ blame_date_width = utf8_strwidth(_("4 years, 11 months ago")) + 1; /* add the null */ break; + case DATE_AUTO: case DATE_NORMAL: blame_date_width = sizeof("Thu Oct 19 16:00:04 2006 -0700"); break; diff --git a/cache.h b/cache.h index 6049f8671138..624817c20414 100644 --- a/cache.h +++ b/cache.h @@ -1223,7 +1223,8 @@ struct date_mode { DATE_ISO8601_STRICT, DATE_RFC2822, DATE_STRFTIME, - DATE_RAW + DATE_RAW, + DATE_AUTO, } type; const char *strftime_fmt; int local; diff --git a/date.c b/date.c index 7c9f76998ac7..c38414a3d968 100644 --- a/date.c +++ b/date.c @@ -184,13 +184,15 @@ const char *show_date(unsigned long time, int tz, const struct date_mode *mode) return timebuf.buf; } - if (mode->type == DATE_RELATIVE) { + if (mode->type == DATE_RELATIVE || mode->type == DATE_AUTO) { struct timeval now; strbuf_reset(&timebuf); gettimeofday(&now, NULL); - show_date_relative(time, tz, &now, &timebuf); - return timebuf.buf; + if (mode->type != DATE_AUTO || time + 24*60*60 > now.tv_sec) { + show_date_relative(time, tz, &now, &timebuf); + return timebuf.buf; + } } tm = time_to_tm(time, tz); @@ -792,6 +794,8 @@ static enum date_mode_type parse_date_type(const char *format, const char **end) return DATE_RAW; if (skip_prefix(format, "format", end)) return DATE_STRFTIME; + if (skip_prefix(format, "auto", end)) + return DATE_AUTO; die("unknown date format %s", format); }