Make git-update-ref a builtin
[gitweb.git] / commit.c
index 7597fba70a8e96a029e3d84cf86289ffcb151223..5914200a2fba2d618951c3210e2b407c29a62d7b 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -56,10 +56,10 @@ static struct commit *check_commit(struct object *obj,
                                   const unsigned char *sha1,
                                   int quiet)
 {
-       if (obj->type != commit_type) {
+       if (obj->type != TYPE_COMMIT) {
                if (!quiet)
                        error("Object %s is a %s, not a commit",
-                             sha1_to_hex(sha1), obj->type);
+                             sha1_to_hex(sha1), typename(obj->type));
                return NULL;
        }
        return (struct commit *) obj;
@@ -86,11 +86,11 @@ struct commit *lookup_commit(const unsigned char *sha1)
        if (!obj) {
                struct commit *ret = xcalloc(1, sizeof(struct commit));
                created_object(sha1, &ret->object);
-               ret->object.type = commit_type;
+               ret->object.type = TYPE_COMMIT;
                return ret;
        }
        if (!obj->type)
-               obj->type = commit_type;
+               obj->type = TYPE_COMMIT;
        return check_commit(obj, sha1, 0);
 }
 
@@ -559,10 +559,24 @@ unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit
        int indent = 4;
        int parents_shown = 0;
        const char *msg = commit->buffer;
+       int plain_non_ascii = 0;
 
        if (fmt == CMIT_FMT_ONELINE || fmt == CMIT_FMT_EMAIL)
                indent = 0;
 
+       /* After-subject is used to pass in Content-Type: multipart
+        * MIME header; in that case we do not have to do the
+        * plaintext content type even if the commit message has
+        * non 7-bit ASCII character.  Otherwise, check if we need
+        * to say this is not a 7-bit ASCII.
+        */
+       if (fmt == CMIT_FMT_EMAIL && !after_subject) {
+               int i;
+               for (i = 0; !plain_non_ascii && msg[i] && i < len; i++)
+                       if (msg[i] & 0x80)
+                               plain_non_ascii = 1;
+       }
+
        for (;;) {
                const char *line = msg;
                int linelen = get_one_line(msg, len);
@@ -648,13 +662,12 @@ unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit
                buf[offset++] = '\n';
                if (fmt == CMIT_FMT_ONELINE)
                        break;
-               if (subject) {
+               if (subject && plain_non_ascii) {
                        static const char header[] =
                                "Content-Type: text/plain; charset=UTF-8\n"
                                "Content-Transfer-Encoding: 8bit\n";
                        memcpy(buf + offset, header, sizeof(header)-1);
                        offset += sizeof(header)-1;
-                       subject = NULL;
                }
                if (after_subject) {
                        int slen = strlen(after_subject);
@@ -698,12 +711,12 @@ int count_parents(struct commit * commit)
 
 void topo_sort_default_setter(struct commit *c, void *data)
 {
-       c->object.util = data;
+       c->util = data;
 }
 
 void *topo_sort_default_getter(struct commit *c)
 {
-       return c->object.util;
+       return c->util;
 }
 
 /*