2 #include "run-command.h"
7 int check_everything_connected(sha1_iterate_fn fn
, int quiet
, void *cb_data
)
9 return check_everything_connected_with_transport(fn
, quiet
, cb_data
, NULL
);
12 * If we feed all the commits we want to verify to this command
14 * $ git rev-list --objects --stdin --not --all
16 * and if it does not error out, that means everything reachable from
17 * these commits locally exists and is connected to our existing refs.
18 * Note that this does _not_ validate the individual objects.
20 * Returns 0 if everything is connected, non-zero otherwise.
22 static int check_everything_connected_real(sha1_iterate_fn fn
,
25 struct transport
*transport
,
26 const char *shallow_file
)
28 struct child_process rev_list
;
31 unsigned char sha1
[20];
33 struct packed_git
*new_pack
= NULL
;
35 if (fn(cb_data
, sha1
))
38 if (transport
&& transport
->smart_options
&&
39 transport
->smart_options
->self_contained_and_connected
&&
40 transport
->pack_lockfile
&&
41 ends_with(transport
->pack_lockfile
, ".keep")) {
42 struct strbuf idx_file
= STRBUF_INIT
;
43 strbuf_addstr(&idx_file
, transport
->pack_lockfile
);
44 strbuf_setlen(&idx_file
, idx_file
.len
- 5); /* ".keep" */
45 strbuf_addstr(&idx_file
, ".idx");
46 new_pack
= add_packed_git(idx_file
.buf
, idx_file
.len
, 1);
47 strbuf_release(&idx_file
);
51 argv
[ac
++] = "--shallow-file";
52 argv
[ac
++] = shallow_file
;
54 argv
[ac
++] = "rev-list";
55 argv
[ac
++] = "--objects";
56 argv
[ac
++] = "--stdin";
60 argv
[ac
++] = "--quiet";
63 memset(&rev_list
, 0, sizeof(rev_list
));
67 rev_list
.no_stdout
= 1;
68 rev_list
.no_stderr
= quiet
;
69 if (start_command(&rev_list
))
70 return error(_("Could not run 'git rev-list'"));
72 sigchain_push(SIGPIPE
, SIG_IGN
);
77 * If index-pack already checked that:
78 * - there are no dangling pointers in the new pack
79 * - the pack is self contained
80 * Then if the updated ref is in the new pack, then we
81 * are sure the ref is good and not sending it to
82 * rev-list for verification.
84 if (new_pack
&& find_pack_entry_one(sha1
, new_pack
))
87 memcpy(commit
, sha1_to_hex(sha1
), 40);
88 if (write_in_full(rev_list
.in
, commit
, 41) < 0) {
89 if (errno
!= EPIPE
&& errno
!= EINVAL
)
90 error(_("failed write to rev-list: %s"),
95 } while (!fn(cb_data
, sha1
));
97 if (close(rev_list
.in
)) {
98 error(_("failed to close rev-list's stdin: %s"), strerror(errno
));
102 sigchain_pop(SIGPIPE
);
103 return finish_command(&rev_list
) || err
;
106 int check_everything_connected_with_transport(sha1_iterate_fn fn
,
109 struct transport
*transport
)
111 return check_everything_connected_real(fn
, quiet
, cb_data
,
115 int check_shallow_connected(sha1_iterate_fn fn
, int quiet
, void *cb_data
,
116 const char *shallow_file
)
118 return check_everything_connected_real(fn
, quiet
, cb_data
,