1 #define USE_THE_REPOSITORY_VARIABLE
3 #include "git-compat-util.h"
5 #include "repository.h"
8 #include "object-store-ll.h"
13 #include "oid-array.h"
17 #include "commit-slab.h"
18 #include "list-objects.h"
19 #include "commit-reach.h"
24 void set_alternate_shallow_file(struct repository
*r
, const char *path
, int override
)
26 if (r
->parsed_objects
->is_shallow
!= -1)
27 BUG("is_repository_shallow must not be called before set_alternate_shallow_file");
28 if (r
->parsed_objects
->alternate_shallow_file
&& !override
)
30 free(r
->parsed_objects
->alternate_shallow_file
);
31 r
->parsed_objects
->alternate_shallow_file
= xstrdup_or_null(path
);
34 int register_shallow(struct repository
*r
, const struct object_id
*oid
)
36 struct commit_graft
*graft
=
37 xmalloc(sizeof(struct commit_graft
));
38 struct commit
*commit
= lookup_commit(r
, oid
);
40 oidcpy(&graft
->oid
, oid
);
41 graft
->nr_parent
= -1;
42 if (commit
&& commit
->object
.parsed
) {
43 free_commit_list(commit
->parents
);
44 commit
->parents
= NULL
;
46 return register_commit_graft(r
, graft
, 0);
49 int unregister_shallow(const struct object_id
*oid
)
51 int pos
= commit_graft_pos(the_repository
, oid
);
54 if (pos
+ 1 < the_repository
->parsed_objects
->grafts_nr
) {
55 free(the_repository
->parsed_objects
->grafts
[pos
]);
56 MOVE_ARRAY(the_repository
->parsed_objects
->grafts
+ pos
,
57 the_repository
->parsed_objects
->grafts
+ pos
+ 1,
58 the_repository
->parsed_objects
->grafts_nr
- pos
- 1);
60 the_repository
->parsed_objects
->grafts_nr
--;
64 int is_repository_shallow(struct repository
*r
)
68 const char *path
= r
->parsed_objects
->alternate_shallow_file
;
70 if (r
->parsed_objects
->is_shallow
>= 0)
71 return r
->parsed_objects
->is_shallow
;
74 path
= git_path_shallow(r
);
76 * fetch-pack sets '--shallow-file ""' as an indicator that no
77 * shallow file should be used. We could just open it and it
78 * will likely fail. But let's do an explicit check instead.
80 if (!*path
|| (fp
= fopen(path
, "r")) == NULL
) {
81 stat_validity_clear(r
->parsed_objects
->shallow_stat
);
82 r
->parsed_objects
->is_shallow
= 0;
83 return r
->parsed_objects
->is_shallow
;
85 stat_validity_update(r
->parsed_objects
->shallow_stat
, fileno(fp
));
86 r
->parsed_objects
->is_shallow
= 1;
88 while (fgets(buf
, sizeof(buf
), fp
)) {
90 if (get_oid_hex(buf
, &oid
))
91 die("bad shallow line: %s", buf
);
92 register_shallow(r
, &oid
);
95 return r
->parsed_objects
->is_shallow
;
98 static void reset_repository_shallow(struct repository
*r
)
100 r
->parsed_objects
->is_shallow
= -1;
101 stat_validity_clear(r
->parsed_objects
->shallow_stat
);
102 parsed_object_pool_reset_commit_grafts(r
->parsed_objects
);
105 int commit_shallow_file(struct repository
*r
, struct shallow_lock
*lk
)
107 int res
= commit_lock_file(&lk
->lock
);
108 reset_repository_shallow(r
);
111 * Update in-memory data structures with the new shallow information,
112 * including unparsing all commits that now have grafts.
114 is_repository_shallow(r
);
119 void rollback_shallow_file(struct repository
*r
, struct shallow_lock
*lk
)
121 rollback_lock_file(&lk
->lock
);
122 reset_repository_shallow(r
);
126 * TODO: use "int" elemtype instead of "int *" when/if commit-slab
127 * supports a "valid" flag.
129 define_commit_slab(commit_depth
, int *);
130 static void free_depth_in_slab(int **ptr
)
134 struct commit_list
*get_shallow_commits(struct object_array
*heads
, int depth
,
135 int shallow_flag
, int not_shallow_flag
)
137 int i
= 0, cur_depth
= 0;
138 struct commit_list
*result
= NULL
;
139 struct object_array stack
= OBJECT_ARRAY_INIT
;
140 struct commit
*commit
= NULL
;
141 struct commit_graft
*graft
;
142 struct commit_depth depths
;
144 init_commit_depth(&depths
);
145 while (commit
|| i
< heads
->nr
|| stack
.nr
) {
146 struct commit_list
*p
;
150 commit
= (struct commit
*)
151 deref_tag(the_repository
,
152 heads
->objects
[i
++].item
,
154 if (!commit
|| commit
->object
.type
!= OBJ_COMMIT
) {
158 depth_slot
= commit_depth_at(&depths
, commit
);
160 *depth_slot
= xmalloc(sizeof(int));
164 commit
= (struct commit
*)
165 object_array_pop(&stack
);
166 cur_depth
= **commit_depth_at(&depths
, commit
);
169 parse_commit_or_die(commit
);
171 if ((depth
!= INFINITE_DEPTH
&& cur_depth
>= depth
) ||
172 (is_repository_shallow(the_repository
) && !commit
->parents
&&
173 (graft
= lookup_commit_graft(the_repository
, &commit
->object
.oid
)) != NULL
&&
174 graft
->nr_parent
< 0)) {
175 commit_list_insert(commit
, &result
);
176 commit
->object
.flags
|= shallow_flag
;
180 commit
->object
.flags
|= not_shallow_flag
;
181 for (p
= commit
->parents
, commit
= NULL
; p
; p
= p
->next
) {
182 int **depth_slot
= commit_depth_at(&depths
, p
->item
);
184 *depth_slot
= xmalloc(sizeof(int));
185 **depth_slot
= cur_depth
;
187 if (cur_depth
>= **depth_slot
)
189 **depth_slot
= cur_depth
;
192 add_object_array(&p
->item
->object
,
196 cur_depth
= **commit_depth_at(&depths
, commit
);
200 deep_clear_commit_depth(&depths
, free_depth_in_slab
);
205 static void show_commit(struct commit
*commit
, void *data
)
207 commit_list_insert(commit
, data
);
211 * Given rev-list arguments, run rev-list. All reachable commits
212 * except border ones are marked with not_shallow_flag. Border commits
213 * are marked with shallow_flag. The list of border/shallow commits
216 struct commit_list
*get_shallow_commits_by_rev_list(int ac
, const char **av
,
218 int not_shallow_flag
)
220 struct commit_list
*result
= NULL
, *p
;
221 struct commit_list
*not_shallow_list
= NULL
;
222 struct rev_info revs
;
223 int both_flags
= shallow_flag
| not_shallow_flag
;
226 * SHALLOW (excluded) and NOT_SHALLOW (included) should not be
227 * set at this point. But better be safe than sorry.
229 clear_object_flags(both_flags
);
231 is_repository_shallow(the_repository
); /* make sure shallows are read */
233 repo_init_revisions(the_repository
, &revs
, NULL
);
234 save_commit_buffer
= 0;
235 setup_revisions(ac
, av
, &revs
, NULL
);
237 if (prepare_revision_walk(&revs
))
238 die("revision walk setup failed");
239 traverse_commit_list(&revs
, show_commit
, NULL
, ¬_shallow_list
);
241 if (!not_shallow_list
)
242 die("no commits selected for shallow requests");
244 /* Mark all reachable commits as NOT_SHALLOW */
245 for (p
= not_shallow_list
; p
; p
= p
->next
)
246 p
->item
->object
.flags
|= not_shallow_flag
;
249 * mark border commits SHALLOW + NOT_SHALLOW.
250 * We cannot clear NOT_SHALLOW right now. Imagine border
251 * commit A is processed first, then commit B, whose parent is
252 * A, later. If NOT_SHALLOW on A is cleared at step 1, B
253 * itself is considered border at step 2, which is incorrect.
255 for (p
= not_shallow_list
; p
; p
= p
->next
) {
256 struct commit
*c
= p
->item
;
257 struct commit_list
*parent
;
259 if (repo_parse_commit(the_repository
, c
))
260 die("unable to parse commit %s",
261 oid_to_hex(&c
->object
.oid
));
263 for (parent
= c
->parents
; parent
; parent
= parent
->next
)
264 if (!(parent
->item
->object
.flags
& not_shallow_flag
)) {
265 c
->object
.flags
|= shallow_flag
;
266 commit_list_insert(c
, &result
);
270 free_commit_list(not_shallow_list
);
273 * Now we can clean up NOT_SHALLOW on border commits. Having
274 * both flags set can confuse the caller.
276 for (p
= result
; p
; p
= p
->next
) {
277 struct object
*o
= &p
->item
->object
;
278 if ((o
->flags
& both_flags
) == both_flags
)
279 o
->flags
&= ~not_shallow_flag
;
281 release_revisions(&revs
);
285 static void check_shallow_file_for_update(struct repository
*r
)
287 if (r
->parsed_objects
->is_shallow
== -1)
288 BUG("shallow must be initialized by now");
290 if (!stat_validity_check(r
->parsed_objects
->shallow_stat
,
291 git_path_shallow(r
)))
292 die("shallow file has changed since we read it");
299 struct write_shallow_data
{
301 int use_pack_protocol
;
306 static int write_one_shallow(const struct commit_graft
*graft
, void *cb_data
)
308 struct write_shallow_data
*data
= cb_data
;
309 const char *hex
= oid_to_hex(&graft
->oid
);
310 if (graft
->nr_parent
!= -1)
312 if (data
->flags
& QUICK
) {
313 if (!repo_has_object_file(the_repository
, &graft
->oid
))
315 } else if (data
->flags
& SEEN_ONLY
) {
316 struct commit
*c
= lookup_commit(the_repository
, &graft
->oid
);
317 if (!c
|| !(c
->object
.flags
& SEEN
)) {
318 if (data
->flags
& VERBOSE
)
319 printf("Removing %s from .git/shallow\n",
320 oid_to_hex(&c
->object
.oid
));
325 if (data
->use_pack_protocol
)
326 packet_buf_write(data
->out
, "shallow %s", hex
);
328 strbuf_addstr(data
->out
, hex
);
329 strbuf_addch(data
->out
, '\n');
334 static int write_shallow_commits_1(struct strbuf
*out
, int use_pack_protocol
,
335 const struct oid_array
*extra
,
338 struct write_shallow_data data
;
341 data
.use_pack_protocol
= use_pack_protocol
;
344 for_each_commit_graft(write_one_shallow
, &data
);
347 for (i
= 0; i
< extra
->nr
; i
++) {
348 strbuf_addstr(out
, oid_to_hex(extra
->oid
+ i
));
349 strbuf_addch(out
, '\n');
355 int write_shallow_commits(struct strbuf
*out
, int use_pack_protocol
,
356 const struct oid_array
*extra
)
358 return write_shallow_commits_1(out
, use_pack_protocol
, extra
, 0);
361 const char *setup_temporary_shallow(const struct oid_array
*extra
)
363 struct tempfile
*temp
;
364 struct strbuf sb
= STRBUF_INIT
;
366 if (write_shallow_commits(&sb
, 0, extra
)) {
367 temp
= xmks_tempfile(git_path("shallow_XXXXXX"));
369 if (write_in_full(temp
->fd
, sb
.buf
, sb
.len
) < 0 ||
370 close_tempfile_gently(temp
) < 0)
371 die_errno("failed to write to %s",
372 get_tempfile_path(temp
));
374 return get_tempfile_path(temp
);
377 * is_repository_shallow() sees empty string as "no shallow
383 void setup_alternate_shallow(struct shallow_lock
*shallow_lock
,
384 const char **alternate_shallow_file
,
385 const struct oid_array
*extra
)
387 struct strbuf sb
= STRBUF_INIT
;
390 fd
= hold_lock_file_for_update(&shallow_lock
->lock
,
391 git_path_shallow(the_repository
),
393 check_shallow_file_for_update(the_repository
);
394 if (write_shallow_commits(&sb
, 0, extra
)) {
395 if (write_in_full(fd
, sb
.buf
, sb
.len
) < 0)
396 die_errno("failed to write to %s",
397 get_lock_file_path(&shallow_lock
->lock
));
398 *alternate_shallow_file
= get_lock_file_path(&shallow_lock
->lock
);
401 * is_repository_shallow() sees empty string as "no
404 *alternate_shallow_file
= "";
408 static int advertise_shallow_grafts_cb(const struct commit_graft
*graft
, void *cb
)
411 if (graft
->nr_parent
== -1)
412 packet_write_fmt(fd
, "shallow %s\n", oid_to_hex(&graft
->oid
));
416 void advertise_shallow_grafts(int fd
)
418 if (!is_repository_shallow(the_repository
))
420 for_each_commit_graft(advertise_shallow_grafts_cb
, &fd
);
424 * mark_reachable_objects() should have been run prior to this and all
425 * reachable commits marked as "SEEN", except when quick_prune is non-zero,
426 * in which case lines are excised from the shallow file if they refer to
427 * commits that do not exist (any longer).
429 void prune_shallow(unsigned options
)
431 struct shallow_lock shallow_lock
= SHALLOW_LOCK_INIT
;
432 struct strbuf sb
= STRBUF_INIT
;
433 unsigned flags
= SEEN_ONLY
;
436 if (options
& PRUNE_QUICK
)
439 if (options
& PRUNE_SHOW_ONLY
) {
441 write_shallow_commits_1(&sb
, 0, NULL
, flags
);
445 fd
= hold_lock_file_for_update(&shallow_lock
.lock
,
446 git_path_shallow(the_repository
),
448 check_shallow_file_for_update(the_repository
);
449 if (write_shallow_commits_1(&sb
, 0, NULL
, flags
)) {
450 if (write_in_full(fd
, sb
.buf
, sb
.len
) < 0)
451 die_errno("failed to write to %s",
452 get_lock_file_path(&shallow_lock
.lock
));
453 commit_shallow_file(the_repository
, &shallow_lock
);
455 unlink(git_path_shallow(the_repository
));
456 rollback_shallow_file(the_repository
, &shallow_lock
);
461 struct trace_key trace_shallow
= TRACE_KEY_INIT(SHALLOW
);
464 * Step 1, split sender shallow commits into "ours" and "theirs"
465 * Step 2, clean "ours" based on .git/shallow
467 void prepare_shallow_info(struct shallow_info
*info
, struct oid_array
*sa
)
470 trace_printf_key(&trace_shallow
, "shallow: prepare_shallow_info\n");
471 memset(info
, 0, sizeof(*info
));
475 ALLOC_ARRAY(info
->ours
, sa
->nr
);
476 ALLOC_ARRAY(info
->theirs
, sa
->nr
);
477 for (i
= 0; i
< sa
->nr
; i
++) {
478 if (repo_has_object_file(the_repository
, sa
->oid
+ i
)) {
479 struct commit_graft
*graft
;
480 graft
= lookup_commit_graft(the_repository
,
482 if (graft
&& graft
->nr_parent
< 0)
484 info
->ours
[info
->nr_ours
++] = i
;
486 info
->theirs
[info
->nr_theirs
++] = i
;
490 void clear_shallow_info(struct shallow_info
*info
)
492 if (info
->used_shallow
) {
493 for (size_t i
= 0; i
< info
->shallow
->nr
; i
++)
494 free(info
->used_shallow
[i
]);
495 free(info
->used_shallow
);
498 free(info
->need_reachability_test
);
499 free(info
->reachable
);
500 free(info
->shallow_ref
);
505 /* Step 4, remove non-existent ones in "theirs" after getting the pack */
507 void remove_nonexistent_theirs_shallow(struct shallow_info
*info
)
509 struct object_id
*oid
= info
->shallow
->oid
;
511 trace_printf_key(&trace_shallow
, "shallow: remove_nonexistent_theirs_shallow\n");
512 for (i
= dst
= 0; i
< info
->nr_theirs
; i
++) {
514 info
->theirs
[dst
] = info
->theirs
[i
];
515 if (repo_has_object_file(the_repository
, oid
+ info
->theirs
[i
]))
518 info
->nr_theirs
= dst
;
521 define_commit_slab(ref_bitmap
, uint32_t *);
523 #define POOL_SIZE (512 * 1024)
526 struct ref_bitmap ref_bitmap
;
533 static uint32_t *paint_alloc(struct paint_info
*info
)
535 unsigned nr
= DIV_ROUND_UP(info
->nr_bits
, 32);
536 unsigned size
= nr
* sizeof(uint32_t);
538 if (!info
->pool_count
|| size
> info
->end
- info
->free
) {
539 if (size
> POOL_SIZE
)
540 BUG("pool size too small for %d in paint_alloc()",
543 REALLOC_ARRAY(info
->pools
, info
->pool_count
);
544 info
->free
= xmalloc(POOL_SIZE
);
545 info
->pools
[info
->pool_count
- 1] = info
->free
;
546 info
->end
= info
->free
+ POOL_SIZE
;
554 * Given a commit SHA-1, walk down to parents until either SEEN,
555 * UNINTERESTING or BOTTOM is hit. Set the id-th bit in ref_bitmap for
556 * all walked commits.
558 static void paint_down(struct paint_info
*info
, const struct object_id
*oid
,
562 struct commit_list
*head
= NULL
;
563 int bitmap_nr
= DIV_ROUND_UP(info
->nr_bits
, 32);
564 size_t bitmap_size
= st_mult(sizeof(uint32_t), bitmap_nr
);
565 struct commit
*c
= lookup_commit_reference_gently(the_repository
, oid
,
567 uint32_t *tmp
; /* to be freed before return */
573 tmp
= xmalloc(bitmap_size
);
574 bitmap
= paint_alloc(info
);
575 memset(bitmap
, 0, bitmap_size
);
576 bitmap
[id
/ 32] |= (1U << (id
% 32));
577 commit_list_insert(c
, &head
);
579 struct commit_list
*p
;
580 struct commit
*c
= pop_commit(&head
);
581 uint32_t **refs
= ref_bitmap_at(&info
->ref_bitmap
, c
);
583 /* XXX check "UNINTERESTING" from pack bitmaps if available */
584 if (c
->object
.flags
& (SEEN
| UNINTERESTING
))
587 c
->object
.flags
|= SEEN
;
592 memcpy(tmp
, *refs
, bitmap_size
);
593 for (i
= 0; i
< bitmap_nr
; i
++)
595 if (memcmp(tmp
, *refs
, bitmap_size
)) {
596 *refs
= paint_alloc(info
);
597 memcpy(*refs
, tmp
, bitmap_size
);
601 if (c
->object
.flags
& BOTTOM
)
604 if (repo_parse_commit(the_repository
, c
))
605 die("unable to parse commit %s",
606 oid_to_hex(&c
->object
.oid
));
608 for (p
= c
->parents
; p
; p
= p
->next
) {
609 if (p
->item
->object
.flags
& SEEN
)
611 commit_list_insert(p
->item
, &head
);
615 nr
= get_max_object_index();
616 for (i
= 0; i
< nr
; i
++) {
617 struct object
*o
= get_indexed_object(i
);
618 if (o
&& o
->type
== OBJ_COMMIT
)
625 static int mark_uninteresting(const char *refname UNUSED
,
626 const char *referent UNUSED
,
627 const struct object_id
*oid
,
629 void *cb_data UNUSED
)
631 struct commit
*commit
= lookup_commit_reference_gently(the_repository
,
635 commit
->object
.flags
|= UNINTERESTING
;
636 mark_parents_uninteresting(NULL
, commit
);
640 static void post_assign_shallow(struct shallow_info
*info
,
641 struct ref_bitmap
*ref_bitmap
,
644 * Step 6(+7), associate shallow commits with new refs
646 * info->ref must be initialized before calling this function.
648 * If used is not NULL, it's an array of info->shallow->nr
649 * bitmaps. The n-th bit set in the m-th bitmap if ref[n] needs the
650 * m-th shallow commit from info->shallow.
652 * If used is NULL, "ours" and "theirs" are updated. And if ref_status
653 * is not NULL it's an array of ref->nr ints. ref_status[i] is true if
654 * the ref needs some shallow commits from either info->ours or
657 void assign_shallow_commits_to_refs(struct shallow_info
*info
,
658 uint32_t **used
, int *ref_status
)
660 struct object_id
*oid
= info
->shallow
->oid
;
661 struct oid_array
*ref
= info
->ref
;
663 int *shallow
, nr_shallow
= 0;
664 struct paint_info pi
;
666 trace_printf_key(&trace_shallow
, "shallow: assign_shallow_commits_to_refs\n");
667 ALLOC_ARRAY(shallow
, info
->nr_ours
+ info
->nr_theirs
);
668 for (i
= 0; i
< info
->nr_ours
; i
++)
669 shallow
[nr_shallow
++] = info
->ours
[i
];
670 for (i
= 0; i
< info
->nr_theirs
; i
++)
671 shallow
[nr_shallow
++] = info
->theirs
[i
];
674 * Prepare the commit graph to track what refs can reach what
675 * (new) shallow commits.
677 nr
= get_max_object_index();
678 for (i
= 0; i
< nr
; i
++) {
679 struct object
*o
= get_indexed_object(i
);
680 if (!o
|| o
->type
!= OBJ_COMMIT
)
683 o
->flags
&= ~(UNINTERESTING
| BOTTOM
| SEEN
);
686 memset(&pi
, 0, sizeof(pi
));
687 init_ref_bitmap(&pi
.ref_bitmap
);
688 pi
.nr_bits
= ref
->nr
;
691 * "--not --all" to cut short the traversal if new refs
692 * connect to old refs. If not (e.g. force ref updates) it'll
693 * have to go down to the current shallow commits.
695 refs_head_ref(get_main_ref_store(the_repository
), mark_uninteresting
,
697 refs_for_each_ref(get_main_ref_store(the_repository
),
698 mark_uninteresting
, NULL
);
700 /* Mark potential bottoms so we won't go out of bound */
701 for (i
= 0; i
< nr_shallow
; i
++) {
702 struct commit
*c
= lookup_commit(the_repository
,
704 c
->object
.flags
|= BOTTOM
;
707 for (i
= 0; i
< ref
->nr
; i
++)
708 paint_down(&pi
, ref
->oid
+ i
, i
);
711 int bitmap_size
= DIV_ROUND_UP(pi
.nr_bits
, 32) * sizeof(uint32_t);
712 memset(used
, 0, sizeof(*used
) * info
->shallow
->nr
);
713 for (i
= 0; i
< nr_shallow
; i
++) {
714 const struct commit
*c
= lookup_commit(the_repository
,
716 uint32_t **map
= ref_bitmap_at(&pi
.ref_bitmap
, c
);
718 used
[shallow
[i
]] = xmemdupz(*map
, bitmap_size
);
721 * unreachable shallow commits are not removed from
722 * "ours" and "theirs". The user is supposed to run
723 * step 7 on every ref separately and not trust "ours"
724 * and "theirs" any more.
727 post_assign_shallow(info
, &pi
.ref_bitmap
, ref_status
);
729 clear_ref_bitmap(&pi
.ref_bitmap
);
730 for (i
= 0; i
< pi
.pool_count
; i
++)
736 struct commit_array
{
737 struct commit
**commits
;
741 static int add_ref(const char *refname UNUSED
,
742 const char *referent UNUSED
,
743 const struct object_id
*oid
,
747 struct commit_array
*ca
= cb_data
;
748 ALLOC_GROW(ca
->commits
, ca
->nr
+ 1, ca
->alloc
);
749 ca
->commits
[ca
->nr
] = lookup_commit_reference_gently(the_repository
,
751 if (ca
->commits
[ca
->nr
])
756 static void update_refstatus(int *ref_status
, int nr
, uint32_t *bitmap
)
761 for (i
= 0; i
< nr
; i
++)
762 if (bitmap
[i
/ 32] & (1U << (i
% 32)))
767 * Step 7, reachability test on "ours" at commit level
769 static void post_assign_shallow(struct shallow_info
*info
,
770 struct ref_bitmap
*ref_bitmap
,
773 struct object_id
*oid
= info
->shallow
->oid
;
777 int bitmap_nr
= DIV_ROUND_UP(info
->ref
->nr
, 32);
778 struct commit_array ca
;
780 trace_printf_key(&trace_shallow
, "shallow: post_assign_shallow\n");
782 memset(ref_status
, 0, sizeof(*ref_status
) * info
->ref
->nr
);
784 /* Remove unreachable shallow commits from "theirs" */
785 for (i
= dst
= 0; i
< info
->nr_theirs
; i
++) {
787 info
->theirs
[dst
] = info
->theirs
[i
];
788 c
= lookup_commit(the_repository
, &oid
[info
->theirs
[i
]]);
789 bitmap
= ref_bitmap_at(ref_bitmap
, c
);
792 for (j
= 0; j
< bitmap_nr
; j
++)
794 update_refstatus(ref_status
, info
->ref
->nr
, *bitmap
);
799 info
->nr_theirs
= dst
;
801 memset(&ca
, 0, sizeof(ca
));
802 refs_head_ref(get_main_ref_store(the_repository
), add_ref
, &ca
);
803 refs_for_each_ref(get_main_ref_store(the_repository
), add_ref
, &ca
);
805 /* Remove unreachable shallow commits from "ours" */
806 for (i
= dst
= 0; i
< info
->nr_ours
; i
++) {
808 info
->ours
[dst
] = info
->ours
[i
];
809 c
= lookup_commit(the_repository
, &oid
[info
->ours
[i
]]);
810 bitmap
= ref_bitmap_at(ref_bitmap
, c
);
813 for (j
= 0; j
< bitmap_nr
; j
++)
815 /* Step 7, reachability test at commit level */
816 int ret
= repo_in_merge_bases_many(the_repository
, c
, ca
.nr
, ca
.commits
, 1);
820 update_refstatus(ref_status
, info
->ref
->nr
, *bitmap
);
831 /* (Delayed) step 7, reachability test at commit level */
832 int delayed_reachability_test(struct shallow_info
*si
, int c
)
834 if (si
->need_reachability_test
[c
]) {
835 struct commit
*commit
= lookup_commit(the_repository
,
836 &si
->shallow
->oid
[c
]);
839 struct commit_array ca
;
841 memset(&ca
, 0, sizeof(ca
));
842 refs_head_ref(get_main_ref_store(the_repository
),
844 refs_for_each_ref(get_main_ref_store(the_repository
),
846 si
->commits
= ca
.commits
;
847 si
->nr_commits
= ca
.nr
;
850 si
->reachable
[c
] = repo_in_merge_bases_many(the_repository
,
855 if (si
->reachable
[c
] < 0)
857 si
->need_reachability_test
[c
] = 0;
859 return si
->reachable
[c
];