Merge branch 'ss/svnimport'
[gitweb.git] / commit.c
index 40c87a7471ba3520d5543fa07280c9277a832672..99f65cee0e7e30e833f850b5993aa8a5797ba889 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -27,7 +27,7 @@ struct sort_node
 
 const char *commit_type = "commit";
 
-struct cmt_fmt_map {
+static struct cmt_fmt_map {
        const char *n;
        size_t cmp_len;
        enum cmit_fmt v;
@@ -585,7 +585,7 @@ static int add_user_info(const char *what, enum cmit_fmt fmt, char *buf,
                break;
        case CMIT_FMT_EMAIL:
                ret += sprintf(buf + ret, "Date: %s\n",
-                              show_rfc2822_date(time, tz));
+                              show_date(time, tz, DATE_RFC2822));
                break;
        case CMIT_FMT_FULLER:
                ret += sprintf(buf + ret, "%sDate: %s\n", what,
@@ -721,7 +721,10 @@ static char *logmsg_reencode(const struct commit *commit,
        encoding = get_header(commit, "encoding");
        use_encoding = encoding ? encoding : utf8;
        if (!strcmp(use_encoding, output_encoding))
-               out = xstrdup(commit->buffer);
+               if (encoding) /* we'll strip encoding header later */
+                       out = xstrdup(commit->buffer);
+               else
+                       return NULL; /* nothing to do */
        else
                out = reencode_string(commit->buffer,
                                      output_encoding, use_encoding);
@@ -778,13 +781,14 @@ static void fill_person(struct interp *table, const char *msg, int len)
                        tz = -tz;
        }
 
-       interp_set_entry(table, 2, show_date(date, tz, 0));
-       interp_set_entry(table, 3, show_rfc2822_date(date, tz));
-       interp_set_entry(table, 4, show_date(date, tz, 1));
+       interp_set_entry(table, 2, show_date(date, tz, DATE_NORMAL));
+       interp_set_entry(table, 3, show_date(date, tz, DATE_RFC2822));
+       interp_set_entry(table, 4, show_date(date, tz, DATE_RELATIVE));
+       interp_set_entry(table, 6, show_date(date, tz, DATE_ISO8601));
 }
 
-static long format_commit_message(const struct commit *commit,
-               const char *msg, char **buf_p, unsigned long *space_p)
+long format_commit_message(const struct commit *commit, const void *format,
+                           char **buf_p, unsigned long *space_p)
 {
        struct interp table[] = {
                { "%H" },       /* commit hash */
@@ -799,12 +803,14 @@ static long format_commit_message(const struct commit *commit,
                { "%aD" },      /* author date, RFC2822 style */
                { "%ar" },      /* author date, relative */
                { "%at" },      /* author date, UNIX timestamp */
+               { "%ai" },      /* author date, ISO 8601 */
                { "%cn" },      /* committer name */
                { "%ce" },      /* committer email */
                { "%cd" },      /* committer date */
                { "%cD" },      /* committer date, RFC2822 style */
                { "%cr" },      /* committer date, relative */
                { "%ct" },      /* committer date, UNIX timestamp */
+               { "%ci" },      /* committer date, ISO 8601 */
                { "%e" },       /* encoding */
                { "%s" },       /* subject */
                { "%b" },       /* body */
@@ -821,10 +827,11 @@ static long format_commit_message(const struct commit *commit,
                IPARENTS, IPARENTS_ABBREV,
                IAUTHOR_NAME, IAUTHOR_EMAIL,
                IAUTHOR_DATE, IAUTHOR_DATE_RFC2822, IAUTHOR_DATE_RELATIVE,
-               IAUTHOR_TIMESTAMP,
+               IAUTHOR_TIMESTAMP, IAUTHOR_ISO8601,
                ICOMMITTER_NAME, ICOMMITTER_EMAIL,
                ICOMMITTER_DATE, ICOMMITTER_DATE_RFC2822,
                ICOMMITTER_DATE_RELATIVE, ICOMMITTER_TIMESTAMP,
+               ICOMMITTER_ISO8601,
                IENCODING,
                ISUBJECT,
                IBODY,
@@ -836,6 +843,7 @@ static long format_commit_message(const struct commit *commit,
        char parents[1024];
        int i;
        enum { HEADER, SUBJECT, BODY } state;
+       const char *msg = commit->buffer;
 
        if (ILEFT_RIGHT + 1 != ARRAY_SIZE(table))
                die("invalid interp table!");
@@ -917,7 +925,7 @@ static long format_commit_message(const struct commit *commit,
                char *buf = *buf_p;
                unsigned long space = *space_p;
 
-               space = interpolate(buf, space, user_format,
+               space = interpolate(buf, space, format,
                                    table, ARRAY_SIZE(table));
                if (!space)
                        break;
@@ -997,7 +1005,7 @@ static void pp_header(enum cmit_fmt fmt,
                        len = linelen;
                        if (fmt == CMIT_FMT_EMAIL)
                                len = bound_rfc2047(linelen, encoding);
-                       ALLOC_GROW(*buf_p, *ofs_p + len, *space_p);
+                       ALLOC_GROW(*buf_p, *ofs_p + len + 80, *space_p);
                        dst = *buf_p + *ofs_p;
                        *ofs_p += add_user_info("Author", fmt, dst,
                                                line + 7, dmode, encoding);
@@ -1008,7 +1016,7 @@ static void pp_header(enum cmit_fmt fmt,
                        len = linelen;
                        if (fmt == CMIT_FMT_EMAIL)
                                len = bound_rfc2047(linelen, encoding);
-                       ALLOC_GROW(*buf_p, *ofs_p + len, *space_p);
+                       ALLOC_GROW(*buf_p, *ofs_p + len + 80, *space_p);
                        dst = *buf_p + *ofs_p;
                        *ofs_p += add_user_info("Commit", fmt, dst,
                                                line + 10, dmode, encoding);
@@ -1158,7 +1166,7 @@ unsigned long pretty_print_commit(enum cmit_fmt fmt,
        char *buf;
 
        if (fmt == CMIT_FMT_USERFORMAT)
-               return format_commit_message(commit, msg, buf_p, space_p);
+               return format_commit_message(commit, user_format, buf_p, space_p);
 
        encoding = (git_log_output_encoding
                    ? git_log_output_encoding