Code

git-svn: establish new connections on commit after fork
[git.git] / commit.c
index 522a6f3aca644f968b825abf83e1fa6474b559eb..00bc3de22eb670c07e78087d96d9a3cff1d0fd67 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -7,15 +7,15 @@ int save_commit_buffer = 1;
 struct sort_node
 {
        /*
-         * the number of children of the associated commit
-         * that also occur in the list being sorted.
-         */
+        * the number of children of the associated commit
+        * that also occur in the list being sorted.
+        */
        unsigned int indegree;
 
        /*
-         * reference to original list item that we will re-use
-         * on output.
-         */
+        * reference to original list item that we will re-use
+        * on output.
+        */
        struct commit_list * list_item;
 
 };
@@ -56,7 +56,7 @@ static struct commit *check_commit(struct object *obj,
                                   const unsigned char *sha1,
                                   int quiet)
 {
-       if (obj->type != TYPE_COMMIT) {
+       if (obj->type != OBJ_COMMIT) {
                if (!quiet)
                        error("Object %s is a %s, not a commit",
                              sha1_to_hex(sha1), typename(obj->type));
@@ -86,11 +86,11 @@ struct commit *lookup_commit(const unsigned char *sha1)
        if (!obj) {
                struct commit *ret = alloc_commit_node();
                created_object(sha1, &ret->object);
-               ret->object.type = TYPE_COMMIT;
+               ret->object.type = OBJ_COMMIT;
                return ret;
        }
        if (!obj->type)
-               obj->type = TYPE_COMMIT;
+               obj->type = OBJ_COMMIT;
        return check_commit(obj, sha1, 0);
 }
 
@@ -123,7 +123,7 @@ static int commit_graft_pos(const unsigned char *sha1)
        while (lo < hi) {
                int mi = (lo + hi) / 2;
                struct commit_graft *graft = commit_graft[mi];
-               int cmp = memcmp(sha1, graft->sha1, 20);
+               int cmp = hashcmp(sha1, graft->sha1);
                if (!cmp)
                        return mi;
                if (cmp < 0)
@@ -655,6 +655,9 @@ unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit
                        continue;
                }
 
+               if (!subject)
+                       body = 1;
+
                if (is_empty_line(line, &linelen)) {
                        if (!body)
                                continue;
@@ -662,8 +665,6 @@ unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit
                                continue;
                        if (fmt == CMIT_FMT_SHORT)
                                break;
-               } else {
-                       body = 1;
                }
 
                if (subject) {
@@ -702,6 +703,12 @@ unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit
        /* Make sure there is an EOLN for the non-oneline case */
        if (fmt != CMIT_FMT_ONELINE)
                buf[offset++] = '\n';
+       /*
+        * make sure there is another EOLN to separate the headers from whatever
+        * body the caller appends if we haven't already written a body
+        */
+       if (fmt == CMIT_FMT_EMAIL && !body)
+               buf[offset++] = '\n';
        buf[offset] = '\0';
        return offset;
 }
@@ -720,10 +727,10 @@ struct commit *pop_commit(struct commit_list **stack)
 
 int count_parents(struct commit * commit)
 {
-        int count = 0;
+        int count;
         struct commit_list * parents = commit->parents;
-        for (count=0;parents; parents=parents->next,count++)
-          ;
+        for (count = 0; parents; parents = parents->next,count++)
+               ;
         return count;
 }