diff options
authorBryce Kwon <bryce@brycekwon.com>
committerBryce Kwon <bryce@brycekwon.com>
commit
parent
tree
download
Keep date-format=local-local from failing pages
The guard took local as a name that may carry the -local suffix, but git reads local only as a whole alias of default-local and dies on anything after it, so that one value turned every page into a 500.
-rw-r--r--MANUAL.txt12
-rw-r--r--source/shared.c9
-rwxr-xr-xtests/t0203-dates.sh13
3 files changed, 27 insertions, 7 deletions
diff --git a/MANUAL.txt b/MANUAL.txt
index 0ea60ff..a06ef7f 100644
--- a/MANUAL.txt
+++ b/MANUAL.txt
@@ -135,12 +135,12 @@ date-format::
entry is too old to be shown as an age. Accepts the same names as git's
--date option: "default", "human", "iso" (or "iso8601"), "iso-strict"
(or "iso8601-strict"), "raw", "relative", "rfc" (or "rfc2822"), "short"
- and "unix", each of which may carry a "-local" suffix, plus
- "format:<strftime>" for an arbitrary layout. An unrecognised value is
- ignored. Dates elsewhere, such as the author and committer lines on the
- commit page, are always ISO 8601 and are not affected, nor are the exact
- timestamps shown on hover. Default value: "short". See also:
- "local-time".
+ and "unix", each of which may carry a "-local" suffix, "local" alone as
+ git's alias of "default-local", plus "format:<strftime>" for an
+ arbitrary layout. An unrecognised value is ignored. Dates elsewhere,
+ such as the author and committer lines on the commit page, are always
+ ISO 8601 and are not affected, nor are the exact timestamps shown on
+ hover. Default value: "short". See also: "local-time".
email-filter::
Specifies a command which will be invoked to format names and email
diff --git a/source/shared.c b/source/shared.c
index 6e69666..84ee4c8 100644
--- a/source/shared.c
+++ b/source/shared.c
@@ -507,7 +507,7 @@ 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",
+ "iso8601-strict", "raw", "relative", "rfc",
"rfc2822", "short", "unix",
};
const char *rest;
@@ -520,6 +520,13 @@ void cgit_parse_date_format(const char *format, struct date_mode *mode)
return;
}
+ // git reads local only as a whole alias of default-local, and dies on
+ // it with a suffix of its own.
+ if (!strcmp(format, "local")) {
+ parse_date_format(format, mode);
+ return;
+ }
+
for (i = 0; i < ARRAY_SIZE(names); i++) {
if (!skip_prefix(format, names[i], &rest))
continue;
diff --git a/tests/t0203-dates.sh b/tests/t0203-dates.sh
index 02f12f1..3c8ecab 100755
--- a/tests/t0203-dates.sh
+++ b/tests/t0203-dates.sh
@@ -80,6 +80,19 @@ test_expect_success 'an unknown date-format falls back to short' '
grep "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]<" tmp
'
+test_expect_success 'a date-format git would refuse falls back to short' '
+ daterc "enable-relative-dates=0" "date-format=local-local" &&
+ dateq "url=dated/refs/" >tmp &&
+ grep "^Status: 200" tmp &&
+ grep "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]<" tmp
+'
+
+test_expect_success 'date-format=local is the default format in local time' '
+ daterc "enable-relative-dates=0" "date-format=local" &&
+ dateq "url=dated/refs/" >tmp &&
+ grep ">[A-Z][a-z][a-z] [A-Z][a-z][a-z] [0-9]* [0-9:]* [0-9]*<" tmp
+'
+
test_expect_success 'date-format still formats the log fallback' '
daterc "date-format=rfc2822" &&
dateq "url=dated/log/" >tmp &&