4 static int is_shallow = -1;
6 int register_shallow(const unsigned char *sha1)
8 struct commit_graft *graft =
9 xmalloc(sizeof(struct commit_graft));
10 struct commit *commit = lookup_commit(sha1);
12 hashcpy(graft->sha1, sha1);
13 graft->nr_parent = -1;
14 if (commit && commit->object.parsed)
15 commit->parents = NULL;
16 return register_commit_graft(graft, 0);
19 int is_repository_shallow()
27 fp = fopen(git_path("shallow"), "r");
34 while (fgets(buf, sizeof(buf), fp)) {
35 unsigned char sha1[20];
36 if (get_sha1_hex(buf, sha1))
37 die("bad shallow line: %s", buf);
38 register_shallow(sha1);
44 struct commit_list *get_shallow_commits(struct object_array *heads, int depth,
45 int shallow_flag, int not_shallow_flag)
47 int i = 0, cur_depth = 0;
48 struct commit_list *result = NULL;
49 struct object_array stack = {0, 0, NULL};
50 struct commit *commit = NULL;
52 while (commit || i < heads->nr || stack.nr) {
53 struct commit_list *p;
56 commit = (struct commit *)
57 heads->objects[i++].item;
58 if (commit->object.type != OBJ_COMMIT) {
62 commit->util = xcalloc(1, sizeof(int));
65 commit = (struct commit *)
66 stack.objects[--stack.nr].item;
67 cur_depth = *(int *)commit->util;
71 commit->object.flags |= not_shallow_flag;
73 for (p = commit->parents, commit = NULL; p; p = p->next) {
75 int *pointer = xmalloc(sizeof(int));
76 p->item->util = pointer;
79 int *pointer = p->item->util;
80 if (cur_depth >= *pointer)
84 if (cur_depth < depth) {
86 add_object_array(&p->item->object,
90 cur_depth = *(int *)commit->util;
93 commit_list_insert(p->item, &result);
94 p->item->object.flags |= shallow_flag;