ref-filter: add deltabase option
[git.git] / builtin / fsck.c
blob06eb42172099a39e6f181d0dd7eab581595d9756
1 #include "builtin.h"
2 #include "cache.h"
3 #include "repository.h"
4 #include "config.h"
5 #include "commit.h"
6 #include "tree.h"
7 #include "blob.h"
8 #include "tag.h"
9 #include "refs.h"
10 #include "pack.h"
11 #include "cache-tree.h"
12 #include "tree-walk.h"
13 #include "fsck.h"
14 #include "parse-options.h"
15 #include "dir.h"
16 #include "progress.h"
17 #include "streaming.h"
18 #include "decorate.h"
19 #include "packfile.h"
20 #include "object-store.h"
21 #include "run-command.h"
23 #define REACHABLE 0x0001
24 #define SEEN 0x0002
25 #define HAS_OBJ 0x0004
26 /* This flag is set if something points to this object. */
27 #define USED 0x0008
29 static int show_root;
30 static int show_tags;
31 static int show_unreachable;
32 static int include_reflogs = 1;
33 static int check_full = 1;
34 static int connectivity_only;
35 static int check_strict;
36 static int keep_cache_objects;
37 static struct fsck_options fsck_walk_options = FSCK_OPTIONS_DEFAULT;
38 static struct fsck_options fsck_obj_options = FSCK_OPTIONS_DEFAULT;
39 static struct object_id head_oid;
40 static const char *head_points_at;
41 static int errors_found;
42 static int write_lost_and_found;
43 static int verbose;
44 static int show_progress = -1;
45 static int show_dangling = 1;
46 static int name_objects;
47 #define ERROR_OBJECT 01
48 #define ERROR_REACHABLE 02
49 #define ERROR_PACK 04
50 #define ERROR_REFS 010
51 #define ERROR_COMMIT_GRAPH 020
53 static const char *describe_object(struct object *obj)
55 static struct strbuf buf = STRBUF_INIT;
56 char *name = name_objects ?
57 lookup_decoration(fsck_walk_options.object_names, obj) : NULL;
59 strbuf_reset(&buf);
60 strbuf_addstr(&buf, oid_to_hex(&obj->oid));
61 if (name)
62 strbuf_addf(&buf, " (%s)", name);
64 return buf.buf;
67 static const char *printable_type(struct object *obj)
69 const char *ret;
71 if (obj->type == OBJ_NONE) {
72 enum object_type type = oid_object_info(the_repository,
73 &obj->oid, NULL);
74 if (type > 0)
75 object_as_type(the_repository, obj, type, 0);
78 ret = type_name(obj->type);
79 if (!ret)
80 ret = "unknown";
82 return ret;
85 static int fsck_config(const char *var, const char *value, void *cb)
87 if (strcmp(var, "fsck.skiplist") == 0) {
88 const char *path;
89 struct strbuf sb = STRBUF_INIT;
91 if (git_config_pathname(&path, var, value))
92 return 1;
93 strbuf_addf(&sb, "skiplist=%s", path);
94 free((char *)path);
95 fsck_set_msg_types(&fsck_obj_options, sb.buf);
96 strbuf_release(&sb);
97 return 0;
100 if (skip_prefix(var, "fsck.", &var)) {
101 fsck_set_msg_type(&fsck_obj_options, var, value);
102 return 0;
105 return git_default_config(var, value, cb);
108 static void objreport(struct object *obj, const char *msg_type,
109 const char *err)
111 fprintf(stderr, "%s in %s %s: %s\n",
112 msg_type, printable_type(obj), describe_object(obj), err);
115 static int objerror(struct object *obj, const char *err)
117 errors_found |= ERROR_OBJECT;
118 objreport(obj, "error", err);
119 return -1;
122 static int fsck_error_func(struct fsck_options *o,
123 struct object *obj, int type, const char *message)
125 objreport(obj, (type == FSCK_WARN) ? "warning" : "error", message);
126 return (type == FSCK_WARN) ? 0 : 1;
129 static struct object_array pending;
131 static int mark_object(struct object *obj, int type, void *data, struct fsck_options *options)
133 struct object *parent = data;
136 * The only case data is NULL or type is OBJ_ANY is when
137 * mark_object_reachable() calls us. All the callers of
138 * that function has non-NULL obj hence ...
140 if (!obj) {
141 /* ... these references to parent->fld are safe here */
142 printf("broken link from %7s %s\n",
143 printable_type(parent), describe_object(parent));
144 printf("broken link from %7s %s\n",
145 (type == OBJ_ANY ? "unknown" : type_name(type)), "unknown");
146 errors_found |= ERROR_REACHABLE;
147 return 1;
150 if (type != OBJ_ANY && obj->type != type)
151 /* ... and the reference to parent is safe here */
152 objerror(parent, "wrong object type in link");
154 if (obj->flags & REACHABLE)
155 return 0;
156 obj->flags |= REACHABLE;
158 if (is_promisor_object(&obj->oid))
160 * Further recursion does not need to be performed on this
161 * object since it is a promisor object (so it does not need to
162 * be added to "pending").
164 return 0;
166 if (!(obj->flags & HAS_OBJ)) {
167 if (parent && !has_object_file(&obj->oid)) {
168 printf("broken link from %7s %s\n",
169 printable_type(parent), describe_object(parent));
170 printf(" to %7s %s\n",
171 printable_type(obj), describe_object(obj));
172 errors_found |= ERROR_REACHABLE;
174 return 1;
177 add_object_array(obj, NULL, &pending);
178 return 0;
181 static void mark_object_reachable(struct object *obj)
183 mark_object(obj, OBJ_ANY, NULL, NULL);
186 static int traverse_one_object(struct object *obj)
188 int result = fsck_walk(obj, obj, &fsck_walk_options);
190 if (obj->type == OBJ_TREE) {
191 struct tree *tree = (struct tree *)obj;
192 free_tree_buffer(tree);
194 return result;
197 static int traverse_reachable(void)
199 struct progress *progress = NULL;
200 unsigned int nr = 0;
201 int result = 0;
202 if (show_progress)
203 progress = start_delayed_progress(_("Checking connectivity"), 0);
204 while (pending.nr) {
205 result |= traverse_one_object(object_array_pop(&pending));
206 display_progress(progress, ++nr);
208 stop_progress(&progress);
209 return !!result;
212 static int mark_used(struct object *obj, int type, void *data, struct fsck_options *options)
214 if (!obj)
215 return 1;
216 obj->flags |= USED;
217 return 0;
221 * Check a single reachable object
223 static void check_reachable_object(struct object *obj)
226 * We obviously want the object to be parsed,
227 * except if it was in a pack-file and we didn't
228 * do a full fsck
230 if (!(obj->flags & HAS_OBJ)) {
231 if (is_promisor_object(&obj->oid))
232 return;
233 if (has_object_pack(&obj->oid))
234 return; /* it is in pack - forget about it */
235 printf("missing %s %s\n", printable_type(obj),
236 describe_object(obj));
237 errors_found |= ERROR_REACHABLE;
238 return;
243 * Check a single unreachable object
245 static void check_unreachable_object(struct object *obj)
248 * Missing unreachable object? Ignore it. It's not like
249 * we miss it (since it can't be reached), nor do we want
250 * to complain about it being unreachable (since it does
251 * not exist).
253 if (!(obj->flags & HAS_OBJ))
254 return;
257 * Unreachable object that exists? Show it if asked to,
258 * since this is something that is prunable.
260 if (show_unreachable) {
261 printf("unreachable %s %s\n", printable_type(obj),
262 describe_object(obj));
263 return;
267 * "!USED" means that nothing at all points to it, including
268 * other unreachable objects. In other words, it's the "tip"
269 * of some set of unreachable objects, usually a commit that
270 * got dropped.
272 * Such starting points are more interesting than some random
273 * set of unreachable objects, so we show them even if the user
274 * hasn't asked for _all_ unreachable objects. If you have
275 * deleted a branch by mistake, this is a prime candidate to
276 * start looking at, for example.
278 if (!(obj->flags & USED)) {
279 if (show_dangling)
280 printf("dangling %s %s\n", printable_type(obj),
281 describe_object(obj));
282 if (write_lost_and_found) {
283 char *filename = git_pathdup("lost-found/%s/%s",
284 obj->type == OBJ_COMMIT ? "commit" : "other",
285 describe_object(obj));
286 FILE *f;
288 if (safe_create_leading_directories_const(filename)) {
289 error("Could not create lost-found");
290 free(filename);
291 return;
293 f = xfopen(filename, "w");
294 if (obj->type == OBJ_BLOB) {
295 if (stream_blob_to_fd(fileno(f), &obj->oid, NULL, 1))
296 die_errno("Could not write '%s'", filename);
297 } else
298 fprintf(f, "%s\n", describe_object(obj));
299 if (fclose(f))
300 die_errno("Could not finish '%s'",
301 filename);
302 free(filename);
304 return;
308 * Otherwise? It's there, it's unreachable, and some other unreachable
309 * object points to it. Ignore it - it's not interesting, and we showed
310 * all the interesting cases above.
314 static void check_object(struct object *obj)
316 if (verbose)
317 fprintf(stderr, "Checking %s\n", describe_object(obj));
319 if (obj->flags & REACHABLE)
320 check_reachable_object(obj);
321 else
322 check_unreachable_object(obj);
325 static void check_connectivity(void)
327 int i, max;
329 /* Traverse the pending reachable objects */
330 traverse_reachable();
332 /* Look up all the requirements, warn about missing objects.. */
333 max = get_max_object_index();
334 if (verbose)
335 fprintf(stderr, "Checking connectivity (%d objects)\n", max);
337 for (i = 0; i < max; i++) {
338 struct object *obj = get_indexed_object(i);
340 if (obj)
341 check_object(obj);
345 static int fsck_obj(struct object *obj, void *buffer, unsigned long size)
347 int err;
349 if (obj->flags & SEEN)
350 return 0;
351 obj->flags |= SEEN;
353 if (verbose)
354 fprintf(stderr, "Checking %s %s\n",
355 printable_type(obj), describe_object(obj));
357 if (fsck_walk(obj, NULL, &fsck_obj_options))
358 objerror(obj, "broken links");
359 err = fsck_object(obj, buffer, size, &fsck_obj_options);
360 if (err)
361 goto out;
363 if (obj->type == OBJ_COMMIT) {
364 struct commit *commit = (struct commit *) obj;
366 if (!commit->parents && show_root)
367 printf("root %s\n", describe_object(&commit->object));
370 if (obj->type == OBJ_TAG) {
371 struct tag *tag = (struct tag *) obj;
373 if (show_tags && tag->tagged) {
374 printf("tagged %s %s", printable_type(tag->tagged),
375 describe_object(tag->tagged));
376 printf(" (%s) in %s\n", tag->tag,
377 describe_object(&tag->object));
381 out:
382 if (obj->type == OBJ_TREE)
383 free_tree_buffer((struct tree *)obj);
384 if (obj->type == OBJ_COMMIT)
385 free_commit_buffer((struct commit *)obj);
386 return err;
389 static int fsck_obj_buffer(const struct object_id *oid, enum object_type type,
390 unsigned long size, void *buffer, int *eaten)
393 * Note, buffer may be NULL if type is OBJ_BLOB. See
394 * verify_packfile(), data_valid variable for details.
396 struct object *obj;
397 obj = parse_object_buffer(the_repository, oid, type, size, buffer,
398 eaten);
399 if (!obj) {
400 errors_found |= ERROR_OBJECT;
401 return error("%s: object corrupt or missing", oid_to_hex(oid));
403 obj->flags &= ~(REACHABLE | SEEN);
404 obj->flags |= HAS_OBJ;
405 return fsck_obj(obj, buffer, size);
408 static int default_refs;
410 static void fsck_handle_reflog_oid(const char *refname, struct object_id *oid,
411 timestamp_t timestamp)
413 struct object *obj;
415 if (!is_null_oid(oid)) {
416 obj = lookup_object(the_repository, oid->hash);
417 if (obj && (obj->flags & HAS_OBJ)) {
418 if (timestamp && name_objects)
419 add_decoration(fsck_walk_options.object_names,
420 obj,
421 xstrfmt("%s@{%"PRItime"}", refname, timestamp));
422 obj->flags |= USED;
423 mark_object_reachable(obj);
424 } else if (!is_promisor_object(oid)) {
425 error("%s: invalid reflog entry %s", refname, oid_to_hex(oid));
426 errors_found |= ERROR_REACHABLE;
431 static int fsck_handle_reflog_ent(struct object_id *ooid, struct object_id *noid,
432 const char *email, timestamp_t timestamp, int tz,
433 const char *message, void *cb_data)
435 const char *refname = cb_data;
437 if (verbose)
438 fprintf(stderr, "Checking reflog %s->%s\n",
439 oid_to_hex(ooid), oid_to_hex(noid));
441 fsck_handle_reflog_oid(refname, ooid, 0);
442 fsck_handle_reflog_oid(refname, noid, timestamp);
443 return 0;
446 static int fsck_handle_reflog(const char *logname, const struct object_id *oid,
447 int flag, void *cb_data)
449 for_each_reflog_ent(logname, fsck_handle_reflog_ent, (void *)logname);
450 return 0;
453 static int fsck_handle_ref(const char *refname, const struct object_id *oid,
454 int flag, void *cb_data)
456 struct object *obj;
458 obj = parse_object(the_repository, oid);
459 if (!obj) {
460 if (is_promisor_object(oid)) {
462 * Increment default_refs anyway, because this is a
463 * valid ref.
465 default_refs++;
466 return 0;
468 error("%s: invalid sha1 pointer %s", refname, oid_to_hex(oid));
469 errors_found |= ERROR_REACHABLE;
470 /* We'll continue with the rest despite the error.. */
471 return 0;
473 if (obj->type != OBJ_COMMIT && is_branch(refname)) {
474 error("%s: not a commit", refname);
475 errors_found |= ERROR_REFS;
477 default_refs++;
478 obj->flags |= USED;
479 if (name_objects)
480 add_decoration(fsck_walk_options.object_names,
481 obj, xstrdup(refname));
482 mark_object_reachable(obj);
484 return 0;
487 static void get_default_heads(void)
489 if (head_points_at && !is_null_oid(&head_oid))
490 fsck_handle_ref("HEAD", &head_oid, 0, NULL);
491 for_each_rawref(fsck_handle_ref, NULL);
492 if (include_reflogs)
493 for_each_reflog(fsck_handle_reflog, NULL);
496 * Not having any default heads isn't really fatal, but
497 * it does mean that "--unreachable" no longer makes any
498 * sense (since in this case everything will obviously
499 * be unreachable by definition.
501 * Showing dangling objects is valid, though (as those
502 * dangling objects are likely lost heads).
504 * So we just print a warning about it, and clear the
505 * "show_unreachable" flag.
507 if (!default_refs) {
508 fprintf(stderr, "notice: No default references\n");
509 show_unreachable = 0;
513 static int fsck_loose(const struct object_id *oid, const char *path, void *data)
515 struct object *obj;
516 enum object_type type;
517 unsigned long size;
518 void *contents;
519 int eaten;
521 if (read_loose_object(path, oid, &type, &size, &contents) < 0) {
522 errors_found |= ERROR_OBJECT;
523 error("%s: object corrupt or missing: %s",
524 oid_to_hex(oid), path);
525 return 0; /* keep checking other objects */
528 if (!contents && type != OBJ_BLOB)
529 BUG("read_loose_object streamed a non-blob");
531 obj = parse_object_buffer(the_repository, oid, type, size,
532 contents, &eaten);
534 if (!obj) {
535 errors_found |= ERROR_OBJECT;
536 error("%s: object could not be parsed: %s",
537 oid_to_hex(oid), path);
538 if (!eaten)
539 free(contents);
540 return 0; /* keep checking other objects */
543 obj->flags &= ~(REACHABLE | SEEN);
544 obj->flags |= HAS_OBJ;
545 if (fsck_obj(obj, contents, size))
546 errors_found |= ERROR_OBJECT;
548 if (!eaten)
549 free(contents);
550 return 0; /* keep checking other objects, even if we saw an error */
553 static int fsck_cruft(const char *basename, const char *path, void *data)
555 if (!starts_with(basename, "tmp_obj_"))
556 fprintf(stderr, "bad sha1 file: %s\n", path);
557 return 0;
560 static int fsck_subdir(unsigned int nr, const char *path, void *progress)
562 display_progress(progress, nr + 1);
563 return 0;
566 static void fsck_object_dir(const char *path)
568 struct progress *progress = NULL;
570 if (verbose)
571 fprintf(stderr, "Checking object directory\n");
573 if (show_progress)
574 progress = start_progress(_("Checking object directories"), 256);
576 for_each_loose_file_in_objdir(path, fsck_loose, fsck_cruft, fsck_subdir,
577 progress);
578 display_progress(progress, 256);
579 stop_progress(&progress);
582 static int fsck_head_link(void)
584 int null_is_error = 0;
586 if (verbose)
587 fprintf(stderr, "Checking HEAD link\n");
589 head_points_at = resolve_ref_unsafe("HEAD", 0, &head_oid, NULL);
590 if (!head_points_at) {
591 errors_found |= ERROR_REFS;
592 return error("Invalid HEAD");
594 if (!strcmp(head_points_at, "HEAD"))
595 /* detached HEAD */
596 null_is_error = 1;
597 else if (!starts_with(head_points_at, "refs/heads/")) {
598 errors_found |= ERROR_REFS;
599 return error("HEAD points to something strange (%s)",
600 head_points_at);
602 if (is_null_oid(&head_oid)) {
603 if (null_is_error) {
604 errors_found |= ERROR_REFS;
605 return error("HEAD: detached HEAD points at nothing");
607 fprintf(stderr, "notice: HEAD points to an unborn branch (%s)\n",
608 head_points_at + 11);
610 return 0;
613 static int fsck_cache_tree(struct cache_tree *it)
615 int i;
616 int err = 0;
618 if (verbose)
619 fprintf(stderr, "Checking cache tree\n");
621 if (0 <= it->entry_count) {
622 struct object *obj = parse_object(the_repository, &it->oid);
623 if (!obj) {
624 error("%s: invalid sha1 pointer in cache-tree",
625 oid_to_hex(&it->oid));
626 errors_found |= ERROR_REFS;
627 return 1;
629 obj->flags |= USED;
630 if (name_objects)
631 add_decoration(fsck_walk_options.object_names,
632 obj, xstrdup(":"));
633 mark_object_reachable(obj);
634 if (obj->type != OBJ_TREE)
635 err |= objerror(obj, "non-tree in cache-tree");
637 for (i = 0; i < it->subtree_nr; i++)
638 err |= fsck_cache_tree(it->down[i]->cache_tree);
639 return err;
642 static void mark_object_for_connectivity(const struct object_id *oid)
644 struct object *obj = lookup_unknown_object(oid->hash);
645 obj->flags |= HAS_OBJ;
648 static int mark_loose_for_connectivity(const struct object_id *oid,
649 const char *path,
650 void *data)
652 mark_object_for_connectivity(oid);
653 return 0;
656 static int mark_packed_for_connectivity(const struct object_id *oid,
657 struct packed_git *pack,
658 uint32_t pos,
659 void *data)
661 mark_object_for_connectivity(oid);
662 return 0;
665 static char const * const fsck_usage[] = {
666 N_("git fsck [<options>] [<object>...]"),
667 NULL
670 static struct option fsck_opts[] = {
671 OPT__VERBOSE(&verbose, N_("be verbose")),
672 OPT_BOOL(0, "unreachable", &show_unreachable, N_("show unreachable objects")),
673 OPT_BOOL(0, "dangling", &show_dangling, N_("show dangling objects")),
674 OPT_BOOL(0, "tags", &show_tags, N_("report tags")),
675 OPT_BOOL(0, "root", &show_root, N_("report root nodes")),
676 OPT_BOOL(0, "cache", &keep_cache_objects, N_("make index objects head nodes")),
677 OPT_BOOL(0, "reflogs", &include_reflogs, N_("make reflogs head nodes (default)")),
678 OPT_BOOL(0, "full", &check_full, N_("also consider packs and alternate objects")),
679 OPT_BOOL(0, "connectivity-only", &connectivity_only, N_("check only connectivity")),
680 OPT_BOOL(0, "strict", &check_strict, N_("enable more strict checking")),
681 OPT_BOOL(0, "lost-found", &write_lost_and_found,
682 N_("write dangling objects in .git/lost-found")),
683 OPT_BOOL(0, "progress", &show_progress, N_("show progress")),
684 OPT_BOOL(0, "name-objects", &name_objects, N_("show verbose names for reachable objects")),
685 OPT_END(),
688 int cmd_fsck(int argc, const char **argv, const char *prefix)
690 int i;
691 struct alternate_object_database *alt;
693 /* fsck knows how to handle missing promisor objects */
694 fetch_if_missing = 0;
696 errors_found = 0;
697 read_replace_refs = 0;
699 argc = parse_options(argc, argv, prefix, fsck_opts, fsck_usage, 0);
701 fsck_walk_options.walk = mark_object;
702 fsck_obj_options.walk = mark_used;
703 fsck_obj_options.error_func = fsck_error_func;
704 if (check_strict)
705 fsck_obj_options.strict = 1;
707 if (show_progress == -1)
708 show_progress = isatty(2);
709 if (verbose)
710 show_progress = 0;
712 if (write_lost_and_found) {
713 check_full = 1;
714 include_reflogs = 0;
717 if (name_objects)
718 fsck_walk_options.object_names =
719 xcalloc(1, sizeof(struct decoration));
721 git_config(fsck_config, NULL);
723 fsck_head_link();
724 if (connectivity_only) {
725 for_each_loose_object(mark_loose_for_connectivity, NULL, 0);
726 for_each_packed_object(mark_packed_for_connectivity, NULL, 0);
727 } else {
728 struct alternate_object_database *alt_odb_list;
730 fsck_object_dir(get_object_directory());
732 prepare_alt_odb(the_repository);
733 alt_odb_list = the_repository->objects->alt_odb_list;
734 for (alt = alt_odb_list; alt; alt = alt->next)
735 fsck_object_dir(alt->path);
737 if (check_full) {
738 struct packed_git *p;
739 uint32_t total = 0, count = 0;
740 struct progress *progress = NULL;
742 if (show_progress) {
743 for (p = get_all_packs(the_repository); p;
744 p = p->next) {
745 if (open_pack_index(p))
746 continue;
747 total += p->num_objects;
750 progress = start_progress(_("Checking objects"), total);
752 for (p = get_all_packs(the_repository); p;
753 p = p->next) {
754 /* verify gives error messages itself */
755 if (verify_pack(p, fsck_obj_buffer,
756 progress, count))
757 errors_found |= ERROR_PACK;
758 count += p->num_objects;
760 stop_progress(&progress);
763 if (fsck_finish(&fsck_obj_options))
764 errors_found |= ERROR_OBJECT;
767 for (i = 0; i < argc; i++) {
768 const char *arg = argv[i];
769 struct object_id oid;
770 if (!get_oid(arg, &oid)) {
771 struct object *obj = lookup_object(the_repository,
772 oid.hash);
774 if (!obj || !(obj->flags & HAS_OBJ)) {
775 if (is_promisor_object(&oid))
776 continue;
777 error("%s: object missing", oid_to_hex(&oid));
778 errors_found |= ERROR_OBJECT;
779 continue;
782 obj->flags |= USED;
783 if (name_objects)
784 add_decoration(fsck_walk_options.object_names,
785 obj, xstrdup(arg));
786 mark_object_reachable(obj);
787 continue;
789 error("invalid parameter: expected sha1, got '%s'", arg);
790 errors_found |= ERROR_OBJECT;
794 * If we've not been given any explicit head information, do the
795 * default ones from .git/refs. We also consider the index file
796 * in this case (ie this implies --cache).
798 if (!argc) {
799 get_default_heads();
800 keep_cache_objects = 1;
803 if (keep_cache_objects) {
804 verify_index_checksum = 1;
805 verify_ce_order = 1;
806 read_cache();
807 for (i = 0; i < active_nr; i++) {
808 unsigned int mode;
809 struct blob *blob;
810 struct object *obj;
812 mode = active_cache[i]->ce_mode;
813 if (S_ISGITLINK(mode))
814 continue;
815 blob = lookup_blob(the_repository,
816 &active_cache[i]->oid);
817 if (!blob)
818 continue;
819 obj = &blob->object;
820 obj->flags |= USED;
821 if (name_objects)
822 add_decoration(fsck_walk_options.object_names,
823 obj,
824 xstrfmt(":%s", active_cache[i]->name));
825 mark_object_reachable(obj);
827 if (active_cache_tree)
828 fsck_cache_tree(active_cache_tree);
831 check_connectivity();
833 if (!git_config_get_bool("core.commitgraph", &i) && i) {
834 struct child_process commit_graph_verify = CHILD_PROCESS_INIT;
835 const char *verify_argv[] = { "commit-graph", "verify", NULL, NULL, NULL };
837 commit_graph_verify.argv = verify_argv;
838 commit_graph_verify.git_cmd = 1;
839 if (run_command(&commit_graph_verify))
840 errors_found |= ERROR_COMMIT_GRAPH;
842 prepare_alt_odb(the_repository);
843 for (alt = the_repository->objects->alt_odb_list; alt; alt = alt->next) {
844 verify_argv[2] = "--object-dir";
845 verify_argv[3] = alt->path;
846 if (run_command(&commit_graph_verify))
847 errors_found |= ERROR_COMMIT_GRAPH;
851 if (!git_config_get_bool("core.multipackindex", &i) && i) {
852 struct child_process midx_verify = CHILD_PROCESS_INIT;
853 const char *midx_argv[] = { "multi-pack-index", "verify", NULL, NULL, NULL };
855 midx_verify.argv = midx_argv;
856 midx_verify.git_cmd = 1;
857 if (run_command(&midx_verify))
858 errors_found |= ERROR_COMMIT_GRAPH;
860 prepare_alt_odb(the_repository);
861 for (alt = the_repository->objects->alt_odb_list; alt; alt = alt->next) {
862 midx_argv[2] = "--object-dir";
863 midx_argv[3] = alt->path;
864 if (run_command(&midx_verify))
865 errors_found |= ERROR_COMMIT_GRAPH;
869 return errors_found;