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)
46 int i = 0, cur_depth = 0;
47 struct commit_list *result = NULL;
48 struct object_array stack = {0, 0, NULL};
49 struct commit *commit = NULL;
51 while (commit || i < heads->nr || stack.nr) {
52 struct commit_list *p;
55 commit = (struct commit *)
56 heads->objects[i++].item;
57 if (commit->object.type != OBJ_COMMIT) {
61 commit->util = xcalloc(1, sizeof(int));
64 commit = (struct commit *)
65 stack.objects[--stack.nr].item;
66 cur_depth = *(int *)commit->util;
71 for (p = commit->parents, commit = NULL; p; p = p->next) {
73 int *pointer = xmalloc(sizeof(int));
74 p->item->util = pointer;
77 int *pointer = p->item->util;
78 if (cur_depth >= *pointer)
82 if (cur_depth < depth) {
84 add_object_array(&p->item->object,
88 cur_depth = *(int *)commit->util;
91 commit_list_insert(p->item, &result);