@matheusbsbs / matheus-bagliano / commits / 7dff9b30ea
Fork 0

Support 'raw' date format

Talking about --date, one thing I wanted for the 1234567890 date was to get things in the raw format. Sure, you get them with --pretty=raw, but it felt a bit sad that you couldn't just ask for the date in raw format. So here's a throw-away patch (meaning: I won't be re-sending it, because I really don't think it's a big deal) to add "--date=raw". It just prints out the internal raw git format - seconds since epoch plus timezone (put another way: 'date +"%s %z"' format) Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Linus Torvalds committed Feb 20, 2009 at 14:15 UTC 7dff9b30ea0603fe265f9f7da055fc34f5d57d2f
3 files changed +12 -2
Documentation/rev-list-options.txt
+3 -1
@@ -13,7 +13,7 @@ include::pretty-options.txt[]
13
14 Synonym for `--date=relative`.
15
16 ---date={relative,local,default,iso,rfc,short}::
16 +--date={relative,local,default,iso,rfc,short,raw}::
17
18 Only takes effect for dates shown in human-readable format, such
19 as when using "--pretty". `log.date` config variable sets a default
@@ -31,6 +31,8 @@ format, often found in E-mail messages.
31 +
32 `--date=short` shows only date but not time, in `YYYY-MM-DD` format.
33 +
34 +`--date=raw` shows the date in the internal raw git format `%s %z` format.
35 ++
36 `--date=default` shows timestamps in the original timezone
37 (either committer's or author's).
38
cache.h
+2 -1
@@ -696,7 +696,8 @@ enum date_mode {
696 DATE_SHORT,
697 DATE_LOCAL,
698 DATE_ISO8601,
699 - DATE_RFC2822
699 + DATE_RFC2822,
700 + DATE_RAW
701 };
702
703 const char *show_date(unsigned long time, int timezone, enum date_mode mode);
date.c
+7
@@ -89,6 +89,11 @@ const char *show_date(unsigned long time, int tz, enum date_mode mode)
89 struct tm *tm;
90 static char timebuf[200];
91
92 + if (mode == DATE_RAW) {
93 + snprintf(timebuf, sizeof(timebuf), "%lu %+05d", time, tz);
94 + return timebuf;
95 + }
96 +
97 if (mode == DATE_RELATIVE) {
98 unsigned long diff;
99 struct timeval now;
@@ -615,6 +620,8 @@ enum date_mode parse_date_format(const char *format)
620 return DATE_LOCAL;
621 else if (!strcmp(format, "default"))
622 return DATE_NORMAL;
623 + else if (!strcmp(format, "raw"))
624 + return DATE_RAW;
625 else
626 die("unknown date format %s", format);
627 }