parse_date_format(): convert a format name to an enum date_mode
Factor out the code to parse --date=<format> parameter to revision walkers into a separate function, parse_date_format(). This function is passed a string and converts it to an enum date_format: - "relative" => DATE_RELATIVE - "iso8601" or "iso" => DATE_ISO8601 - "rfc2822" => DATE_RFC2822 - "short" => DATE_SHORT - "local" => DATE_LOCAL - "default" => DATE_NORMAL In the event that none of these strings is found, the function die()s. Signed-off-by: Andy Parkins <andyparkins@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Andy Parkins committed
Sep 28, 2007 at 15:17 UTC
856665f827c31ace3f19e672f8911f7f15f2a0e2
3 files changed
+22
-16
cache.h
+1
@@ -432,6 +432,7 @@ const char *show_date(unsigned long time, int timezone, enum date_mode mode);
432
int parse_date(const char *date, char *buf, int bufsize);
433
void datestamp(char *buf, int bufsize);
434
unsigned long approxidate(const char *);
435
+enum date_mode parse_date_format(const char *format);
436
437
extern const char *git_author_info(int);
438
extern const char *git_committer_info(int);
date.c
+20
@@ -584,6 +584,26 @@ int parse_date(const char *date, char *result, int maxlen)
584
return date_string(then, offset, result, maxlen);
585
}
586
587
+enum date_mode parse_date_format(const char *format)
588
+{
589
+ if (!strcmp(format, "relative"))
590
+ return DATE_RELATIVE;
591
+ else if (!strcmp(format, "iso8601") ||
592
+ !strcmp(format, "iso"))
593
+ return DATE_ISO8601;
594
+ else if (!strcmp(format, "rfc2822") ||
595
+ !strcmp(format, "rfc"))
596
+ return DATE_RFC2822;
597
+ else if (!strcmp(format, "short"))
598
+ return DATE_SHORT;
599
+ else if (!strcmp(format, "local"))
600
+ return DATE_LOCAL;
601
+ else if (!strcmp(format, "default"))
602
+ return DATE_NORMAL;
603
+ else
604
+ die("unknown date format %s", format);
605
+}
606
+
607
void datestamp(char *buf, int bufsize)
608
{
609
time_t now;
revision.c
+1
-16
@@ -1134,22 +1134,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
1134
continue;
1135
}
1136
if (!strncmp(arg, "--date=", 7)) {
1137
- if (!strcmp(arg + 7, "relative"))
1138
- revs->date_mode = DATE_RELATIVE;
1139
- else if (!strcmp(arg + 7, "iso8601") ||
1140
- !strcmp(arg + 7, "iso"))
1141
- revs->date_mode = DATE_ISO8601;
1142
- else if (!strcmp(arg + 7, "rfc2822") ||
1143
- !strcmp(arg + 7, "rfc"))
1144
- revs->date_mode = DATE_RFC2822;
1145
- else if (!strcmp(arg + 7, "short"))
1146
- revs->date_mode = DATE_SHORT;
1147
- else if (!strcmp(arg + 7, "local"))
1148
- revs->date_mode = DATE_LOCAL;
1149
- else if (!strcmp(arg + 7, "default"))
1150
- revs->date_mode = DATE_NORMAL;
1151
- else
1152
- die("unknown date format %s", arg);
1137
+ revs->date_mode = parse_date_format(arg + 7);
1138
continue;
1139
}
1140
if (!strcmp(arg, "--log-size")) {