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
;
26 struct check_connected_options defaults
= CHECK_CONNECTED_INIT
;
27 const struct object_id
*oid
;
29 struct packed_git
*new_pack
= NULL
;
30 struct transport
*transport
;
35 transport
= opt
->transport
;
44 if (transport
&& transport
->smart_options
&&
45 transport
->smart_options
->self_contained_and_connected
&&
46 transport
->pack_lockfiles
.nr
== 1 &&
47 strip_suffix(transport
->pack_lockfiles
.items
[0].string
,
48 ".keep", &base_len
)) {
49 struct strbuf idx_file
= STRBUF_INIT
;
50 strbuf_add(&idx_file
, transport
->pack_lockfiles
.items
[0].string
,
52 strbuf_addstr(&idx_file
, ".idx");
53 new_pack
= add_packed_git(idx_file
.buf
, idx_file
.len
, 1);
54 strbuf_release(&idx_file
);
57 if (has_promisor_remote()) {
59 * For partial clones, we don't want to have to do a regular
60 * connectivity check because we have to enumerate and exclude
61 * all promisor objects (slow), and then the connectivity check
62 * itself becomes a no-op because in a partial clone every
63 * object is a promisor object. Instead, just make sure we
64 * received, in a promisor packfile, the objects pointed to by
67 * Before checking for promisor packs, be sure we have the
68 * latest pack-files loaded into memory.
70 reprepare_packed_git(the_repository
);
74 for (p
= get_all_packs(the_repository
); p
; p
= p
->next
) {
75 if (!p
->pack_promisor
)
77 if (find_pack_entry_one(oid
->hash
, p
))
78 goto promisor_pack_found
;
81 * Fallback to rev-list with oid and the rest of the
82 * object IDs provided by fn.
84 goto no_promisor_pack_found
;
87 } while ((oid
= fn(cb_data
)) != NULL
);
92 no_promisor_pack_found
:
93 if (opt
->shallow_file
) {
94 strvec_push(&rev_list
.args
, "--shallow-file");
95 strvec_push(&rev_list
.args
, opt
->shallow_file
);
97 strvec_push(&rev_list
.args
,"rev-list");
98 strvec_push(&rev_list
.args
, "--objects");
99 strvec_push(&rev_list
.args
, "--stdin");
100 if (has_promisor_remote())
101 strvec_push(&rev_list
.args
, "--exclude-promisor-objects");
102 if (!opt
->is_deepening_fetch
) {
103 strvec_push(&rev_list
.args
, "--not");
104 if (opt
->exclude_hidden_refs_section
)
105 strvec_pushf(&rev_list
.args
, "--exclude-hidden=%s",
106 opt
->exclude_hidden_refs_section
);
107 strvec_push(&rev_list
.args
, "--all");
109 strvec_push(&rev_list
.args
, "--quiet");
110 strvec_push(&rev_list
.args
, "--alternate-refs");
112 strvec_pushf(&rev_list
.args
, "--progress=%s",
113 _("Checking connectivity"));
115 rev_list
.git_cmd
= 1;
117 strvec_pushv(&rev_list
.env
, opt
->env
);
119 rev_list
.no_stdout
= 1;
121 rev_list
.err
= opt
->err_fd
;
123 rev_list
.no_stderr
= opt
->quiet
;
125 if (start_command(&rev_list
)) {
127 return error(_("Could not run 'git rev-list'"));
130 sigchain_push(SIGPIPE
, SIG_IGN
);
132 rev_list_in
= xfdopen(rev_list
.in
, "w");
136 * If index-pack already checked that:
137 * - there are no dangling pointers in the new pack
138 * - the pack is self contained
139 * Then if the updated ref is in the new pack, then we
140 * are sure the ref is good and not sending it to
141 * rev-list for verification.
143 if (new_pack
&& find_pack_entry_one(oid
->hash
, new_pack
))
146 if (fprintf(rev_list_in
, "%s\n", oid_to_hex(oid
)) < 0)
148 } while ((oid
= fn(cb_data
)) != NULL
);
150 if (ferror(rev_list_in
) || fflush(rev_list_in
)) {
151 if (errno
!= EPIPE
&& errno
!= EINVAL
)
152 error_errno(_("failed write to rev-list"));
156 if (fclose(rev_list_in
))
157 err
= error_errno(_("failed to close rev-list's stdin"));
159 sigchain_pop(SIGPIPE
);
161 return finish_command(&rev_list
) || err
;