4 #include "repository.h"
7 #include "object-store.h"
13 #include "oid-array.h"
16 #include "commit-slab.h"
17 #include "list-objects.h"
18 #include "commit-reach.h"
22 void set_alternate_shallow_file(struct repository
*r
, const char *path
, int override
)
24 if (r
->parsed_objects
->is_shallow
!= -1)
25 BUG("is_repository_shallow must not be called before set_alternate_shallow_file");
26 if (r
->parsed_objects
->alternate_shallow_file
&& !override
)
28 free(r
->parsed_objects
->alternate_shallow_file
);
29 r
->parsed_objects
->alternate_shallow_file
= xstrdup_or_null(path
);
32 int register_shallow(struct repository
*r
, const struct object_id
*oid
)
34 struct commit_graft
*graft
=
35 xmalloc(sizeof(struct commit_graft
));
36 struct commit
*commit
= lookup_commit(the_repository
, oid
);
38 oidcpy(&graft
->oid
, oid
);
39 graft
->nr_parent
= -1;
40 if (commit
&& commit
->object
.parsed
)
41 commit
->parents
= NULL
;
42 return register_commit_graft(r
, graft
, 0);
45 int unregister_shallow(const struct object_id
*oid
)
47 int pos
= commit_graft_pos(the_repository
, oid
);
50 if (pos
+ 1 < the_repository
->parsed_objects
->grafts_nr
)
51 MOVE_ARRAY(the_repository
->parsed_objects
->grafts
+ pos
,
52 the_repository
->parsed_objects
->grafts
+ pos
+ 1,
53 the_repository
->parsed_objects
->grafts_nr
- pos
- 1);
54 the_repository
->parsed_objects
->grafts_nr
--;
58 int is_repository_shallow(struct repository
*r
)
62 const char *path
= r
->parsed_objects
->alternate_shallow_file
;
64 if (r
->parsed_objects
->is_shallow
>= 0)
65 return r
->parsed_objects
->is_shallow
;
68 path
= git_path_shallow(r
);
70 * fetch-pack sets '--shallow-file ""' as an indicator that no
71 * shallow file should be used. We could just open it and it
72 * will likely fail. But let's do an explicit check instead.
74 if (!*path
|| (fp
= fopen(path
, "r")) == NULL
) {
75 stat_validity_clear(r
->parsed_objects
->shallow_stat
);
76 r
->parsed_objects
->is_shallow
= 0;
77 return r
->parsed_objects
->is_shallow
;
79 stat_validity_update(r
->parsed_objects
->shallow_stat
, fileno(fp
));
80 r
->parsed_objects
->is_shallow
= 1;
82 while (fgets(buf
, sizeof(buf
), fp
)) {
84 if (get_oid_hex(buf
, &oid
))
85 die("bad shallow line: %s", buf
);
86 register_shallow(r
, &oid
);
89 return r
->parsed_objects
->is_shallow
;
92 static void reset_repository_shallow(struct repository
*r
)
94 r
->parsed_objects
->is_shallow
= -1;
95 stat_validity_clear(r
->parsed_objects
->shallow_stat
);
96 reset_commit_grafts(r
);
99 int commit_shallow_file(struct repository
*r
, struct shallow_lock
*lk
)
101 int res
= commit_lock_file(&lk
->lock
);
102 reset_repository_shallow(r
);
105 * Update in-memory data structures with the new shallow information,
106 * including unparsing all commits that now have grafts.
108 is_repository_shallow(r
);
113 void rollback_shallow_file(struct repository
*r
, struct shallow_lock
*lk
)
115 rollback_lock_file(&lk
->lock
);
116 reset_repository_shallow(r
);
120 * TODO: use "int" elemtype instead of "int *" when/if commit-slab
121 * supports a "valid" flag.
123 define_commit_slab(commit_depth
, int *);
124 static void free_depth_in_slab(int **ptr
)
128 struct commit_list
*get_shallow_commits(struct object_array
*heads
, int depth
,
129 int shallow_flag
, int not_shallow_flag
)
131 int i
= 0, cur_depth
= 0;
132 struct commit_list
*result
= NULL
;
133 struct object_array stack
= OBJECT_ARRAY_INIT
;
134 struct commit
*commit
= NULL
;
135 struct commit_graft
*graft
;
136 struct commit_depth depths
;
138 init_commit_depth(&depths
);
139 while (commit
|| i
< heads
->nr
|| stack
.nr
) {
140 struct commit_list
*p
;
144 commit
= (struct commit
*)
145 deref_tag(the_repository
,
146 heads
->objects
[i
++].item
,
148 if (!commit
|| commit
->object
.type
!= OBJ_COMMIT
) {
152 depth_slot
= commit_depth_at(&depths
, commit
);
154 *depth_slot
= xmalloc(sizeof(int));
158 commit
= (struct commit
*)
159 object_array_pop(&stack
);
160 cur_depth
= **commit_depth_at(&depths
, commit
);
163 parse_commit_or_die(commit
);
165 if ((depth
!= INFINITE_DEPTH
&& cur_depth
>= depth
) ||
166 (is_repository_shallow(the_repository
) && !commit
->parents
&&
167 (graft
= lookup_commit_graft(the_repository
, &commit
->object
.oid
)) != NULL
&&
168 graft
->nr_parent
< 0)) {
169 commit_list_insert(commit
, &result
);
170 commit
->object
.flags
|= shallow_flag
;
174 commit
->object
.flags
|= not_shallow_flag
;
175 for (p
= commit
->parents
, commit
= NULL
; p
; p
= p
->next
) {
176 int **depth_slot
= commit_depth_at(&depths
, p
->item
);
178 *depth_slot
= xmalloc(sizeof(int));
179 **depth_slot
= cur_depth
;
181 if (cur_depth
>= **depth_slot
)
183 **depth_slot
= cur_depth
;
186 add_object_array(&p
->item
->object
,
190 cur_depth
= **commit_depth_at(&depths
, commit
);
194 deep_clear_commit_depth(&depths
, free_depth_in_slab
);
199 static void show_commit(struct commit
*commit
, void *data
)
201 commit_list_insert(commit
, data
);
205 * Given rev-list arguments, run rev-list. All reachable commits
206 * except border ones are marked with not_shallow_flag. Border commits
207 * are marked with shallow_flag. The list of border/shallow commits
210 struct commit_list
*get_shallow_commits_by_rev_list(int ac
, const char **av
,
212 int not_shallow_flag
)
214 struct commit_list
*result
= NULL
, *p
;
215 struct commit_list
*not_shallow_list
= NULL
;
216 struct rev_info revs
;
217 int both_flags
= shallow_flag
| not_shallow_flag
;
220 * SHALLOW (excluded) and NOT_SHALLOW (included) should not be
221 * set at this point. But better be safe than sorry.
223 clear_object_flags(both_flags
);
225 is_repository_shallow(the_repository
); /* make sure shallows are read */
227 repo_init_revisions(the_repository
, &revs
, NULL
);
228 save_commit_buffer
= 0;
229 setup_revisions(ac
, av
, &revs
, NULL
);
231 if (prepare_revision_walk(&revs
))
232 die("revision walk setup failed");
233 traverse_commit_list(&revs
, show_commit
, NULL
, ¬_shallow_list
);
235 if (!not_shallow_list
)
236 die("no commits selected for shallow requests");
238 /* Mark all reachable commits as NOT_SHALLOW */
239 for (p
= not_shallow_list
; p
; p
= p
->next
)
240 p
->item
->object
.flags
|= not_shallow_flag
;
243 * mark border commits SHALLOW + NOT_SHALLOW.
244 * We cannot clear NOT_SHALLOW right now. Imagine border
245 * commit A is processed first, then commit B, whose parent is
246 * A, later. If NOT_SHALLOW on A is cleared at step 1, B
247 * itself is considered border at step 2, which is incorrect.
249 for (p
= not_shallow_list
; p
; p
= p
->next
) {
250 struct commit
*c
= p
->item
;
251 struct commit_list
*parent
;
254 die("unable to parse commit %s",
255 oid_to_hex(&c
->object
.oid
));
257 for (parent
= c
->parents
; parent
; parent
= parent
->next
)
258 if (!(parent
->item
->object
.flags
& not_shallow_flag
)) {
259 c
->object
.flags
|= shallow_flag
;
260 commit_list_insert(c
, &result
);
264 free_commit_list(not_shallow_list
);
267 * Now we can clean up NOT_SHALLOW on border commits. Having
268 * both flags set can confuse the caller.
270 for (p
= result
; p
; p
= p
->next
) {
271 struct object
*o
= &p
->item
->object
;
272 if ((o
->flags
& both_flags
) == both_flags
)
273 o
->flags
&= ~not_shallow_flag
;
275 release_revisions(&revs
);
279 static void check_shallow_file_for_update(struct repository
*r
)
281 if (r
->parsed_objects
->is_shallow
== -1)
282 BUG("shallow must be initialized by now");
284 if (!stat_validity_check(r
->parsed_objects
->shallow_stat
,
285 git_path_shallow(r
)))
286 die("shallow file has changed since we read it");
293 struct write_shallow_data
{
295 int use_pack_protocol
;
300 static int write_one_shallow(const struct commit_graft
*graft
, void *cb_data
)
302 struct write_shallow_data
*data
= cb_data
;
303 const char *hex
= oid_to_hex(&graft
->oid
);
304 if (graft
->nr_parent
!= -1)
306 if (data
->flags
& QUICK
) {
307 if (!has_object_file(&graft
->oid
))
309 } else if (data
->flags
& SEEN_ONLY
) {
310 struct commit
*c
= lookup_commit(the_repository
, &graft
->oid
);
311 if (!c
|| !(c
->object
.flags
& SEEN
)) {
312 if (data
->flags
& VERBOSE
)
313 printf("Removing %s from .git/shallow\n",
314 oid_to_hex(&c
->object
.oid
));
319 if (data
->use_pack_protocol
)
320 packet_buf_write(data
->out
, "shallow %s", hex
);
322 strbuf_addstr(data
->out
, hex
);
323 strbuf_addch(data
->out
, '\n');
328 static int write_shallow_commits_1(struct strbuf
*out
, int use_pack_protocol
,
329 const struct oid_array
*extra
,
332 struct write_shallow_data data
;
335 data
.use_pack_protocol
= use_pack_protocol
;
338 for_each_commit_graft(write_one_shallow
, &data
);
341 for (i
= 0; i
< extra
->nr
; i
++) {
342 strbuf_addstr(out
, oid_to_hex(extra
->oid
+ i
));
343 strbuf_addch(out
, '\n');
349 int write_shallow_commits(struct strbuf
*out
, int use_pack_protocol
,
350 const struct oid_array
*extra
)
352 return write_shallow_commits_1(out
, use_pack_protocol
, extra
, 0);
355 const char *setup_temporary_shallow(const struct oid_array
*extra
)
357 struct tempfile
*temp
;
358 struct strbuf sb
= STRBUF_INIT
;
360 if (write_shallow_commits(&sb
, 0, extra
)) {
361 temp
= xmks_tempfile(git_path("shallow_XXXXXX"));
363 if (write_in_full(temp
->fd
, sb
.buf
, sb
.len
) < 0 ||
364 close_tempfile_gently(temp
) < 0)
365 die_errno("failed to write to %s",
366 get_tempfile_path(temp
));
368 return get_tempfile_path(temp
);
371 * is_repository_shallow() sees empty string as "no shallow
377 void setup_alternate_shallow(struct shallow_lock
*shallow_lock
,
378 const char **alternate_shallow_file
,
379 const struct oid_array
*extra
)
381 struct strbuf sb
= STRBUF_INIT
;
384 fd
= hold_lock_file_for_update(&shallow_lock
->lock
,
385 git_path_shallow(the_repository
),
387 check_shallow_file_for_update(the_repository
);
388 if (write_shallow_commits(&sb
, 0, extra
)) {
389 if (write_in_full(fd
, sb
.buf
, sb
.len
) < 0)
390 die_errno("failed to write to %s",
391 get_lock_file_path(&shallow_lock
->lock
));
392 *alternate_shallow_file
= get_lock_file_path(&shallow_lock
->lock
);
395 * is_repository_shallow() sees empty string as "no
398 *alternate_shallow_file
= "";
402 static int advertise_shallow_grafts_cb(const struct commit_graft
*graft
, void *cb
)
405 if (graft
->nr_parent
== -1)
406 packet_write_fmt(fd
, "shallow %s\n", oid_to_hex(&graft
->oid
));
410 void advertise_shallow_grafts(int fd
)
412 if (!is_repository_shallow(the_repository
))
414 for_each_commit_graft(advertise_shallow_grafts_cb
, &fd
);
418 * mark_reachable_objects() should have been run prior to this and all
419 * reachable commits marked as "SEEN", except when quick_prune is non-zero,
420 * in which case lines are excised from the shallow file if they refer to
421 * commits that do not exist (any longer).
423 void prune_shallow(unsigned options
)
425 struct shallow_lock shallow_lock
= SHALLOW_LOCK_INIT
;
426 struct strbuf sb
= STRBUF_INIT
;
427 unsigned flags
= SEEN_ONLY
;
430 if (options
& PRUNE_QUICK
)
433 if (options
& PRUNE_SHOW_ONLY
) {
435 write_shallow_commits_1(&sb
, 0, NULL
, flags
);
439 fd
= hold_lock_file_for_update(&shallow_lock
.lock
,
440 git_path_shallow(the_repository
),
442 check_shallow_file_for_update(the_repository
);
443 if (write_shallow_commits_1(&sb
, 0, NULL
, flags
)) {
444 if (write_in_full(fd
, sb
.buf
, sb
.len
) < 0)
445 die_errno("failed to write to %s",
446 get_lock_file_path(&shallow_lock
.lock
));
447 commit_shallow_file(the_repository
, &shallow_lock
);
449 unlink(git_path_shallow(the_repository
));
450 rollback_shallow_file(the_repository
, &shallow_lock
);
455 struct trace_key trace_shallow
= TRACE_KEY_INIT(SHALLOW
);
458 * Step 1, split sender shallow commits into "ours" and "theirs"
459 * Step 2, clean "ours" based on .git/shallow
461 void prepare_shallow_info(struct shallow_info
*info
, struct oid_array
*sa
)
464 trace_printf_key(&trace_shallow
, "shallow: prepare_shallow_info\n");
465 memset(info
, 0, sizeof(*info
));
469 ALLOC_ARRAY(info
->ours
, sa
->nr
);
470 ALLOC_ARRAY(info
->theirs
, sa
->nr
);
471 for (i
= 0; i
< sa
->nr
; i
++) {
472 if (has_object_file(sa
->oid
+ i
)) {
473 struct commit_graft
*graft
;
474 graft
= lookup_commit_graft(the_repository
,
476 if (graft
&& graft
->nr_parent
< 0)
478 info
->ours
[info
->nr_ours
++] = i
;
480 info
->theirs
[info
->nr_theirs
++] = i
;
484 void clear_shallow_info(struct shallow_info
*info
)
490 /* Step 4, remove non-existent ones in "theirs" after getting the pack */
492 void remove_nonexistent_theirs_shallow(struct shallow_info
*info
)
494 struct object_id
*oid
= info
->shallow
->oid
;
496 trace_printf_key(&trace_shallow
, "shallow: remove_nonexistent_theirs_shallow\n");
497 for (i
= dst
= 0; i
< info
->nr_theirs
; i
++) {
499 info
->theirs
[dst
] = info
->theirs
[i
];
500 if (has_object_file(oid
+ info
->theirs
[i
]))
503 info
->nr_theirs
= dst
;
506 define_commit_slab(ref_bitmap
, uint32_t *);
508 #define POOL_SIZE (512 * 1024)
511 struct ref_bitmap ref_bitmap
;
518 static uint32_t *paint_alloc(struct paint_info
*info
)
520 unsigned nr
= DIV_ROUND_UP(info
->nr_bits
, 32);
521 unsigned size
= nr
* sizeof(uint32_t);
523 if (!info
->pool_count
|| size
> info
->end
- info
->free
) {
524 if (size
> POOL_SIZE
)
525 BUG("pool size too small for %d in paint_alloc()",
528 REALLOC_ARRAY(info
->pools
, info
->pool_count
);
529 info
->free
= xmalloc(POOL_SIZE
);
530 info
->pools
[info
->pool_count
- 1] = info
->free
;
531 info
->end
= info
->free
+ POOL_SIZE
;
539 * Given a commit SHA-1, walk down to parents until either SEEN,
540 * UNINTERESTING or BOTTOM is hit. Set the id-th bit in ref_bitmap for
541 * all walked commits.
543 static void paint_down(struct paint_info
*info
, const struct object_id
*oid
,
547 struct commit_list
*head
= NULL
;
548 int bitmap_nr
= DIV_ROUND_UP(info
->nr_bits
, 32);
549 size_t bitmap_size
= st_mult(sizeof(uint32_t), bitmap_nr
);
550 struct commit
*c
= lookup_commit_reference_gently(the_repository
, oid
,
552 uint32_t *tmp
; /* to be freed before return */
558 tmp
= xmalloc(bitmap_size
);
559 bitmap
= paint_alloc(info
);
560 memset(bitmap
, 0, bitmap_size
);
561 bitmap
[id
/ 32] |= (1U << (id
% 32));
562 commit_list_insert(c
, &head
);
564 struct commit_list
*p
;
565 struct commit
*c
= pop_commit(&head
);
566 uint32_t **refs
= ref_bitmap_at(&info
->ref_bitmap
, c
);
568 /* XXX check "UNINTERESTING" from pack bitmaps if available */
569 if (c
->object
.flags
& (SEEN
| UNINTERESTING
))
572 c
->object
.flags
|= SEEN
;
577 memcpy(tmp
, *refs
, bitmap_size
);
578 for (i
= 0; i
< bitmap_nr
; i
++)
580 if (memcmp(tmp
, *refs
, bitmap_size
)) {
581 *refs
= paint_alloc(info
);
582 memcpy(*refs
, tmp
, bitmap_size
);
586 if (c
->object
.flags
& BOTTOM
)
590 die("unable to parse commit %s",
591 oid_to_hex(&c
->object
.oid
));
593 for (p
= c
->parents
; p
; p
= p
->next
) {
594 if (p
->item
->object
.flags
& SEEN
)
596 commit_list_insert(p
->item
, &head
);
600 nr
= get_max_object_index();
601 for (i
= 0; i
< nr
; i
++) {
602 struct object
*o
= get_indexed_object(i
);
603 if (o
&& o
->type
== OBJ_COMMIT
)
610 static int mark_uninteresting(const char *refname UNUSED
,
611 const struct object_id
*oid
,
613 void *cb_data UNUSED
)
615 struct commit
*commit
= lookup_commit_reference_gently(the_repository
,
619 commit
->object
.flags
|= UNINTERESTING
;
620 mark_parents_uninteresting(NULL
, commit
);
624 static void post_assign_shallow(struct shallow_info
*info
,
625 struct ref_bitmap
*ref_bitmap
,
628 * Step 6(+7), associate shallow commits with new refs
630 * info->ref must be initialized before calling this function.
632 * If used is not NULL, it's an array of info->shallow->nr
633 * bitmaps. The n-th bit set in the m-th bitmap if ref[n] needs the
634 * m-th shallow commit from info->shallow.
636 * If used is NULL, "ours" and "theirs" are updated. And if ref_status
637 * is not NULL it's an array of ref->nr ints. ref_status[i] is true if
638 * the ref needs some shallow commits from either info->ours or
641 void assign_shallow_commits_to_refs(struct shallow_info
*info
,
642 uint32_t **used
, int *ref_status
)
644 struct object_id
*oid
= info
->shallow
->oid
;
645 struct oid_array
*ref
= info
->ref
;
647 int *shallow
, nr_shallow
= 0;
648 struct paint_info pi
;
650 trace_printf_key(&trace_shallow
, "shallow: assign_shallow_commits_to_refs\n");
651 ALLOC_ARRAY(shallow
, info
->nr_ours
+ info
->nr_theirs
);
652 for (i
= 0; i
< info
->nr_ours
; i
++)
653 shallow
[nr_shallow
++] = info
->ours
[i
];
654 for (i
= 0; i
< info
->nr_theirs
; i
++)
655 shallow
[nr_shallow
++] = info
->theirs
[i
];
658 * Prepare the commit graph to track what refs can reach what
659 * (new) shallow commits.
661 nr
= get_max_object_index();
662 for (i
= 0; i
< nr
; i
++) {
663 struct object
*o
= get_indexed_object(i
);
664 if (!o
|| o
->type
!= OBJ_COMMIT
)
667 o
->flags
&= ~(UNINTERESTING
| BOTTOM
| SEEN
);
670 memset(&pi
, 0, sizeof(pi
));
671 init_ref_bitmap(&pi
.ref_bitmap
);
672 pi
.nr_bits
= ref
->nr
;
675 * "--not --all" to cut short the traversal if new refs
676 * connect to old refs. If not (e.g. force ref updates) it'll
677 * have to go down to the current shallow commits.
679 head_ref(mark_uninteresting
, NULL
);
680 for_each_ref(mark_uninteresting
, NULL
);
682 /* Mark potential bottoms so we won't go out of bound */
683 for (i
= 0; i
< nr_shallow
; i
++) {
684 struct commit
*c
= lookup_commit(the_repository
,
686 c
->object
.flags
|= BOTTOM
;
689 for (i
= 0; i
< ref
->nr
; i
++)
690 paint_down(&pi
, ref
->oid
+ i
, i
);
693 int bitmap_size
= DIV_ROUND_UP(pi
.nr_bits
, 32) * sizeof(uint32_t);
694 memset(used
, 0, sizeof(*used
) * info
->shallow
->nr
);
695 for (i
= 0; i
< nr_shallow
; i
++) {
696 const struct commit
*c
= lookup_commit(the_repository
,
698 uint32_t **map
= ref_bitmap_at(&pi
.ref_bitmap
, c
);
700 used
[shallow
[i
]] = xmemdupz(*map
, bitmap_size
);
703 * unreachable shallow commits are not removed from
704 * "ours" and "theirs". The user is supposed to run
705 * step 7 on every ref separately and not trust "ours"
706 * and "theirs" any more.
709 post_assign_shallow(info
, &pi
.ref_bitmap
, ref_status
);
711 clear_ref_bitmap(&pi
.ref_bitmap
);
712 for (i
= 0; i
< pi
.pool_count
; i
++)
718 struct commit_array
{
719 struct commit
**commits
;
723 static int add_ref(const char *refname UNUSED
,
724 const struct object_id
*oid
,
728 struct commit_array
*ca
= cb_data
;
729 ALLOC_GROW(ca
->commits
, ca
->nr
+ 1, ca
->alloc
);
730 ca
->commits
[ca
->nr
] = lookup_commit_reference_gently(the_repository
,
732 if (ca
->commits
[ca
->nr
])
737 static void update_refstatus(int *ref_status
, int nr
, uint32_t *bitmap
)
742 for (i
= 0; i
< nr
; i
++)
743 if (bitmap
[i
/ 32] & (1U << (i
% 32)))
748 * Step 7, reachability test on "ours" at commit level
750 static void post_assign_shallow(struct shallow_info
*info
,
751 struct ref_bitmap
*ref_bitmap
,
754 struct object_id
*oid
= info
->shallow
->oid
;
758 int bitmap_nr
= DIV_ROUND_UP(info
->ref
->nr
, 32);
759 struct commit_array ca
;
761 trace_printf_key(&trace_shallow
, "shallow: post_assign_shallow\n");
763 memset(ref_status
, 0, sizeof(*ref_status
) * info
->ref
->nr
);
765 /* Remove unreachable shallow commits from "theirs" */
766 for (i
= dst
= 0; i
< info
->nr_theirs
; i
++) {
768 info
->theirs
[dst
] = info
->theirs
[i
];
769 c
= lookup_commit(the_repository
, &oid
[info
->theirs
[i
]]);
770 bitmap
= ref_bitmap_at(ref_bitmap
, c
);
773 for (j
= 0; j
< bitmap_nr
; j
++)
775 update_refstatus(ref_status
, info
->ref
->nr
, *bitmap
);
780 info
->nr_theirs
= dst
;
782 memset(&ca
, 0, sizeof(ca
));
783 head_ref(add_ref
, &ca
);
784 for_each_ref(add_ref
, &ca
);
786 /* Remove unreachable shallow commits from "ours" */
787 for (i
= dst
= 0; i
< info
->nr_ours
; i
++) {
789 info
->ours
[dst
] = info
->ours
[i
];
790 c
= lookup_commit(the_repository
, &oid
[info
->ours
[i
]]);
791 bitmap
= ref_bitmap_at(ref_bitmap
, c
);
794 for (j
= 0; j
< bitmap_nr
; j
++)
796 /* Step 7, reachability test at commit level */
797 !in_merge_bases_many(c
, ca
.nr
, ca
.commits
)) {
798 update_refstatus(ref_status
, info
->ref
->nr
, *bitmap
);
808 /* (Delayed) step 7, reachability test at commit level */
809 int delayed_reachability_test(struct shallow_info
*si
, int c
)
811 if (si
->need_reachability_test
[c
]) {
812 struct commit
*commit
= lookup_commit(the_repository
,
813 &si
->shallow
->oid
[c
]);
816 struct commit_array ca
;
818 memset(&ca
, 0, sizeof(ca
));
819 head_ref(add_ref
, &ca
);
820 for_each_ref(add_ref
, &ca
);
821 si
->commits
= ca
.commits
;
822 si
->nr_commits
= ca
.nr
;
825 si
->reachable
[c
] = in_merge_bases_many(commit
,
828 si
->need_reachability_test
[c
] = 0;
830 return si
->reachable
[c
];