THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

Git Source Code Mirror - This is a publish-only repository and all pull requests are ignored. Please follow Documentation/SubmittingPatches procedure for any of your improvements.
git
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
3.9KB

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