diff options
-rw-r--r-- | Documentation/rev-list-options.txt | 4 | ||||
-rw-r--r-- | builtin/blame.c | 3 | ||||
-rw-r--r-- | cache.h | 3 | ||||
-rw-r--r-- | date.c | 8 | ||||
-rwxr-xr-x | t/t0006-date.sh | 2 |
5 files changed, 19 insertions, 1 deletions
diff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt index 9215534afa..fd86ed12dc 100644 --- a/Documentation/rev-list-options.txt +++ b/Documentation/rev-list-options.txt @@ -751,6 +751,10 @@ Note that the `-local` option does not affect the seconds-since-epoch value (which is always measured in UTC), but does switch the accompanying timezone value. + +`--date=unix` shows the date as a Unix epoch timestamp (seconds since +1970). As with `--raw`, this is always in UTC and therefore `-local` +has no effect. ++ `--date=format:...` feeds the format `...` to your system `strftime`. Use `--date=format:%c` to show the date in your system locale's preferred format. See the `strftime` manual for a complete list of diff --git a/builtin/blame.c b/builtin/blame.c index 7417edf6ef..002e70f9b5 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -2626,6 +2626,9 @@ parse_done: case DATE_RAW: blame_date_width = sizeof("1161298804 -0700"); break; + case DATE_UNIX: + blame_date_width = sizeof("1161298804"); + break; case DATE_SHORT: blame_date_width = sizeof("2006-10-19"); break; @@ -1223,7 +1223,8 @@ struct date_mode { DATE_ISO8601_STRICT, DATE_RFC2822, DATE_STRFTIME, - DATE_RAW + DATE_RAW, + DATE_UNIX } type; const char *strftime_fmt; int local; @@ -177,6 +177,12 @@ const char *show_date(unsigned long time, int tz, const struct date_mode *mode) struct tm *tm; static struct strbuf timebuf = STRBUF_INIT; + if (mode->type == DATE_UNIX) { + strbuf_reset(&timebuf); + strbuf_addf(&timebuf, "%lu", time); + return timebuf.buf; + } + if (mode->local) tz = local_tzoffset(time); @@ -792,6 +798,8 @@ static enum date_mode_type parse_date_type(const char *format, const char **end) return DATE_NORMAL; if (skip_prefix(format, "raw", end)) return DATE_RAW; + if (skip_prefix(format, "unix", end)) + return DATE_UNIX; if (skip_prefix(format, "format", end)) return DATE_STRFTIME; diff --git a/t/t0006-date.sh b/t/t0006-date.sh index 482fec0d7e..c0c910867d 100755 --- a/t/t0006-date.sh +++ b/t/t0006-date.sh @@ -46,8 +46,10 @@ check_show rfc2822 "$TIME" 'Wed, 15 Jun 2016 16:13:20 +0200' check_show short "$TIME" '2016-06-15' check_show default "$TIME" 'Wed Jun 15 16:13:20 2016 +0200' check_show raw "$TIME" '1466000000 +0200' +check_show unix "$TIME" '1466000000' check_show iso-local "$TIME" '2016-06-15 14:13:20 +0000' check_show raw-local "$TIME" '1466000000 +0000' +check_show unix-local "$TIME" '1466000000' # arbitrary time absurdly far in the future FUTURE="5758122296 -0400" |