Skip to content

Commit 7dff9b3

Browse files
torvaldsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8c5b85c commit 7dff9b3

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

Documentation/rev-list-options.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ include::pretty-options.txt[]
1313

1414
Synonym for `--date=relative`.
1515

16-
--date={relative,local,default,iso,rfc,short}::
16+
--date={relative,local,default,iso,rfc,short,raw}::
1717

1818
Only takes effect for dates shown in human-readable format, such
1919
as when using "--pretty". `log.date` config variable sets a default
@@ -31,6 +31,8 @@ format, often found in E-mail messages.
3131
+
3232
`--date=short` shows only date but not time, in `YYYY-MM-DD` format.
3333
+
34+
`--date=raw` shows the date in the internal raw git format `%s %z` format.
35+
+
3436
`--date=default` shows timestamps in the original timezone
3537
(either committer's or author's).
3638

cache.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,8 @@ enum date_mode {
696696
DATE_SHORT,
697697
DATE_LOCAL,
698698
DATE_ISO8601,
699-
DATE_RFC2822
699+
DATE_RFC2822,
700+
DATE_RAW
700701
};
701702

702703
const char *show_date(unsigned long time, int timezone, enum date_mode mode);

date.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ const char *show_date(unsigned long time, int tz, enum date_mode mode)
8989
struct tm *tm;
9090
static char timebuf[200];
9191

92+
if (mode == DATE_RAW) {
93+
snprintf(timebuf, sizeof(timebuf), "%lu %+05d", time, tz);
94+
return timebuf;
95+
}
96+
9297
if (mode == DATE_RELATIVE) {
9398
unsigned long diff;
9499
struct timeval now;
@@ -615,6 +620,8 @@ enum date_mode parse_date_format(const char *format)
615620
return DATE_LOCAL;
616621
else if (!strcmp(format, "default"))
617622
return DATE_NORMAL;
623+
else if (!strcmp(format, "raw"))
624+
return DATE_RAW;
618625
else
619626
die("unknown date format %s", format);
620627
}

0 commit comments

Comments
 (0)