documentation: use the word "index" in the git-add manual page
[gitweb.git] / commit.c
index f1ba972d9abcb218b9aae0680a753edeb3666bc3..5632e32685478dcce34e479e8e916b0ccd3a3b13 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -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;
        }
@@ -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;
@@ -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,