Skip to content

Commit ee8f838

Browse files
robinrosenberggitster
authored andcommitted
Support output ISO 8601 format dates
Support output of full ISO 8601 style dates in e.g. git log and other places that use interpolation for formatting. Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent d60a6a6 commit ee8f838

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

Documentation/pretty-formats.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,14 @@ The placeholders are:
106106
- '%aD': author date, RFC2822 style
107107
- '%ar': author date, relative
108108
- '%at': author date, UNIX timestamp
109+
- '%ai': author date, ISO 8601 format
109110
- '%cn': committer name
110111
- '%ce': committer email
111112
- '%cd': committer date
112113
- '%cD': committer date, RFC2822 style
113114
- '%cr': committer date, relative
114115
- '%ct': committer date, UNIX timestamp
116+
- '%ci': committer date, ISO 8601 format
115117
- '%e': encoding
116118
- '%s': subject
117119
- '%b': body

cache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ extern void *read_object_with_reference(const unsigned char *sha1,
409409
unsigned long *size,
410410
unsigned char *sha1_ret);
411411

412-
enum date_mode { DATE_NORMAL = 0, DATE_RELATIVE, DATE_SHORT, DATE_LOCAL };
412+
enum date_mode { DATE_NORMAL = 0, DATE_RELATIVE, DATE_SHORT, DATE_LOCAL, DATE_ISO8601 };
413413
const char *show_date(unsigned long time, int timezone, enum date_mode mode);
414414
const char *show_rfc2822_date(unsigned long time, int timezone);
415415
int parse_date(const char *date, char *buf, int bufsize);

commit.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,7 @@ static void fill_person(struct interp *table, const char *msg, int len)
781781
interp_set_entry(table, 2, show_date(date, tz, 0));
782782
interp_set_entry(table, 3, show_rfc2822_date(date, tz));
783783
interp_set_entry(table, 4, show_date(date, tz, 1));
784+
interp_set_entry(table, 6, show_date(date, tz, DATE_ISO8601));
784785
}
785786

786787
static long format_commit_message(const struct commit *commit,
@@ -799,12 +800,14 @@ static long format_commit_message(const struct commit *commit,
799800
{ "%aD" }, /* author date, RFC2822 style */
800801
{ "%ar" }, /* author date, relative */
801802
{ "%at" }, /* author date, UNIX timestamp */
803+
{ "%ai" }, /* author date, ISO 8601 */
802804
{ "%cn" }, /* committer name */
803805
{ "%ce" }, /* committer email */
804806
{ "%cd" }, /* committer date */
805807
{ "%cD" }, /* committer date, RFC2822 style */
806808
{ "%cr" }, /* committer date, relative */
807809
{ "%ct" }, /* committer date, UNIX timestamp */
810+
{ "%ci" }, /* committer date, ISO 8601 */
808811
{ "%e" }, /* encoding */
809812
{ "%s" }, /* subject */
810813
{ "%b" }, /* body */
@@ -821,10 +824,11 @@ static long format_commit_message(const struct commit *commit,
821824
IPARENTS, IPARENTS_ABBREV,
822825
IAUTHOR_NAME, IAUTHOR_EMAIL,
823826
IAUTHOR_DATE, IAUTHOR_DATE_RFC2822, IAUTHOR_DATE_RELATIVE,
824-
IAUTHOR_TIMESTAMP,
827+
IAUTHOR_TIMESTAMP, IAUTHOR_ISO8601,
825828
ICOMMITTER_NAME, ICOMMITTER_EMAIL,
826829
ICOMMITTER_DATE, ICOMMITTER_DATE_RFC2822,
827830
ICOMMITTER_DATE_RELATIVE, ICOMMITTER_TIMESTAMP,
831+
ICOMMITTER_ISO8601,
828832
IENCODING,
829833
ISUBJECT,
830834
IBODY,

date.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,13 @@ const char *show_date(unsigned long time, int tz, enum date_mode mode)
137137
if (mode == DATE_SHORT)
138138
sprintf(timebuf, "%04d-%02d-%02d", tm->tm_year + 1900,
139139
tm->tm_mon + 1, tm->tm_mday);
140+
else if (mode == DATE_ISO8601)
141+
sprintf(timebuf, "%04d-%02d-%02d %02d:%02d:%02d %+05d",
142+
tm->tm_year + 1900,
143+
tm->tm_mon + 1,
144+
tm->tm_mday,
145+
tm->tm_hour, tm->tm_min, tm->tm_sec,
146+
tz);
140147
else
141148
sprintf(timebuf, "%.3s %.3s %d %02d:%02d:%02d %d%c%+05d",
142149
weekday_names[tm->tm_wday],

0 commit comments

Comments
 (0)