Merge branch 'bb/date-iso-strict'
authorJunio C Hamano <gitster@pobox.com>
Fri, 19 Sep 2014 18:38:32 +0000 (11:38 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 19 Sep 2014 18:38:32 +0000 (11:38 -0700)
"log --date=iso" uses a slight variant of ISO 8601 format that is
made more human readable. A new "--date=iso-strict" option gives
datetime output that is more strictly conformant.

* bb/date-iso-strict:
pretty: provide a strict ISO 8601 date format

Documentation/git-rev-list.txt
Documentation/pretty-formats.txt
Documentation/rev-list-options.txt
builtin/blame.c
cache.h
date.c
pretty.c
t/t4205-log-pretty-formats.sh
index 7a1585def0ce0c0ca78a2735f619f0e8bdf3506c..fd7f8b5bc1840bc93273dd7b076d86499626912a 100644 (file)
@@ -45,7 +45,7 @@ SYNOPSIS
             [ \--regexp-ignore-case | -i ]
             [ \--extended-regexp | -E ]
             [ \--fixed-strings | -F ]
-            [ \--date=(local|relative|default|iso|rfc|short) ]
+            [ \--date=(local|relative|default|iso|iso-strict|rfc|short) ]
             [ [\--objects | \--objects-edge] [ \--unpacked ] ]
             [ \--pretty | \--header ]
             [ \--bisect ]
index eac79096d3d9cb544c9e213d285b5a3158367246..6c30723740cff5d88d3696f45e2325bc565e5f4a 100644 (file)
@@ -115,7 +115,8 @@ The placeholders are:
 - '%aD': author date, RFC2822 style
 - '%ar': author date, relative
 - '%at': author date, UNIX timestamp
-- '%ai': author date, ISO 8601 format
+- '%ai': author date, ISO 8601-like format
+- '%aI': author date, strict ISO 8601 format
 - '%cn': committer name
 - '%cN': committer name (respecting .mailmap, see
   linkgit:git-shortlog[1] or linkgit:git-blame[1])
@@ -126,7 +127,8 @@ The placeholders are:
 - '%cD': committer date, RFC2822 style
 - '%cr': committer date, relative
 - '%ct': committer date, UNIX timestamp
-- '%ci': committer date, ISO 8601 format
+- '%ci': committer date, ISO 8601-like format
+- '%cI': committer date, strict ISO 8601 format
 - '%d': ref names, like the --decorate option of linkgit:git-log[1]
 - '%e': encoding
 - '%s': subject
index deb8cca9173ccbaf8c15ade3f8b3312fb6bdcbad..5d311b8d46712ab0efb863d3ecd009386476a092 100644 (file)
@@ -677,7 +677,7 @@ include::pretty-options.txt[]
 --relative-date::
        Synonym for `--date=relative`.
 
---date=(relative|local|default|iso|rfc|short|raw)::
+--date=(relative|local|default|iso|iso-strict|rfc|short|raw)::
        Only takes effect for dates shown in human-readable format, such
        as when using `--pretty`. `log.date` config variable sets a default
        value for the log command's `--date` option.
@@ -687,7 +687,16 @@ e.g. ``2 hours ago''.
 +
 `--date=local` shows timestamps in user's local time zone.
 +
-`--date=iso` (or `--date=iso8601`) shows timestamps in ISO 8601 format.
+`--date=iso` (or `--date=iso8601`) shows timestamps in a ISO 8601-like format.
+The differences to the strict ISO 8601 format are:
+
+       - a space instead of the `T` date/time delimiter
+       - a space between time and time zone
+       - no colon between hours and minutes of the time zone
+
++
+`--date=iso-strict` (or `--date=iso8601-strict`) shows timestamps in strict
+ISO 8601 format.
 +
 `--date=rfc` (or `--date=rfc2822`) shows timestamps in RFC 2822
 format, often found in email messages.
index ca4ba6ff15b91d9cbb6b2ce3783fa3e69d0f3ff1..3838be2b0274fbd72b200c2bf294e4d2842a020c 100644 (file)
@@ -2580,6 +2580,9 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
        case DATE_RFC2822:
                blame_date_width = sizeof("Thu, 19 Oct 2006 16:00:04 -0700");
                break;
+       case DATE_ISO8601_STRICT:
+               blame_date_width = sizeof("2006-10-19T16:00:04-07:00");
+               break;
        case DATE_ISO8601:
                blame_date_width = sizeof("2006-10-19 16:00:04 -0700");
                break;
diff --git a/cache.h b/cache.h
index dfa1a5696d448b407644276df58fb24e25c57113..823feb87b70b205b5de25dc10e84e97d88cb6c62 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -1039,6 +1039,7 @@ enum date_mode {
        DATE_SHORT,
        DATE_LOCAL,
        DATE_ISO8601,
+       DATE_ISO8601_STRICT,
        DATE_RFC2822,
        DATE_RAW
 };
diff --git a/date.c b/date.c
index 782de95d90c6ac1a02ddfa0df81ca93ecdf910c4..5d73d9b7b223be54b8ad14c3c5a7eca1b501ec09 100644 (file)
--- a/date.c
+++ b/date.c
@@ -200,7 +200,16 @@ const char *show_date(unsigned long time, int tz, enum date_mode mode)
                                tm->tm_mday,
                                tm->tm_hour, tm->tm_min, tm->tm_sec,
                                tz);
-       else if (mode == DATE_RFC2822)
+       else if (mode == DATE_ISO8601_STRICT) {
+               char sign = (tz >= 0) ? '+' : '-';
+               tz = abs(tz);
+               strbuf_addf(&timebuf, "%04d-%02d-%02dT%02d:%02d:%02d%c%02d:%02d",
+                               tm->tm_year + 1900,
+                               tm->tm_mon + 1,
+                               tm->tm_mday,
+                               tm->tm_hour, tm->tm_min, tm->tm_sec,
+                               sign, tz / 100, tz % 100);
+       } else if (mode == DATE_RFC2822)
                strbuf_addf(&timebuf, "%.3s, %d %.3s %d %02d:%02d:%02d %+05d",
                        weekday_names[tm->tm_wday], tm->tm_mday,
                        month_names[tm->tm_mon], tm->tm_year + 1900,
@@ -751,6 +760,9 @@ enum date_mode parse_date_format(const char *format)
        else if (!strcmp(format, "iso8601") ||
                 !strcmp(format, "iso"))
                return DATE_ISO8601;
+       else if (!strcmp(format, "iso8601-strict") ||
+                !strcmp(format, "iso-strict"))
+               return DATE_ISO8601_STRICT;
        else if (!strcmp(format, "rfc2822") ||
                 !strcmp(format, "rfc"))
                return DATE_RFC2822;
index 44b9f643725c68325a9caf92dff819e22e38e3ad..5f012a6b8ed6cdf345b350e3fa2f6b821ceebd7d 100644 (file)
--- a/pretty.c
+++ b/pretty.c
@@ -738,9 +738,12 @@ static size_t format_person_part(struct strbuf *sb, char part,
        case 'r':       /* date, relative */
                strbuf_addstr(sb, show_ident_date(&s, DATE_RELATIVE));
                return placeholder_len;
-       case 'i':       /* date, ISO 8601 */
+       case 'i':       /* date, ISO 8601-like */
                strbuf_addstr(sb, show_ident_date(&s, DATE_ISO8601));
                return placeholder_len;
+       case 'I':       /* date, ISO 8601 strict */
+               strbuf_addstr(sb, show_ident_date(&s, DATE_ISO8601_STRICT));
+               return placeholder_len;
        }
 
 skip:
index de0cc4a0fd5fe37bb36a3268182d95de3589f4b4..9b75399572b1cbe1bfcb00995e1660a93fe6a4c6 100755 (executable)
@@ -438,6 +438,14 @@ test_expect_success 'strbuf_utf8_replace() not producing NUL' '
        ! grep Q actual
 '
 
+# ISO strict date format
+test_expect_success 'ISO and ISO-strict date formats display the same values' '
+       git log --format=%ai%n%ci |
+       sed -e "s/ /T/; s/ //; s/..\$/:&/" >expected &&
+       git log --format=%aI%n%cI >actual &&
+       test_cmp expected actual
+'
+
 # get new digests (with no abbreviations)
 head1=$(git rev-parse --verify HEAD~0) &&
 head2=$(git rev-parse --verify HEAD~1) &&