Code

test-lib: fail if invalid options are passed
[git.git] / commit.c
index c99db162a48e0a47e73e6bfc2ae5fd4b7c9dfa1a..8f6b703c557599921d890c3b50b66eaa397de548 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -316,6 +316,26 @@ int parse_commit(struct commit *item)
        return ret;
 }
 
+static void unparse_commit_list(struct commit_list *list)
+{
+       for (; list; list = list->next)
+               unparse_commit(list->item);
+}
+
+void unparse_commit(struct commit *item)
+{
+       item->object.flags = 0;
+       item->object.used = 0;
+       if (item->object.parsed) {
+               item->object.parsed = 0;
+               if (item->parents) {
+                       unparse_commit_list(item->parents);
+                       free_commit_list(item->parents);
+                       item->parents = NULL;
+               }
+       }
+}
+
 struct commit_list *commit_list_insert(struct commit *item, struct commit_list **list_p)
 {
        struct commit_list *new_list = xmalloc(sizeof(struct commit_list));
@@ -705,6 +725,21 @@ struct commit_list *get_merge_bases(struct commit *one, struct commit *two,
        return get_merge_bases_many(one, 1, &two, cleanup);
 }
 
+int is_descendant_of(struct commit *commit, struct commit_list *with_commit)
+{
+       if (!with_commit)
+               return 1;
+       while (with_commit) {
+               struct commit *other;
+
+               other = with_commit->item;
+               with_commit = with_commit->next;
+               if (in_merge_bases(other, &commit, 1))
+                       return 1;
+       }
+       return 0;
+}
+
 int in_merge_bases(struct commit *commit, struct commit **reference, int num)
 {
        struct commit_list *bases, *b;