convert "enum date_mode" into a struct

In preparation for adding date modes that may carry extra information beyond the mode itself, this patch converts the date_mode enum into a struct. Most of the conversion is fairly straightforward; we pass the struct as a pointer and dereference the type field where necessary. Locations that declare a date_mode can use a "{}" constructor. However, the tricky case is where we use the enum labels as constants, like: show_date(t, tz, DATE_NORMAL); Ideally we could say: show_date(t, tz, &{ DATE_NORMAL }); but of course C does not allow that. Likewise, we cannot cast the constant to a struct, because we need to pass an actual address. Our options are basically: 1. Manually add a "struct date_mode d = { DATE_NORMAL }" definition to each caller, and pass "&d". This makes the callers uglier, because they sometimes do not even have their own scope (e.g., they are inside a switch statement). 2. Provide a pre-made global "date_normal" struct that can be passed by address. We'd also need "date_rfc2822", "date_iso8601", and so forth. But at least the ugliness is defined in one place. 3. Provide a wrapper that generates the correct struct on the fly. The big downside is that we end up pointing to a single global, which makes our wrapper non-reentrant. But show_date is already not reentrant, so it does not matter. This patch implements 3, along with a minor macro to keep the size of the callers sane. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Jun 25, 2015 at 12:55 UTC a5481a6c9438cbd9c246cfa59ff49c31a0926fb6
23 files changed +97 -77
archive.c
+1 -1
@@ -33,7 +33,7 @@ static void format_subst(const struct commit *commit,
33 char *to_free = NULL;
34 struct strbuf fmt = STRBUF_INIT;
35 struct pretty_print_context ctx = {0};
36 - ctx.date_mode = DATE_NORMAL;
36 + ctx.date_mode.type = DATE_NORMAL;
37 ctx.abbrev = DEFAULT_ABBREV;
38
39 if (src == buf->buf)
builtin/blame.c
+5 -5
@@ -50,7 +50,7 @@ static int xdl_opts;
50 static int abbrev = -1;
51 static int no_whole_file_rename;
52
53 -static enum date_mode blame_date_mode = DATE_ISO8601;
53 +static struct date_mode blame_date_mode = { DATE_ISO8601 };
54 static size_t blame_date_width;
55
56 static struct string_list mailmap;
@@ -1827,7 +1827,7 @@ static const char *format_time(unsigned long time, const char *tz_str,
1827 size_t time_width;
1828 int tz;
1829 tz = atoi(tz_str);
1830 - time_str = show_date(time, tz, blame_date_mode);
1830 + time_str = show_date(time, tz, &blame_date_mode);
1831 strbuf_addstr(&time_buf, time_str);
1832 /*
1833 * Add space paddings to time_buf to display a fixed width
@@ -2187,7 +2187,7 @@ static int git_blame_config(const char *var, const char *value, void *cb)
2187 if (!strcmp(var, "blame.date")) {
2188 if (!value)
2189 return config_error_nonbool(var);
2190 - blame_date_mode = parse_date_format(value);
2190 + parse_date_format(value, &blame_date_mode);
2191 return 0;
2192 }
2193
@@ -2569,13 +2569,13 @@ parse_done:
2569
2570 if (cmd_is_annotate) {
2571 output_option |= OUTPUT_ANNOTATE_COMPAT;
2572 - blame_date_mode = DATE_ISO8601;
2572 + blame_date_mode.type = DATE_ISO8601;
2573 } else {
2574 blame_date_mode = revs.date_mode;
2575 }
2576
2577 /* The maximum width used to show the dates */
2578 - switch (blame_date_mode) {
2578 + switch (blame_date_mode.type) {
2579 case DATE_RFC2822:
2580 blame_date_width = sizeof("Thu, 19 Oct 2006 16:00:04 -0700");
2581 break;
builtin/commit.c
+2 -2
@@ -856,7 +856,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
856 _("%s"
857 "Date: %s"),
858 ident_shown++ ? "" : "\n",
859 - show_ident_date(&ai, DATE_NORMAL));
859 + show_ident_date(&ai, DATE_MODE(NORMAL)));
860
861 if (!committer_ident_sufficiently_given())
862 status_printf_ln(s, GIT_COLOR_NORMAL,
@@ -1046,7 +1046,7 @@ static const char *find_author_by_nickname(const char *name)
1046 commit = get_revision(&revs);
1047 if (commit) {
1048 struct pretty_print_context ctx = {0};
1049 - ctx.date_mode = DATE_NORMAL;
1049 + ctx.date_mode.type = DATE_NORMAL;
1050 strbuf_release(&buf);
1051 format_commit_message(commit, "%aN <%aE>", &buf, &ctx);
1052 clear_mailmap(&mailmap);
builtin/for-each-ref.c
+3 -3
@@ -389,7 +389,7 @@ static void grab_date(const char *buf, struct atom_value *v, const char *atomnam
389 char *zone;
390 unsigned long timestamp;
391 long tz;
392 - enum date_mode date_mode = DATE_NORMAL;
392 + struct date_mode date_mode = { DATE_NORMAL };
393 const char *formatp;
394
395 /*
@@ -401,7 +401,7 @@ static void grab_date(const char *buf, struct atom_value *v, const char *atomnam
401 formatp = strchr(atomname, ':');
402 if (formatp != NULL) {
403 formatp++;
404 - date_mode = parse_date_format(formatp);
404 + parse_date_format(formatp, &date_mode);
405 }
406
407 if (!eoemail)
@@ -412,7 +412,7 @@ static void grab_date(const char *buf, struct atom_value *v, const char *atomnam
412 tz = strtol(zone, NULL, 10);
413 if ((tz == LONG_MIN || tz == LONG_MAX) && errno == ERANGE)
414 goto bad;
415 - v->s = xstrdup(show_date(timestamp, tz, date_mode));
415 + v->s = xstrdup(show_date(timestamp, tz, &date_mode));
416 v->ul = timestamp;
417 return;
418 bad:
builtin/log.c
+2 -2
@@ -112,7 +112,7 @@ static void cmd_log_init_defaults(struct rev_info *rev)
112 DIFF_OPT_SET(&rev->diffopt, ALLOW_TEXTCONV);
113
114 if (default_date_mode)
115 - rev->date_mode = parse_date_format(default_date_mode);
115 + parse_date_format(default_date_mode, &rev->date_mode);
116 rev->diffopt.touched_flags = 0;
117 }
118
@@ -939,7 +939,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
939
940 msg = body;
941 pp.fmt = CMIT_FMT_EMAIL;
942 - pp.date_mode = DATE_RFC2822;
942 + pp.date_mode.type = DATE_RFC2822;
943 pp_user_info(&pp, NULL, &sb, committer, encoding);
944 pp_title_line(&pp, &msg, &sb, encoding, need_8bit_cte);
945 pp_remainder(&pp, &msg, &sb, 0);
builtin/shortlog.c
+1 -1
@@ -138,7 +138,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
138 ctx.abbrev = log->abbrev;
139 ctx.subject = "";
140 ctx.after_subject = "";
141 - ctx.date_mode = DATE_NORMAL;
141 + ctx.date_mode.type = DATE_NORMAL;
142 ctx.output_encoding = get_log_output_encoding();
143 pretty_print_commit(&ctx, commit, &ufbuf);
144 buffer = ufbuf.buf;
builtin/show-branch.c
+2 -1
@@ -784,7 +784,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
784 else
785 msg++;
786 reflog_msg[i] = xstrfmt("(%s) %s",
787 - show_date(timestamp, tz, DATE_RELATIVE),
787 + show_date(timestamp, tz,
788 + DATE_MODE(RELATIVE)),
789 msg);
790 free(logmsg);
791 sprintf(nth_desc, "%s@{%d}", *av, base+i);
cache.h
+23 -12
@@ -1105,18 +1105,28 @@ extern void *read_object_with_reference(const unsigned char *sha1,
1105 extern struct object *peel_to_type(const char *name, int namelen,
1106 struct object *o, enum object_type);
1107
1108 -enum date_mode {
1109 - DATE_NORMAL = 0,
1110 - DATE_RELATIVE,
1111 - DATE_SHORT,
1112 - DATE_LOCAL,
1113 - DATE_ISO8601,
1114 - DATE_ISO8601_STRICT,
1115 - DATE_RFC2822,
1116 - DATE_RAW
1108 +struct date_mode {
1109 + enum date_mode_type {
1110 + DATE_NORMAL = 0,
1111 + DATE_RELATIVE,
1112 + DATE_SHORT,
1113 + DATE_LOCAL,
1114 + DATE_ISO8601,
1115 + DATE_ISO8601_STRICT,
1116 + DATE_RFC2822,
1117 + DATE_RAW
1118 + } type;
1119 };
1120
1119 -const char *show_date(unsigned long time, int timezone, enum date_mode mode);
1121 +/*
1122 + * Convenience helper for passing a constant type, like:
1123 + *
1124 + * show_date(t, tz, DATE_MODE(NORMAL));
1125 + */
1126 +#define DATE_MODE(t) date_mode_from_type(DATE_##t)
1127 +struct date_mode *date_mode_from_type(enum date_mode_type type);
1128 +
1129 +const char *show_date(unsigned long time, int timezone, const struct date_mode *mode);
1130 void show_date_relative(unsigned long time, int tz, const struct timeval *now,
1131 struct strbuf *timebuf);
1132 int parse_date(const char *date, struct strbuf *out);
@@ -1126,7 +1136,7 @@ void datestamp(struct strbuf *out);
1136 #define approxidate(s) approxidate_careful((s), NULL)
1137 unsigned long approxidate_careful(const char *, int *);
1138 unsigned long approxidate_relative(const char *date, const struct timeval *now);
1129 -enum date_mode parse_date_format(const char *format);
1139 +void parse_date_format(const char *format, struct date_mode *mode);
1140 int date_overflows(unsigned long date);
1141
1142 #define IDENT_STRICT 1
@@ -1163,7 +1173,8 @@ extern int split_ident_line(struct ident_split *, const char *, int);
1173 * the ident_split. It will also sanity-check the values and produce
1174 * a well-known sentinel date if they appear bogus.
1175 */
1166 -const char *show_ident_date(const struct ident_split *id, enum date_mode mode);
1176 +const char *show_ident_date(const struct ident_split *id,
1177 + const struct date_mode *mode);
1178
1179 /*
1180 * Compare split idents for equality or strict ordering. Note that we
commit.h
+1 -1
@@ -145,7 +145,7 @@ struct pretty_print_context {
145 const char *subject;
146 const char *after_subject;
147 int preserve_subject;
148 - enum date_mode date_mode;
148 + struct date_mode date_mode;
149 unsigned date_mode_explicit:1;
150 int need_8bit_cte;
151 char *notes_message;
date.c
+25 -18
@@ -160,18 +160,25 @@ void show_date_relative(unsigned long time, int tz,
160 (diff + 183) / 365);
161 }
162
163 -const char *show_date(unsigned long time, int tz, enum date_mode mode)
163 +struct date_mode *date_mode_from_type(enum date_mode_type type)
164 +{
165 + static struct date_mode mode;
166 + mode.type = type;
167 + return &mode;
168 +}
169 +
170 +const char *show_date(unsigned long time, int tz, const struct date_mode *mode)
171 {
172 struct tm *tm;
173 static struct strbuf timebuf = STRBUF_INIT;
174
168 - if (mode == DATE_RAW) {
175 + if (mode->type == DATE_RAW) {
176 strbuf_reset(&timebuf);
177 strbuf_addf(&timebuf, "%lu %+05d", time, tz);
178 return timebuf.buf;
179 }
180
174 - if (mode == DATE_RELATIVE) {
181 + if (mode->type == DATE_RELATIVE) {
182 struct timeval now;
183
184 strbuf_reset(&timebuf);
@@ -180,7 +187,7 @@ const char *show_date(unsigned long time, int tz, enum date_mode mode)
187 return timebuf.buf;
188 }
189
183 - if (mode == DATE_LOCAL)
190 + if (mode->type == DATE_LOCAL)
191 tz = local_tzoffset(time);
192
193 tm = time_to_tm(time, tz);
@@ -190,17 +197,17 @@ const char *show_date(unsigned long time, int tz, enum date_mode mode)
197 }
198
199 strbuf_reset(&timebuf);
193 - if (mode == DATE_SHORT)
200 + if (mode->type == DATE_SHORT)
201 strbuf_addf(&timebuf, "%04d-%02d-%02d", tm->tm_year + 1900,
202 tm->tm_mon + 1, tm->tm_mday);
196 - else if (mode == DATE_ISO8601)
203 + else if (mode->type == DATE_ISO8601)
204 strbuf_addf(&timebuf, "%04d-%02d-%02d %02d:%02d:%02d %+05d",
205 tm->tm_year + 1900,
206 tm->tm_mon + 1,
207 tm->tm_mday,
208 tm->tm_hour, tm->tm_min, tm->tm_sec,
209 tz);
203 - else if (mode == DATE_ISO8601_STRICT) {
210 + else if (mode->type == DATE_ISO8601_STRICT) {
211 char sign = (tz >= 0) ? '+' : '-';
212 tz = abs(tz);
213 strbuf_addf(&timebuf, "%04d-%02d-%02dT%02d:%02d:%02d%c%02d:%02d",
@@ -209,7 +216,7 @@ const char *show_date(unsigned long time, int tz, enum date_mode mode)
216 tm->tm_mday,
217 tm->tm_hour, tm->tm_min, tm->tm_sec,
218 sign, tz / 100, tz % 100);
212 - } else if (mode == DATE_RFC2822)
219 + } else if (mode->type == DATE_RFC2822)
220 strbuf_addf(&timebuf, "%.3s, %d %.3s %d %02d:%02d:%02d %+05d",
221 weekday_names[tm->tm_wday], tm->tm_mday,
222 month_names[tm->tm_mon], tm->tm_year + 1900,
@@ -221,7 +228,7 @@ const char *show_date(unsigned long time, int tz, enum date_mode mode)
228 tm->tm_mday,
229 tm->tm_hour, tm->tm_min, tm->tm_sec,
230 tm->tm_year + 1900,
224 - (mode == DATE_LOCAL) ? 0 : ' ',
231 + (mode->type == DATE_LOCAL) ? 0 : ' ',
232 tz);
233 return timebuf.buf;
234 }
@@ -759,27 +766,27 @@ int parse_date(const char *date, struct strbuf *result)
766 return 0;
767 }
768
762 -enum date_mode parse_date_format(const char *format)
769 +void parse_date_format(const char *format, struct date_mode *mode)
770 {
771 if (!strcmp(format, "relative"))
765 - return DATE_RELATIVE;
772 + mode->type = DATE_RELATIVE;
773 else if (!strcmp(format, "iso8601") ||
774 !strcmp(format, "iso"))
768 - return DATE_ISO8601;
775 + mode->type = DATE_ISO8601;
776 else if (!strcmp(format, "iso8601-strict") ||
777 !strcmp(format, "iso-strict"))
771 - return DATE_ISO8601_STRICT;
778 + mode->type = DATE_ISO8601_STRICT;
779 else if (!strcmp(format, "rfc2822") ||
780 !strcmp(format, "rfc"))
774 - return DATE_RFC2822;
781 + mode->type = DATE_RFC2822;
782 else if (!strcmp(format, "short"))
776 - return DATE_SHORT;
783 + mode->type = DATE_SHORT;
784 else if (!strcmp(format, "local"))
778 - return DATE_LOCAL;
785 + mode->type = DATE_LOCAL;
786 else if (!strcmp(format, "default"))
780 - return DATE_NORMAL;
787 + mode->type = DATE_NORMAL;
788 else if (!strcmp(format, "raw"))
782 - return DATE_RAW;
789 + mode->type = DATE_RAW;
790 else
791 die("unknown date format %s", format);
792 }
fast-import.c
+1 -1
@@ -421,7 +421,7 @@ static void write_crash_report(const char *err)
421 fprintf(rpt, "fast-import crash report:\n");
422 fprintf(rpt, " fast-import process: %"PRIuMAX"\n", (uintmax_t) getpid());
423 fprintf(rpt, " parent process : %"PRIuMAX"\n", (uintmax_t) getppid());
424 - fprintf(rpt, " at %s\n", show_date(time(NULL), 0, DATE_LOCAL));
424 + fprintf(rpt, " at %s\n", show_date(time(NULL), 0, DATE_MODE(LOCAL)));
425 fputc('\n', rpt);
426
427 fputs("fatal: ", rpt);
http-backend.c
+1 -1
@@ -92,7 +92,7 @@ static void hdr_int(const char *name, uintmax_t value)
92
93 static void hdr_date(const char *name, unsigned long when)
94 {
95 - const char *value = show_date(when, 0, DATE_RFC2822);
95 + const char *value = show_date(when, 0, DATE_MODE(RFC2822));
96 hdr_str(name, value);
97 }
98
log-tree.c
+1 -1
@@ -639,7 +639,7 @@ void show_log(struct rev_info *opt)
639 */
640 show_reflog_message(opt->reflog_info,
641 opt->commit_format == CMIT_FMT_ONELINE,
642 - opt->date_mode,
642 + &opt->date_mode,
643 opt->date_mode_explicit);
644 if (opt->commit_format == CMIT_FMT_ONELINE)
645 return;
pretty.c
+15 -14
@@ -399,7 +399,7 @@ static void add_rfc2047(struct strbuf *sb, const char *line, size_t len,
399 }
400
401 const char *show_ident_date(const struct ident_split *ident,
402 - enum date_mode mode)
402 + const struct date_mode *mode)
403 {
404 unsigned long date = 0;
405 long tz = 0;
@@ -489,15 +489,15 @@ void pp_user_info(struct pretty_print_context *pp,
489 switch (pp->fmt) {
490 case CMIT_FMT_MEDIUM:
491 strbuf_addf(sb, "Date: %s\n",
492 - show_ident_date(&ident, pp->date_mode));
492 + show_ident_date(&ident, &pp->date_mode));
493 break;
494 case CMIT_FMT_EMAIL:
495 strbuf_addf(sb, "Date: %s\n",
496 - show_ident_date(&ident, DATE_RFC2822));
496 + show_ident_date(&ident, DATE_MODE(RFC2822)));
497 break;
498 case CMIT_FMT_FULLER:
499 strbuf_addf(sb, "%sDate: %s\n", what,
500 - show_ident_date(&ident, pp->date_mode));
500 + show_ident_date(&ident, &pp->date_mode));
501 break;
502 default:
503 /* notin' */
@@ -671,7 +671,8 @@ static int mailmap_name(const char **email, size_t *email_len,
671 }
672
673 static size_t format_person_part(struct strbuf *sb, char part,
674 - const char *msg, int len, enum date_mode dmode)
674 + const char *msg, int len,
675 + const struct date_mode *dmode)
676 {
677 /* currently all placeholders have same length */
678 const int placeholder_len = 2;
@@ -711,16 +712,16 @@ static size_t format_person_part(struct strbuf *sb, char part,
712 strbuf_addstr(sb, show_ident_date(&s, dmode));
713 return placeholder_len;
714 case 'D': /* date, RFC2822 style */
714 - strbuf_addstr(sb, show_ident_date(&s, DATE_RFC2822));
715 + strbuf_addstr(sb, show_ident_date(&s, DATE_MODE(RFC2822)));
716 return placeholder_len;
717 case 'r': /* date, relative */
717 - strbuf_addstr(sb, show_ident_date(&s, DATE_RELATIVE));
718 + strbuf_addstr(sb, show_ident_date(&s, DATE_MODE(RELATIVE)));
719 return placeholder_len;
720 case 'i': /* date, ISO 8601-like */
720 - strbuf_addstr(sb, show_ident_date(&s, DATE_ISO8601));
721 + strbuf_addstr(sb, show_ident_date(&s, DATE_MODE(ISO8601)));
722 return placeholder_len;
723 case 'I': /* date, ISO 8601 strict */
723 - strbuf_addstr(sb, show_ident_date(&s, DATE_ISO8601_STRICT));
724 + strbuf_addstr(sb, show_ident_date(&s, DATE_MODE(ISO8601_STRICT)));
725 return placeholder_len;
726 }
727
@@ -933,7 +934,7 @@ static void rewrap_message_tail(struct strbuf *sb,
934 static int format_reflog_person(struct strbuf *sb,
935 char part,
936 struct reflog_walk_info *log,
936 - enum date_mode dmode)
937 + const struct date_mode *dmode)
938 {
939 const char *ident;
940
@@ -1185,7 +1186,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
1186 if (c->pretty_ctx->reflog_info)
1187 get_reflog_selector(sb,
1188 c->pretty_ctx->reflog_info,
1188 - c->pretty_ctx->date_mode,
1189 + &c->pretty_ctx->date_mode,
1190 c->pretty_ctx->date_mode_explicit,
1191 (placeholder[1] == 'd'));
1192 return 2;
@@ -1200,7 +1201,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
1201 return format_reflog_person(sb,
1202 placeholder[1],
1203 c->pretty_ctx->reflog_info,
1203 - c->pretty_ctx->date_mode);
1204 + &c->pretty_ctx->date_mode);
1205 }
1206 return 0; /* unknown %g placeholder */
1207 case 'N':
@@ -1251,11 +1252,11 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
1252 case 'a': /* author ... */
1253 return format_person_part(sb, placeholder[1],
1254 msg + c->author.off, c->author.len,
1254 - c->pretty_ctx->date_mode);
1255 + &c->pretty_ctx->date_mode);
1256 case 'c': /* committer ... */
1257 return format_person_part(sb, placeholder[1],
1258 msg + c->committer.off, c->committer.len,
1258 - c->pretty_ctx->date_mode);
1259 + &c->pretty_ctx->date_mode);
1260 case 'e': /* encoding */
1261 if (c->commit_encoding)
1262 strbuf_addstr(sb, c->commit_encoding);
reflog-walk.c
+2 -2
@@ -249,7 +249,7 @@ void fake_reflog_parent(struct reflog_walk_info *info, struct commit *commit)
249
250 void get_reflog_selector(struct strbuf *sb,
251 struct reflog_walk_info *reflog_info,
252 - enum date_mode dmode, int force_date,
252 + const struct date_mode *dmode, int force_date,
253 int shorten)
254 {
255 struct commit_reflog *commit_reflog = reflog_info->last_commit_reflog;
@@ -311,7 +311,7 @@ const char *get_reflog_ident(struct reflog_walk_info *reflog_info)
311 }
312
313 void show_reflog_message(struct reflog_walk_info *reflog_info, int oneline,
314 - enum date_mode dmode, int force_date)
314 + const struct date_mode *dmode, int force_date)
315 {
316 if (reflog_info && reflog_info->last_commit_reflog) {
317 struct commit_reflog *commit_reflog = reflog_info->last_commit_reflog;
reflog-walk.h
+2 -2
@@ -11,13 +11,13 @@ extern int add_reflog_for_walk(struct reflog_walk_info *info,
11 extern void fake_reflog_parent(struct reflog_walk_info *info,
12 struct commit *commit);
13 extern void show_reflog_message(struct reflog_walk_info *info, int,
14 - enum date_mode, int force_date);
14 + const struct date_mode *, int force_date);
15 extern void get_reflog_message(struct strbuf *sb,
16 struct reflog_walk_info *reflog_info);
17 extern const char *get_reflog_ident(struct reflog_walk_info *reflog_info);
18 extern void get_reflog_selector(struct strbuf *sb,
19 struct reflog_walk_info *reflog_info,
20 - enum date_mode dmode, int force_date,
20 + const struct date_mode *dmode, int force_date,
21 int shorten);
22
23 #endif
refs.c
+2 -2
@@ -3371,14 +3371,14 @@ static int read_ref_at_ent(unsigned char *osha1, unsigned char *nsha1,
3371 hashcpy(cb->sha1, nsha1);
3372 if (hashcmp(cb->osha1, nsha1))
3373 warning("Log for ref %s has gap after %s.",
3374 - cb->refname, show_date(cb->date, cb->tz, DATE_RFC2822));
3374 + cb->refname, show_date(cb->date, cb->tz, DATE_MODE(RFC2822)));
3375 }
3376 else if (cb->date == cb->at_time)
3377 hashcpy(cb->sha1, nsha1);
3378 else if (hashcmp(nsha1, cb->sha1))
3379 warning("Log for ref %s unexpectedly ended on %s.",
3380 cb->refname, show_date(cb->date, cb->tz,
3381 - DATE_RFC2822));
3381 + DATE_MODE(RFC2822)));
3382 hashcpy(cb->osha1, osha1);
3383 hashcpy(cb->nsha1, nsha1);
3384 cb->found_it = 1;
revision.c
+2 -2
@@ -1996,10 +1996,10 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
1996 } else if (!strcmp(arg, "--full-history")) {
1997 revs->simplify_history = 0;
1998 } else if (!strcmp(arg, "--relative-date")) {
1999 - revs->date_mode = DATE_RELATIVE;
1999 + revs->date_mode.type = DATE_RELATIVE;
2000 revs->date_mode_explicit = 1;
2001 } else if ((argcount = parse_long_opt("date", argv, &optarg))) {
2002 - revs->date_mode = parse_date_format(optarg);
2002 + parse_date_format(optarg, &revs->date_mode);
2003 revs->date_mode_explicit = 1;
2004 return argcount;
2005 } else if (!strcmp(arg, "--log-size")) {
revision.h
+1 -1
@@ -146,7 +146,7 @@ struct rev_info {
146 track_first_time:1,
147 linear:1;
148
149 - enum date_mode date_mode;
149 + struct date_mode date_mode;
150
151 unsigned int abbrev;
152 enum cmit_fmt commit_format;
sha1_name.c
+1 -1
@@ -576,7 +576,7 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1,
576 if (!(flags & GET_SHA1_QUIETLY)) {
577 warning("Log for '%.*s' only goes "
578 "back to %s.", len, str,
579 - show_date(co_time, co_tz, DATE_RFC2822));
579 + show_date(co_time, co_tz, DATE_MODE(RFC2822)));
580 }
581 } else {
582 if (flags & GET_SHA1_QUIETLY) {
submodule.c
+1 -1
@@ -993,7 +993,7 @@ static void print_commit(struct commit *commit)
993 {
994 struct strbuf sb = STRBUF_INIT;
995 struct pretty_print_context ctx = {0};
996 - ctx.date_mode = DATE_NORMAL;
996 + ctx.date_mode.type = DATE_NORMAL;
997 format_commit_message(commit, " %h: %m %s", &sb, &ctx);
998 fprintf(stderr, "%s\n", sb.buf);
999 strbuf_release(&sb);
test-date.c
+2 -2
@@ -29,7 +29,7 @@ static void parse_dates(char **argv, struct timeval *now)
29 parse_date(*argv, &result);
30 if (sscanf(result.buf, "%lu %d", &t, &tz) == 2)
31 printf("%s -> %s\n",
32 - *argv, show_date(t, tz, DATE_ISO8601));
32 + *argv, show_date(t, tz, DATE_MODE(ISO8601)));
33 else
34 printf("%s -> bad\n", *argv);
35 }
@@ -41,7 +41,7 @@ static void parse_approxidate(char **argv, struct timeval *now)
41 for (; *argv; argv++) {
42 time_t t;
43 t = approxidate_relative(*argv, now);
44 - printf("%s -> %s\n", *argv, show_date(t, 0, DATE_ISO8601));
44 + printf("%s -> %s\n", *argv, show_date(t, 0, DATE_MODE(ISO8601)));
45 }
46 }
47
test-revision-walking.c
+1 -1
@@ -17,7 +17,7 @@ static void print_commit(struct commit *commit)
17 {
18 struct strbuf sb = STRBUF_INIT;
19 struct pretty_print_context ctx = {0};
20 - ctx.date_mode = DATE_NORMAL;
20 + ctx.date_mode.type = DATE_NORMAL;
21 format_commit_message(commit, " %m %s", &sb, &ctx);
22 printf("%s\n", sb.buf);
23 strbuf_release(&sb);