Code

mktag: minimally update the description.
[git.git] / commit.c
index 10466c4ae0cb1db8648b9191fece9d9dbf238cb6..4ca4d44ba0d648c6c102ac17160b69f6f0f02836 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -148,7 +148,7 @@ static int commit_graft_pos(const unsigned char *sha1)
 int register_commit_graft(struct commit_graft *graft, int ignore_dups)
 {
        int pos = commit_graft_pos(graft->sha1);
-       
+
        if (0 <= pos) {
                if (ignore_dups)
                        free(graft);
@@ -406,7 +406,7 @@ struct commit_list * insert_by_date(struct commit *item, struct commit_list **li
        return commit_list_insert(item, pp);
 }
 
-       
+
 void sort_by_date(struct commit_list **list)
 {
        struct commit_list *ret = NULL;
@@ -511,12 +511,16 @@ static int add_rfc2047(char *buf, const char *line, int len,
        bp += i;
        for (i = 0; i < len; i++) {
                unsigned ch = line[i] & 0xFF;
-               if (is_rfc2047_special(ch)) {
+               /*
+                * We encode ' ' using '=20' even though rfc2047
+                * allows using '_' for readability.  Unfortunately,
+                * many programs do not understand this and just
+                * leave the underscore in place.
+                */
+               if (is_rfc2047_special(ch) || ch == ' ') {
                        sprintf(bp, "=%02X", ch);
                        bp += 3;
                }
-               else if (ch == ' ')
-                       *bp++ = '_';
                else
                        *bp++ = ch;
        }
@@ -526,7 +530,7 @@ static int add_rfc2047(char *buf, const char *line, int len,
 }
 
 static int add_user_info(const char *what, enum cmit_fmt fmt, char *buf,
-                        const char *line, int relative_date,
+                        const char *line, enum date_mode dmode,
                         const char *encoding)
 {
        char *date;
@@ -569,7 +573,7 @@ static int add_user_info(const char *what, enum cmit_fmt fmt, char *buf,
        switch (fmt) {
        case CMIT_FMT_MEDIUM:
                ret += sprintf(buf + ret, "Date:   %s\n",
-                              show_date(time, tz, relative_date));
+                              show_date(time, tz, dmode));
                break;
        case CMIT_FMT_EMAIL:
                ret += sprintf(buf + ret, "Date: %s\n",
@@ -577,7 +581,7 @@ static int add_user_info(const char *what, enum cmit_fmt fmt, char *buf,
                break;
        case CMIT_FMT_FULLER:
                ret += sprintf(buf + ret, "%sDate: %s\n", what,
-                              show_date(time, tz, relative_date));
+                              show_date(time, tz, dmode));
                break;
        default:
                /* notin' */
@@ -638,7 +642,9 @@ static char *get_header(const struct commit *commit, const char *key)
                        next = NULL;
                } else
                        next = eol + 1;
-               if (!strncmp(line, key, key_len) && line[key_len] == ' ') {
+               if (eol - line > key_len &&
+                   !strncmp(line, key, key_len) &&
+                   line[key_len] == ' ') {
                        int len = eol - line - key_len;
                        char *ret = xmalloc(len);
                        memcpy(ret, line + key_len + 1, len - 1);
@@ -718,14 +724,6 @@ static char *logmsg_reencode(const struct commit *commit,
        return out;
 }
 
-static char *xstrndup(const char *text, int len)
-{
-       char *result = xmalloc(len + 1);
-       memcpy(result, text, len);
-       result[len] = '\0';
-       return result;
-}
-
 static void fill_person(struct interp *table, const char *msg, int len)
 {
        int start, end, tz = 0;
@@ -919,7 +917,7 @@ unsigned long pretty_print_commit(enum cmit_fmt fmt,
                                  char *buf, unsigned long space,
                                  int abbrev, const char *subject,
                                  const char *after_subject,
-                                 int relative_date)
+                                 enum date_mode dmode)
 {
        int hdr = 1, body = 0, seen_title = 0;
        unsigned long offset = 0;
@@ -1023,14 +1021,14 @@ unsigned long pretty_print_commit(enum cmit_fmt fmt,
                                offset += add_user_info("Author", fmt,
                                                        buf + offset,
                                                        line + 7,
-                                                       relative_date,
+                                                       dmode,
                                                        encoding);
                        if (!memcmp(line, "committer ", 10) &&
                            (fmt == CMIT_FMT_FULL || fmt == CMIT_FMT_FULLER))
                                offset += add_user_info("Commit", fmt,
                                                        buf + offset,
                                                        line + 10,
-                                                       relative_date,
+                                                       dmode,
                                                        encoding);
                        continue;
                }
@@ -1069,6 +1067,7 @@ unsigned long pretty_print_commit(enum cmit_fmt fmt,
                        int sz;
                        char header[512];
                        const char *header_fmt =
+                               "MIME-Version: 1.0\n"
                                "Content-Type: text/plain; charset=%s\n"
                                "Content-Transfer-Encoding: 8bit\n";
                        sz = snprintf(header, sizeof(header), header_fmt,
@@ -1117,15 +1116,6 @@ struct commit *pop_commit(struct commit_list **stack)
        return item;
 }
 
-int count_parents(struct commit * commit)
-{
-        int count;
-        struct commit_list * parents = commit->parents;
-        for (count = 0; parents; parents = parents->next,count++)
-               ;
-        return count;
-}
-
 void topo_sort_default_setter(struct commit *c, void *data)
 {
        c->util = data;
@@ -1161,7 +1151,7 @@ void sort_in_topological_order_fn(struct commit_list ** list, int lifo,
                next = next->next;
                count++;
        }
-       
+
        if (!count)
                return;
        /* allocate an array to help sort the list */
@@ -1189,11 +1179,11 @@ void sort_in_topological_order_fn(struct commit_list ** list, int lifo,
                }
                next=next->next;
        }
-       /* 
+       /*
          * find the tips
          *
-         * tips are nodes not reachable from any other node in the list 
-         * 
+         * tips are nodes not reachable from any other node in the list
+         *
          * the tips serve as a starting set for the work queue.
          */
        next=*list;
@@ -1221,7 +1211,7 @@ void sort_in_topological_order_fn(struct commit_list ** list, int lifo,
 
                        if (pn) {
                                /*
-                                * parents are only enqueued for emission 
+                                * parents are only enqueued for emission
                                  * when all their children have been emitted thereby
                                  * guaranteeing topological order.
                                  */