From 86e4e2e2809412ed6221e297bf0df063ad3698bf Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 1 Aug 2026 22:15:27 -1000 Subject: Add `enable-relative-dates` and `date-format` --- source/shared.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'source/shared.c') diff --git a/source/shared.c b/source/shared.c index 59f1c8e..058d938 100644 --- a/source/shared.c +++ b/source/shared.c @@ -439,6 +439,39 @@ int cgit_parse_snapshots_mask(const char *str) return rv; } +/* + * Git's parse_date_format() dies on anything it does not recognize, which + * would turn a typo in cgitrc into a failed request, so gate it behind the + * set of formats cgit documents and leave the mode alone otherwise. + */ +void cgit_parse_date_format(const char *format, struct date_mode *mode) +{ + static const char * const names[] = { + "default", "human", "iso", "iso-strict", "iso8601", + "iso8601-strict", "local", "raw", "relative", "rfc", + "rfc2822", "short", "unix", + }; + const char *rest; + size_t i; + + if (skip_prefix(format, "format:", &rest)) { + // an empty strftime format would render every date blank + if (*rest) + parse_date_format(format, mode); + return; + } + + for (i = 0; i < ARRAY_SIZE(names); i++) { + if (!skip_prefix(format, names[i], &rest)) + continue; + // "iso" also prefixes "iso8601", so keep looking on a partial hit + if (*rest && strcmp(rest, "-local")) + continue; + parse_date_format(format, mode); + return; + } +} + typedef struct { char * name; char * value; -- cgit v2.8.0