5 static int is_shallow
= -1;
7 int register_shallow(const unsigned char *sha1
)
9 struct commit_graft
*graft
=
10 xmalloc(sizeof(struct commit_graft
));
11 struct commit
*commit
= lookup_commit(sha1
);
13 hashcpy(graft
->sha1
, sha1
);
14 graft
->nr_parent
= -1;
15 if (commit
&& commit
->object
.parsed
)
16 commit
->parents
= NULL
;
17 return register_commit_graft(graft
, 0);
20 int is_repository_shallow(void)
28 fp
= fopen(git_path("shallow"), "r");
35 while (fgets(buf
, sizeof(buf
), fp
)) {
36 unsigned char sha1
[20];
37 if (get_sha1_hex(buf
, sha1
))
38 die("bad shallow line: %s", buf
);
39 register_shallow(sha1
);
45 struct commit_list
*get_shallow_commits(struct object_array
*heads
, int depth
,
46 int shallow_flag
, int not_shallow_flag
)
48 int i
= 0, cur_depth
= 0;
49 struct commit_list
*result
= NULL
;
50 struct object_array stack
= OBJECT_ARRAY_INIT
;
51 struct commit
*commit
= NULL
;
53 while (commit
|| i
< heads
->nr
|| stack
.nr
) {
54 struct commit_list
*p
;
57 commit
= (struct commit
*)
58 deref_tag(heads
->objects
[i
++].item
, NULL
, 0);
59 if (!commit
|| commit
->object
.type
!= OBJ_COMMIT
) {
64 commit
->util
= xmalloc(sizeof(int));
65 *(int *)commit
->util
= 0;
68 commit
= (struct commit
*)
69 stack
.objects
[--stack
.nr
].item
;
70 cur_depth
= *(int *)commit
->util
;
73 if (parse_commit(commit
))
74 die("invalid commit");
76 if (cur_depth
>= depth
) {
77 commit_list_insert(commit
, &result
);
78 commit
->object
.flags
|= shallow_flag
;
82 commit
->object
.flags
|= not_shallow_flag
;
83 for (p
= commit
->parents
, commit
= NULL
; p
; p
= p
->next
) {
85 int *pointer
= xmalloc(sizeof(int));
86 p
->item
->util
= pointer
;
89 int *pointer
= p
->item
->util
;
90 if (cur_depth
>= *pointer
)
94 if (cur_depth
< depth
) {
96 add_object_array(&p
->item
->object
,
100 cur_depth
= *(int *)commit
->util
;
103 commit_list_insert(p
->item
, &result
);
104 p
->item
->object
.flags
|= shallow_flag
;