2 #include "object-store.h"
3 #include "run-command.h"
8 #include "promisor-remote.h"
11 * If we feed all the commits we want to verify to this command
13 * $ git rev-list --objects --stdin --not --all
15 * and if it does not error out, that means everything reachable from
16 * these commits locally exists and is connected to our existing refs.
17 * Note that this does _not_ validate the individual objects.
19 * Returns 0 if everything is connected, non-zero otherwise.
21 int check_connected(oid_iterate_fn fn
, void *cb_data
,
22 struct check_connected_options
*opt
)
24 struct child_process rev_list
= CHILD_PROCESS_INIT
;
25 struct check_connected_options defaults
= CHECK_CONNECTED_INIT
;
26 char commit
[GIT_MAX_HEXSZ
+ 1];
29 struct packed_git
*new_pack
= NULL
;
30 struct transport
*transport
;
32 const unsigned hexsz
= the_hash_algo
->hexsz
;
36 transport
= opt
->transport
;
38 if (fn(cb_data
, &oid
)) {
44 if (transport
&& transport
->smart_options
&&
45 transport
->smart_options
->self_contained_and_connected
&&
46 transport
->pack_lockfile
&&
47 strip_suffix(transport
->pack_lockfile
, ".keep", &base_len
)) {
48 struct strbuf idx_file
= STRBUF_INIT
;
49 strbuf_add(&idx_file
, transport
->pack_lockfile
, base_len
);
50 strbuf_addstr(&idx_file
, ".idx");
51 new_pack
= add_packed_git(idx_file
.buf
, idx_file
.len
, 1);
52 strbuf_release(&idx_file
);
55 if (opt
->check_refs_only
) {
57 * For partial clones, we don't want to have to do a regular
58 * connectivity check because we have to enumerate and exclude
59 * all promisor objects (slow), and then the connectivity check
60 * itself becomes a no-op because in a partial clone every
61 * object is a promisor object. Instead, just make sure we
62 * received the objects pointed to by each wanted ref.
65 if (!repo_has_object_file_with_flags(the_repository
, &oid
,
66 OBJECT_INFO_SKIP_FETCH_OBJECT
))
68 } while (!fn(cb_data
, &oid
));
72 if (opt
->shallow_file
) {
73 argv_array_push(&rev_list
.args
, "--shallow-file");
74 argv_array_push(&rev_list
.args
, opt
->shallow_file
);
76 argv_array_push(&rev_list
.args
,"rev-list");
77 argv_array_push(&rev_list
.args
, "--objects");
78 argv_array_push(&rev_list
.args
, "--stdin");
79 if (has_promisor_remote())
80 argv_array_push(&rev_list
.args
, "--exclude-promisor-objects");
81 if (!opt
->is_deepening_fetch
) {
82 argv_array_push(&rev_list
.args
, "--not");
83 argv_array_push(&rev_list
.args
, "--all");
85 argv_array_push(&rev_list
.args
, "--quiet");
86 argv_array_push(&rev_list
.args
, "--alternate-refs");
88 argv_array_pushf(&rev_list
.args
, "--progress=%s",
89 _("Checking connectivity"));
92 rev_list
.env
= opt
->env
;
94 rev_list
.no_stdout
= 1;
96 rev_list
.err
= opt
->err_fd
;
98 rev_list
.no_stderr
= opt
->quiet
;
100 if (start_command(&rev_list
))
101 return error(_("Could not run 'git rev-list'"));
103 sigchain_push(SIGPIPE
, SIG_IGN
);
105 commit
[hexsz
] = '\n';
108 * If index-pack already checked that:
109 * - there are no dangling pointers in the new pack
110 * - the pack is self contained
111 * Then if the updated ref is in the new pack, then we
112 * are sure the ref is good and not sending it to
113 * rev-list for verification.
115 if (new_pack
&& find_pack_entry_one(oid
.hash
, new_pack
))
118 memcpy(commit
, oid_to_hex(&oid
), hexsz
);
119 if (write_in_full(rev_list
.in
, commit
, hexsz
+ 1) < 0) {
120 if (errno
!= EPIPE
&& errno
!= EINVAL
)
121 error_errno(_("failed write to rev-list"));
125 } while (!fn(cb_data
, &oid
));
127 if (close(rev_list
.in
))
128 err
= error_errno(_("failed to close rev-list's stdin"));
130 sigchain_pop(SIGPIPE
);
131 return finish_command(&rev_list
) || err
;