Git.pm: fix example in command_close_bidi_pipe documentation
[gitweb.git] / shallow.c
index 4d90eda19efe0a80c1cb39e8897ab3ed5e6fcf56..6be915f38f1fe8dbe0a22c4cd8ae2569331f483f 100644 (file)
--- a/shallow.c
+++ b/shallow.c
@@ -47,7 +47,7 @@ struct commit_list *get_shallow_commits(struct object_array *heads, int depth,
 {
        int i = 0, cur_depth = 0;
        struct commit_list *result = NULL;
-       struct object_array stack = {0, 0, NULL};
+       struct object_array stack = OBJECT_ARRAY_INIT;
        struct commit *commit = NULL;
 
        while (commit || i < heads->nr || stack.nr) {
@@ -72,8 +72,14 @@ struct commit_list *get_shallow_commits(struct object_array *heads, int depth,
                }
                if (parse_commit(commit))
                        die("invalid commit");
-               commit->object.flags |= not_shallow_flag;
                cur_depth++;
+               if (cur_depth >= depth) {
+                       commit_list_insert(commit, &result);
+                       commit->object.flags |= shallow_flag;
+                       commit = NULL;
+                       continue;
+               }
+               commit->object.flags |= not_shallow_flag;
                for (p = commit->parents, commit = NULL; p; p = p->next) {
                        if (!p->item->util) {
                                int *pointer = xmalloc(sizeof(int));