* If we feed all the commits we want to verify to this command * * $ git rev-list --objects --stdin --not --all * * and if it does not error out, that means everything reachable from * these commits locally exists and is connected to our existing refs. * Note that this does _not_ validate the individual objects. * * Returns 0 if everything is connected, non-zero otherwise. */
| 23 | * Returns 0 if everything is connected, non-zero otherwise. |
| 24 | */ |
| 25 | int check_connected(oid_iterate_fn fn, void *cb_data, |
| 26 | struct check_connected_options *opt) |
| 27 | { |
| 28 | struct child_process rev_list = CHILD_PROCESS_INIT; |
| 29 | FILE *rev_list_in; |
| 30 | struct check_connected_options defaults = CHECK_CONNECTED_INIT; |
| 31 | const struct object_id *oid; |
| 32 | int err = 0; |
| 33 | struct packed_git *new_pack = NULL; |
| 34 | struct transport *transport; |
| 35 | size_t base_len; |
| 36 | |
| 37 | if (!opt) |
| 38 | opt = &defaults; |
| 39 | transport = opt->transport; |
| 40 | |
| 41 | oid = fn(cb_data); |
| 42 | if (!oid) { |
| 43 | if (opt->err_fd) |
| 44 | close(opt->err_fd); |
| 45 | return err; |
| 46 | } |
| 47 | |
| 48 | if (repo_has_promisor_remote(the_repository)) { |
| 49 | /* |
| 50 | * For partial clones, we don't want to have to do a regular |
| 51 | * connectivity check because we have to enumerate and exclude |
| 52 | * all promisor objects (slow), and then the connectivity check |
| 53 | * itself becomes a no-op because in a partial clone every |
| 54 | * object is a promisor object. Instead, just make sure we |
| 55 | * received, in a promisor packfile, the objects pointed to by |
| 56 | * each wanted ref. |
| 57 | * |
| 58 | * Before checking for promisor packs, be sure we have the |
| 59 | * latest pack-files loaded into memory. |
| 60 | */ |
| 61 | odb_reprepare(the_repository->objects); |
| 62 | do { |
| 63 | struct packed_git *p; |
| 64 | |
| 65 | repo_for_each_pack(the_repository, p) { |
| 66 | if (!p->pack_promisor) |
| 67 | continue; |
| 68 | if (find_pack_entry_one(oid, p)) |
| 69 | goto promisor_pack_found; |
| 70 | } |
| 71 | /* |
| 72 | * Fallback to rev-list with oid and the rest of the |
| 73 | * object IDs provided by fn. |
| 74 | */ |
| 75 | goto no_promisor_pack_found; |
| 76 | promisor_pack_found: |
| 77 | ; |
| 78 | } while ((oid = fn(cb_data)) != NULL); |
| 79 | if (opt->err_fd) |
| 80 | close(opt->err_fd); |
| 81 | return 0; |
| 82 | } |
no test coverage detected