Set object type at object creation time, not object parse time.
[git.git] / commit.c
index 911f643..c0dd689 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -12,6 +12,7 @@ struct commit *lookup_commit(unsigned char *sha1)
                struct commit *ret = malloc(sizeof(struct commit));
                memset(ret, 0, sizeof(struct commit));
                created_object(sha1, &ret->object);
+               ret->object.type = commit_type;
                return ret;
        }
        if (obj->parsed && obj->type != commit_type) {
@@ -56,7 +57,6 @@ int parse_commit(struct commit *item)
        if (strcmp(type, commit_type))
                return error("Object %s not a commit",
                             sha1_to_hex(item->object.sha1));
-       item->object.type = commit_type;
        get_sha1_hex(bufptr + 5, parent);
        item->tree = lookup_tree(parent);
        add_ref(&item->object, &item->tree->object);
@@ -114,7 +114,8 @@ void sort_by_date(struct commit_list **list)
        *list = ret;
 }
 
-struct commit *pop_most_recent_commit(struct commit_list **list)
+struct commit *pop_most_recent_commit(struct commit_list **list,
+                                     unsigned int mark)
 {
        struct commit *ret = (*list)->item;
        struct commit_list *parents = ret->parents;
@@ -124,8 +125,12 @@ struct commit *pop_most_recent_commit(struct commit_list **list)
        free(old);
 
        while (parents) {
-               parse_commit(parents->item);
-               insert_by_date(list, parents->item);
+               struct commit *commit = parents->item;
+               parse_commit(commit);
+               if (!(commit->object.flags & mark)) {
+                       commit->object.flags |= mark;
+                       insert_by_date(list, commit);
+               }
                parents = parents->next;
        }
        return ret;