]>
Commit | Line | Data |
---|---|---|
f8adbec9 | 1 | #define USE_THE_INDEX_COMPATIBILITY_MACROS |
baffc0e7 | 2 | #include "builtin.h" |
4b182421 | 3 | #include "cache.h" |
031dc927 | 4 | #include "repository.h" |
b2141fc1 | 5 | #include "config.h" |
ff5ebe39 DB |
6 | #include "commit.h" |
7 | #include "tree.h" | |
8 | #include "blob.h" | |
c418eda4 | 9 | #include "tag.h" |
944d8589 | 10 | #include "refs.h" |
f9253394 | 11 | #include "pack.h" |
53dc3f3e | 12 | #include "cache-tree.h" |
e9a95bef | 13 | #include "tree-walk.h" |
271b8d25 | 14 | #include "fsck.h" |
5ac0a206 | 15 | #include "parse-options.h" |
8ca12c0d | 16 | #include "dir.h" |
1e49f22f | 17 | #include "progress.h" |
6f7f3beb | 18 | #include "streaming.h" |
90cf590f | 19 | #include "decorate.h" |
0317f455 | 20 | #include "packfile.h" |
0d4a1321 | 21 | #include "object-store.h" |
5a5ea141 | 22 | #include "resolve-undo.h" |
e0fd51e1 | 23 | #include "run-command.h" |
b29759d8 | 24 | #include "worktree.h" |
ff5ebe39 DB |
25 | |
26 | #define REACHABLE 0x0001 | |
2d9c58c6 | 27 | #define SEEN 0x0002 |
6e454b9a | 28 | #define HAS_OBJ 0x0004 |
092c55d0 JT |
29 | /* This flag is set if something points to this object. */ |
30 | #define USED 0x0008 | |
d9839e03 | 31 | |
96f1e58f DR |
32 | static int show_root; |
33 | static int show_tags; | |
34 | static int show_unreachable; | |
566842f6 | 35 | static int include_reflogs = 1; |
f29cd393 | 36 | static int check_full = 1; |
02976bf8 | 37 | static int connectivity_only; |
96f1e58f DR |
38 | static int check_strict; |
39 | static int keep_cache_objects; | |
22410549 JS |
40 | static struct fsck_options fsck_walk_options = FSCK_OPTIONS_DEFAULT; |
41 | static struct fsck_options fsck_obj_options = FSCK_OPTIONS_DEFAULT; | |
e2b4f635 | 42 | static int errors_found; |
68f6c019 | 43 | static int write_lost_and_found; |
20f1eb6b | 44 | static int verbose; |
1e49f22f | 45 | static int show_progress = -1; |
c6a13b2c | 46 | static int show_dangling = 1; |
90cf590f | 47 | static int name_objects; |
e2b4f635 JH |
48 | #define ERROR_OBJECT 01 |
49 | #define ERROR_REACHABLE 02 | |
a3ed7552 | 50 | #define ERROR_PACK 04 |
122f76f5 | 51 | #define ERROR_REFS 010 |
e0fd51e1 | 52 | #define ERROR_COMMIT_GRAPH 020 |
e68a5272 | 53 | #define ERROR_MULTI_PACK_INDEX 040 |
d9839e03 | 54 | |
82ef89b3 | 55 | static const char *describe_object(const struct object_id *oid) |
993a21b0 | 56 | { |
82ef89b3 | 57 | return fsck_describe_object(&fsck_walk_options, oid); |
993a21b0 JS |
58 | } |
59 | ||
82ef89b3 JK |
60 | static const char *printable_type(const struct object_id *oid, |
61 | enum object_type type) | |
97ca7ca8 JK |
62 | { |
63 | const char *ret; | |
64 | ||
82ef89b3 JK |
65 | if (type == OBJ_NONE) |
66 | type = oid_object_info(the_repository, oid, NULL); | |
a2b22854 | 67 | |
82ef89b3 | 68 | ret = type_name(type); |
97ca7ca8 | 69 | if (!ret) |
674ba340 | 70 | ret = _("unknown"); |
97ca7ca8 JK |
71 | |
72 | return ret; | |
73 | } | |
74 | ||
c99ba492 | 75 | static int objerror(struct object *obj, const char *err) |
f1f0d088 | 76 | { |
e2b4f635 | 77 | errors_found |= ERROR_OBJECT; |
674ba340 NTND |
78 | /* TRANSLATORS: e.g. error in tree 01bfda: <more explanation> */ |
79 | fprintf_ln(stderr, _("error in %s %s: %s"), | |
82ef89b3 JK |
80 | printable_type(&obj->oid, obj->type), |
81 | describe_object(&obj->oid), err); | |
f1f0d088 PB |
82 | return -1; |
83 | } | |
84 | ||
1cd772cc | 85 | static int fsck_error_func(struct fsck_options *o, |
5afc4b1d JK |
86 | const struct object_id *oid, |
87 | enum object_type object_type, | |
394d5d31 ÆAB |
88 | enum fsck_msg_type msg_type, |
89 | enum fsck_msg_id msg_id, | |
90 | const char *message) | |
f1f0d088 | 91 | { |
5afc4b1d | 92 | switch (msg_type) { |
bbb15c51 | 93 | case FSCK_WARN: |
674ba340 NTND |
94 | /* TRANSLATORS: e.g. warning in tree 01bfda: <more explanation> */ |
95 | fprintf_ln(stderr, _("warning in %s %s: %s"), | |
5afc4b1d JK |
96 | printable_type(oid, object_type), |
97 | describe_object(oid), message); | |
bbb15c51 NTND |
98 | return 0; |
99 | case FSCK_ERROR: | |
674ba340 NTND |
100 | /* TRANSLATORS: e.g. error in tree 01bfda: <more explanation> */ |
101 | fprintf_ln(stderr, _("error in %s %s: %s"), | |
5afc4b1d JK |
102 | printable_type(oid, object_type), |
103 | describe_object(oid), message); | |
bbb15c51 NTND |
104 | return 1; |
105 | default: | |
5afc4b1d JK |
106 | BUG("%d (FSCK_IGNORE?) should never trigger this callback", |
107 | msg_type); | |
bbb15c51 | 108 | } |
f1f0d088 PB |
109 | } |
110 | ||
04d39759 LT |
111 | static struct object_array pending; |
112 | ||
28abf260 ÆAB |
113 | static int mark_object(struct object *obj, enum object_type type, |
114 | void *data, struct fsck_options *options) | |
271b8d25 | 115 | { |
271b8d25 | 116 | struct object *parent = data; |
271b8d25 | 117 | |
a1cdc251 JH |
118 | /* |
119 | * The only case data is NULL or type is OBJ_ANY is when | |
120 | * mark_object_reachable() calls us. All the callers of | |
121 | * that function has non-NULL obj hence ... | |
122 | */ | |
271b8d25 | 123 | if (!obj) { |
a1cdc251 | 124 | /* ... these references to parent->fld are safe here */ |
674ba340 | 125 | printf_ln(_("broken link from %7s %s"), |
82ef89b3 JK |
126 | printable_type(&parent->oid, parent->type), |
127 | describe_object(&parent->oid)); | |
674ba340 NTND |
128 | printf_ln(_("broken link from %7s %s"), |
129 | (type == OBJ_ANY ? _("unknown") : type_name(type)), | |
130 | _("unknown")); | |
271b8d25 MK |
131 | errors_found |= ERROR_REACHABLE; |
132 | return 1; | |
133 | } | |
134 | ||
135 | if (type != OBJ_ANY && obj->type != type) | |
a1cdc251 | 136 | /* ... and the reference to parent is safe here */ |
674ba340 | 137 | objerror(parent, _("wrong object type in link")); |
271b8d25 MK |
138 | |
139 | if (obj->flags & REACHABLE) | |
140 | return 0; | |
141 | obj->flags |= REACHABLE; | |
caba7fc3 JT |
142 | |
143 | if (is_promisor_object(&obj->oid)) | |
144 | /* | |
145 | * Further recursion does not need to be performed on this | |
146 | * object since it is a promisor object (so it does not need to | |
147 | * be added to "pending"). | |
148 | */ | |
149 | return 0; | |
150 | ||
6e454b9a | 151 | if (!(obj->flags & HAS_OBJ)) { |
9eb86f41 | 152 | if (parent && !has_object(the_repository, &obj->oid, 1)) { |
674ba340 NTND |
153 | printf_ln(_("broken link from %7s %s\n" |
154 | " to %7s %s"), | |
82ef89b3 JK |
155 | printable_type(&parent->oid, parent->type), |
156 | describe_object(&parent->oid), | |
157 | printable_type(&obj->oid, obj->type), | |
158 | describe_object(&obj->oid)); | |
271b8d25 MK |
159 | errors_found |= ERROR_REACHABLE; |
160 | } | |
161 | return 1; | |
162 | } | |
163 | ||
16aa3bfc | 164 | add_object_array(obj, NULL, &pending); |
04d39759 LT |
165 | return 0; |
166 | } | |
167 | ||
168 | static void mark_object_reachable(struct object *obj) | |
169 | { | |
22410549 | 170 | mark_object(obj, OBJ_ANY, NULL, NULL); |
04d39759 LT |
171 | } |
172 | ||
a1cdc251 | 173 | static int traverse_one_object(struct object *obj) |
04d39759 | 174 | { |
ba3a08ca EW |
175 | int result = fsck_walk(obj, obj, &fsck_walk_options); |
176 | ||
177 | if (obj->type == OBJ_TREE) { | |
178 | struct tree *tree = (struct tree *)obj; | |
179 | free_tree_buffer(tree); | |
180 | } | |
181 | return result; | |
271b8d25 MK |
182 | } |
183 | ||
04d39759 | 184 | static int traverse_reachable(void) |
271b8d25 | 185 | { |
1e49f22f NTND |
186 | struct progress *progress = NULL; |
187 | unsigned int nr = 0; | |
04d39759 | 188 | int result = 0; |
1e49f22f | 189 | if (show_progress) |
8aade107 | 190 | progress = start_delayed_progress(_("Checking connectivity"), 0); |
04d39759 | 191 | while (pending.nr) { |
71992039 | 192 | result |= traverse_one_object(object_array_pop(&pending)); |
1e49f22f | 193 | display_progress(progress, ++nr); |
04d39759 | 194 | } |
1e49f22f | 195 | stop_progress(&progress); |
04d39759 | 196 | return !!result; |
271b8d25 MK |
197 | } |
198 | ||
a1aad716 ÆAB |
199 | static int mark_used(struct object *obj, enum object_type object_type, |
200 | void *data, struct fsck_options *options) | |
271b8d25 MK |
201 | { |
202 | if (!obj) | |
203 | return 1; | |
092c55d0 | 204 | obj->flags |= USED; |
271b8d25 | 205 | return 0; |
f1f0d088 PB |
206 | } |
207 | ||
8d8c2a5a JK |
208 | static void mark_unreachable_referents(const struct object_id *oid) |
209 | { | |
210 | struct fsck_options options = FSCK_OPTIONS_DEFAULT; | |
d0229abd | 211 | struct object *obj = lookup_object(the_repository, oid); |
8d8c2a5a JK |
212 | |
213 | if (!obj || !(obj->flags & HAS_OBJ)) | |
214 | return; /* not part of our original set */ | |
215 | if (obj->flags & REACHABLE) | |
216 | return; /* reachable objects already traversed */ | |
217 | ||
218 | /* | |
219 | * Avoid passing OBJ_NONE to fsck_walk, which will parse the object | |
220 | * (and we want to avoid parsing blobs). | |
221 | */ | |
222 | if (obj->type == OBJ_NONE) { | |
223 | enum object_type type = oid_object_info(the_repository, | |
224 | &obj->oid, NULL); | |
225 | if (type > 0) | |
6da43d93 | 226 | object_as_type(obj, type, 0); |
8d8c2a5a JK |
227 | } |
228 | ||
229 | options.walk = mark_used; | |
230 | fsck_walk(obj, NULL, &options); | |
231 | } | |
232 | ||
233 | static int mark_loose_unreachable_referents(const struct object_id *oid, | |
234 | const char *path, | |
235 | void *data) | |
236 | { | |
237 | mark_unreachable_referents(oid); | |
238 | return 0; | |
239 | } | |
240 | ||
241 | static int mark_packed_unreachable_referents(const struct object_id *oid, | |
242 | struct packed_git *pack, | |
243 | uint32_t pos, | |
244 | void *data) | |
245 | { | |
246 | mark_unreachable_referents(oid); | |
247 | return 0; | |
248 | } | |
249 | ||
18af29f2 LT |
250 | /* |
251 | * Check a single reachable object | |
252 | */ | |
253 | static void check_reachable_object(struct object *obj) | |
254 | { | |
18af29f2 LT |
255 | /* |
256 | * We obviously want the object to be parsed, | |
257 | * except if it was in a pack-file and we didn't | |
258 | * do a full fsck | |
259 | */ | |
6e454b9a | 260 | if (!(obj->flags & HAS_OBJ)) { |
caba7fc3 JT |
261 | if (is_promisor_object(&obj->oid)) |
262 | return; | |
14c3c80c | 263 | if (has_object_pack(&obj->oid)) |
18af29f2 | 264 | return; /* it is in pack - forget about it */ |
82ef89b3 JK |
265 | printf_ln(_("missing %s %s"), |
266 | printable_type(&obj->oid, obj->type), | |
267 | describe_object(&obj->oid)); | |
e2b4f635 | 268 | errors_found |= ERROR_REACHABLE; |
18af29f2 LT |
269 | return; |
270 | } | |
18af29f2 LT |
271 | } |
272 | ||
273 | /* | |
274 | * Check a single unreachable object | |
275 | */ | |
276 | static void check_unreachable_object(struct object *obj) | |
277 | { | |
278 | /* | |
279 | * Missing unreachable object? Ignore it. It's not like | |
280 | * we miss it (since it can't be reached), nor do we want | |
281 | * to complain about it being unreachable (since it does | |
282 | * not exist). | |
283 | */ | |
b4584e4f | 284 | if (!(obj->flags & HAS_OBJ)) |
18af29f2 LT |
285 | return; |
286 | ||
287 | /* | |
288 | * Unreachable object that exists? Show it if asked to, | |
289 | * since this is something that is prunable. | |
290 | */ | |
291 | if (show_unreachable) { | |
82ef89b3 JK |
292 | printf_ln(_("unreachable %s %s"), |
293 | printable_type(&obj->oid, obj->type), | |
294 | describe_object(&obj->oid)); | |
18af29f2 LT |
295 | return; |
296 | } | |
297 | ||
298 | /* | |
092c55d0 | 299 | * "!USED" means that nothing at all points to it, including |
3dff5379 | 300 | * other unreachable objects. In other words, it's the "tip" |
18af29f2 LT |
301 | * of some set of unreachable objects, usually a commit that |
302 | * got dropped. | |
303 | * | |
304 | * Such starting points are more interesting than some random | |
305 | * set of unreachable objects, so we show them even if the user | |
306 | * hasn't asked for _all_ unreachable objects. If you have | |
307 | * deleted a branch by mistake, this is a prime candidate to | |
308 | * start looking at, for example. | |
309 | */ | |
092c55d0 | 310 | if (!(obj->flags & USED)) { |
c6a13b2c | 311 | if (show_dangling) |
82ef89b3 JK |
312 | printf_ln(_("dangling %s %s"), |
313 | printable_type(&obj->oid, obj->type), | |
314 | describe_object(&obj->oid)); | |
68f6c019 | 315 | if (write_lost_and_found) { |
fcd12db6 | 316 | char *filename = git_pathdup("lost-found/%s/%s", |
68f6c019 | 317 | obj->type == OBJ_COMMIT ? "commit" : "other", |
82ef89b3 | 318 | describe_object(&obj->oid)); |
68f6c019 JS |
319 | FILE *f; |
320 | ||
dcf69262 | 321 | if (safe_create_leading_directories_const(filename)) { |
674ba340 | 322 | error(_("could not create lost-found")); |
fcd12db6 | 323 | free(filename); |
68f6c019 JS |
324 | return; |
325 | } | |
23a9e071 | 326 | f = xfopen(filename, "w"); |
16a7fcfe | 327 | if (obj->type == OBJ_BLOB) { |
7eda0e4f | 328 | if (stream_blob_to_fd(fileno(f), &obj->oid, NULL, 1)) |
674ba340 | 329 | die_errno(_("could not write '%s'"), filename); |
16a7fcfe | 330 | } else |
82ef89b3 | 331 | fprintf(f, "%s\n", describe_object(&obj->oid)); |
47d32af2 | 332 | if (fclose(f)) |
674ba340 | 333 | die_errno(_("could not finish '%s'"), |
d824cbba | 334 | filename); |
fcd12db6 | 335 | free(filename); |
68f6c019 | 336 | } |
18af29f2 LT |
337 | return; |
338 | } | |
339 | ||
340 | /* | |
341 | * Otherwise? It's there, it's unreachable, and some other unreachable | |
342 | * object points to it. Ignore it - it's not interesting, and we showed | |
343 | * all the interesting cases above. | |
344 | */ | |
345 | } | |
346 | ||
347 | static void check_object(struct object *obj) | |
348 | { | |
20f1eb6b | 349 | if (verbose) |
82ef89b3 | 350 | fprintf_ln(stderr, _("Checking %s"), describe_object(&obj->oid)); |
20f1eb6b | 351 | |
18af29f2 LT |
352 | if (obj->flags & REACHABLE) |
353 | check_reachable_object(obj); | |
354 | else | |
355 | check_unreachable_object(obj); | |
356 | } | |
f1f0d088 | 357 | |
8ba0bbb2 LT |
358 | static void check_connectivity(void) |
359 | { | |
fc046a75 | 360 | int i, max; |
8ba0bbb2 | 361 | |
04d39759 LT |
362 | /* Traverse the pending reachable objects */ |
363 | traverse_reachable(); | |
364 | ||
8d8c2a5a JK |
365 | /* |
366 | * With --connectivity-only, we won't have actually opened and marked | |
367 | * unreachable objects with USED. Do that now to make --dangling, etc | |
368 | * accurate. | |
369 | */ | |
370 | if (connectivity_only && (show_dangling || write_lost_and_found)) { | |
371 | /* | |
372 | * Even though we already have a "struct object" for each of | |
373 | * these in memory, we must not iterate over the internal | |
374 | * object hash as we do below. Our loop would potentially | |
375 | * resize the hash, making our iteration invalid. | |
376 | * | |
377 | * Instead, we'll just go back to the source list of objects, | |
378 | * and ignore any that weren't present in our earlier | |
379 | * traversal. | |
380 | */ | |
381 | for_each_loose_object(mark_loose_unreachable_referents, NULL, 0); | |
382 | for_each_packed_object(mark_packed_unreachable_referents, NULL, 0); | |
383 | } | |
384 | ||
8ba0bbb2 | 385 | /* Look up all the requirements, warn about missing objects.. */ |
fc046a75 | 386 | max = get_max_object_index(); |
20f1eb6b | 387 | if (verbose) |
674ba340 | 388 | fprintf_ln(stderr, _("Checking connectivity (%d objects)"), max); |
20f1eb6b | 389 | |
fc046a75 | 390 | for (i = 0; i < max; i++) { |
fc046a75 | 391 | struct object *obj = get_indexed_object(i); |
8ba0bbb2 | 392 | |
18af29f2 LT |
393 | if (obj) |
394 | check_object(obj); | |
8ba0bbb2 LT |
395 | } |
396 | } | |
397 | ||
7ac4f3a0 | 398 | static int fsck_obj(struct object *obj, void *buffer, unsigned long size) |
85003492 | 399 | { |
83cd6f90 RS |
400 | int err; |
401 | ||
ba002f3b | 402 | if (obj->flags & SEEN) |
85003492 | 403 | return 0; |
ba002f3b | 404 | obj->flags |= SEEN; |
85003492 | 405 | |
20f1eb6b | 406 | if (verbose) |
674ba340 | 407 | fprintf_ln(stderr, _("Checking %s %s"), |
82ef89b3 JK |
408 | printable_type(&obj->oid, obj->type), |
409 | describe_object(&obj->oid)); | |
42ea9cb2 | 410 | |
22410549 | 411 | if (fsck_walk(obj, NULL, &fsck_obj_options)) |
674ba340 | 412 | objerror(obj, _("broken links")); |
7ac4f3a0 | 413 | err = fsck_object(obj, buffer, size, &fsck_obj_options); |
83cd6f90 RS |
414 | if (err) |
415 | goto out; | |
1ea34e36 | 416 | |
ba002f3b MK |
417 | if (obj->type == OBJ_COMMIT) { |
418 | struct commit *commit = (struct commit *) obj; | |
de2eb7f6 | 419 | |
ba002f3b | 420 | if (!commit->parents && show_root) |
674ba340 | 421 | printf_ln(_("root %s"), |
82ef89b3 | 422 | describe_object(&commit->object.oid)); |
ba002f3b | 423 | } |
92d4c85d | 424 | |
ba002f3b MK |
425 | if (obj->type == OBJ_TAG) { |
426 | struct tag *tag = (struct tag *) obj; | |
20f1eb6b | 427 | |
ba002f3b | 428 | if (show_tags && tag->tagged) { |
674ba340 | 429 | printf_ln(_("tagged %s %s (%s) in %s"), |
82ef89b3 JK |
430 | printable_type(&tag->tagged->oid, tag->tagged->type), |
431 | describe_object(&tag->tagged->oid), | |
bbb15c51 | 432 | tag->tag, |
82ef89b3 | 433 | describe_object(&tag->object.oid)); |
ba002f3b | 434 | } |
92d4c85d | 435 | } |
889262ea | 436 | |
83cd6f90 RS |
437 | out: |
438 | if (obj->type == OBJ_TREE) | |
439 | free_tree_buffer((struct tree *)obj); | |
440 | if (obj->type == OBJ_COMMIT) | |
6a7895fd SB |
441 | free_commit_buffer(the_repository->parsed_objects, |
442 | (struct commit *)obj); | |
83cd6f90 | 443 | return err; |
20222118 LT |
444 | } |
445 | ||
9fd75046 | 446 | static int fsck_obj_buffer(const struct object_id *oid, enum object_type type, |
c9486eb0 NTND |
447 | unsigned long size, void *buffer, int *eaten) |
448 | { | |
ec9d2249 NTND |
449 | /* |
450 | * Note, buffer may be NULL if type is OBJ_BLOB. See | |
451 | * verify_packfile(), data_valid variable for details. | |
452 | */ | |
c9486eb0 | 453 | struct object *obj; |
1ec5bfd2 SB |
454 | obj = parse_object_buffer(the_repository, oid, type, size, buffer, |
455 | eaten); | |
c9486eb0 NTND |
456 | if (!obj) { |
457 | errors_found |= ERROR_OBJECT; | |
674ba340 NTND |
458 | return error(_("%s: object corrupt or missing"), |
459 | oid_to_hex(oid)); | |
c9486eb0 | 460 | } |
092c55d0 JT |
461 | obj->flags &= ~(REACHABLE | SEEN); |
462 | obj->flags |= HAS_OBJ; | |
7ac4f3a0 | 463 | return fsck_obj(obj, buffer, size); |
c9486eb0 NTND |
464 | } |
465 | ||
96f1e58f | 466 | static int default_refs; |
944d8589 | 467 | |
9461d272 | 468 | static void fsck_handle_reflog_oid(const char *refname, struct object_id *oid, |
dddbad72 | 469 | timestamp_t timestamp) |
55dd5526 JH |
470 | { |
471 | struct object *obj; | |
472 | ||
9461d272 | 473 | if (!is_null_oid(oid)) { |
d0229abd | 474 | obj = lookup_object(the_repository, oid); |
c2d17b3b | 475 | if (obj && (obj->flags & HAS_OBJ)) { |
a59cfb32 | 476 | if (timestamp) |
73390290 | 477 | fsck_put_object_name(&fsck_walk_options, oid, |
a59cfb32 JK |
478 | "%s@{%"PRItime"}", |
479 | refname, timestamp); | |
092c55d0 | 480 | obj->flags |= USED; |
271b8d25 | 481 | mark_object_reachable(obj); |
498f1f61 | 482 | } else if (!is_promisor_object(oid)) { |
674ba340 NTND |
483 | error(_("%s: invalid reflog entry %s"), |
484 | refname, oid_to_hex(oid)); | |
19bf6c9b | 485 | errors_found |= ERROR_REACHABLE; |
55dd5526 JH |
486 | } |
487 | } | |
d66ae59b MH |
488 | } |
489 | ||
9461d272 | 490 | static int fsck_handle_reflog_ent(struct object_id *ooid, struct object_id *noid, |
dddbad72 | 491 | const char *email, timestamp_t timestamp, int tz, |
883d60fa | 492 | const char *message, void *cb_data) |
55dd5526 | 493 | { |
19bf6c9b | 494 | const char *refname = cb_data; |
55dd5526 | 495 | |
20f1eb6b | 496 | if (verbose) |
674ba340 NTND |
497 | fprintf_ln(stderr, _("Checking reflog %s->%s"), |
498 | oid_to_hex(ooid), oid_to_hex(noid)); | |
20f1eb6b | 499 | |
9461d272 | 500 | fsck_handle_reflog_oid(refname, ooid, 0); |
501 | fsck_handle_reflog_oid(refname, noid, timestamp); | |
55dd5526 JH |
502 | return 0; |
503 | } | |
504 | ||
635b99a0 MH |
505 | static int fsck_handle_reflog(const char *logname, const struct object_id *oid, |
506 | int flag, void *cb_data) | |
eb8381c8 | 507 | { |
b29759d8 NTND |
508 | struct strbuf refname = STRBUF_INIT; |
509 | ||
510 | strbuf_worktree_ref(cb_data, &refname, logname); | |
511 | for_each_reflog_ent(refname.buf, fsck_handle_reflog_ent, refname.buf); | |
512 | strbuf_release(&refname); | |
eb8381c8 NP |
513 | return 0; |
514 | } | |
515 | ||
635b99a0 MH |
516 | static int fsck_handle_ref(const char *refname, const struct object_id *oid, |
517 | int flag, void *cb_data) | |
1024932f | 518 | { |
1024932f LT |
519 | struct object *obj; |
520 | ||
109cd76d | 521 | obj = parse_object(the_repository, oid); |
8a498a05 | 522 | if (!obj) { |
43f25158 JT |
523 | if (is_promisor_object(oid)) { |
524 | /* | |
525 | * Increment default_refs anyway, because this is a | |
526 | * valid ref. | |
527 | */ | |
528 | default_refs++; | |
529 | return 0; | |
530 | } | |
674ba340 NTND |
531 | error(_("%s: invalid sha1 pointer %s"), |
532 | refname, oid_to_hex(oid)); | |
30d1038d | 533 | errors_found |= ERROR_REACHABLE; |
944d8589 LT |
534 | /* We'll continue with the rest despite the error.. */ |
535 | return 0; | |
8a498a05 | 536 | } |
122f76f5 | 537 | if (obj->type != OBJ_COMMIT && is_branch(refname)) { |
674ba340 | 538 | error(_("%s: not a commit"), refname); |
122f76f5 JH |
539 | errors_found |= ERROR_REFS; |
540 | } | |
944d8589 | 541 | default_refs++; |
092c55d0 | 542 | obj->flags |= USED; |
a59cfb32 | 543 | fsck_put_object_name(&fsck_walk_options, |
73390290 | 544 | oid, "%s", refname); |
271b8d25 | 545 | mark_object_reachable(obj); |
55dd5526 | 546 | |
7c4d07c7 | 547 | return 0; |
1024932f LT |
548 | } |
549 | ||
b29759d8 NTND |
550 | static int fsck_head_link(const char *head_ref_name, |
551 | const char **head_points_at, | |
a8c754d4 EN |
552 | struct object_id *head_oid); |
553 | ||
1024932f LT |
554 | static void get_default_heads(void) |
555 | { | |
b29759d8 | 556 | struct worktree **worktrees, **p; |
a8c754d4 EN |
557 | const char *head_points_at; |
558 | struct object_id head_oid; | |
559 | ||
635b99a0 | 560 | for_each_rawref(fsck_handle_ref, NULL); |
b29759d8 | 561 | |
03f2465b | 562 | worktrees = get_worktrees(); |
b29759d8 NTND |
563 | for (p = worktrees; *p; p++) { |
564 | struct worktree *wt = *p; | |
565 | struct strbuf ref = STRBUF_INIT; | |
566 | ||
567 | strbuf_worktree_ref(wt, &ref, "HEAD"); | |
568 | fsck_head_link(ref.buf, &head_points_at, &head_oid); | |
569 | if (head_points_at && !is_null_oid(&head_oid)) | |
570 | fsck_handle_ref(ref.buf, &head_oid, 0, NULL); | |
571 | strbuf_release(&ref); | |
572 | ||
573 | if (include_reflogs) | |
574 | refs_for_each_reflog(get_worktree_ref_store(wt), | |
575 | fsck_handle_reflog, wt); | |
576 | } | |
577 | free_worktrees(worktrees); | |
071fa89e LT |
578 | |
579 | /* | |
580 | * Not having any default heads isn't really fatal, but | |
581 | * it does mean that "--unreachable" no longer makes any | |
582 | * sense (since in this case everything will obviously | |
583 | * be unreachable by definition. | |
584 | * | |
585 | * Showing dangling objects is valid, though (as those | |
586 | * dangling objects are likely lost heads). | |
587 | * | |
588 | * So we just print a warning about it, and clear the | |
589 | * "show_unreachable" flag. | |
590 | */ | |
591 | if (!default_refs) { | |
674ba340 | 592 | fprintf_ln(stderr, _("notice: No default references")); |
071fa89e LT |
593 | show_unreachable = 0; |
594 | } | |
1024932f LT |
595 | } |
596 | ||
31deb28f ÆAB |
597 | struct for_each_loose_cb |
598 | { | |
599 | struct progress *progress; | |
600 | struct strbuf obj_type; | |
601 | }; | |
602 | ||
7ac4f3a0 | 603 | static int fsck_loose(const struct object_id *oid, const char *path, void *data) |
c68b489e | 604 | { |
31deb28f | 605 | struct for_each_loose_cb *cb_data = data; |
c68b489e | 606 | struct object *obj; |
31deb28f | 607 | enum object_type type = OBJ_NONE; |
c68b489e | 608 | unsigned long size; |
16235e3b | 609 | void *contents = NULL; |
c68b489e | 610 | int eaten; |
31deb28f | 611 | struct object_info oi = OBJECT_INFO_INIT; |
96e41f58 | 612 | struct object_id real_oid = *null_oid(); |
31deb28f ÆAB |
613 | int err = 0; |
614 | ||
615 | strbuf_reset(&cb_data->obj_type); | |
616 | oi.type_name = &cb_data->obj_type; | |
617 | oi.sizep = &size; | |
618 | oi.typep = &type; | |
619 | ||
96e41f58 ÆAB |
620 | if (read_loose_object(path, oid, &real_oid, &contents, &oi) < 0) { |
621 | if (contents && !oideq(&real_oid, oid)) | |
622 | err = error(_("%s: hash-path mismatch, found at: %s"), | |
623 | oid_to_hex(&real_oid), path); | |
624 | else | |
625 | err = error(_("%s: object corrupt or missing: %s"), | |
626 | oid_to_hex(oid), path); | |
627 | } | |
31deb28f ÆAB |
628 | if (type != OBJ_NONE && type < 0) |
629 | err = error(_("%s: object is of unknown type '%s': %s"), | |
96e41f58 ÆAB |
630 | oid_to_hex(&real_oid), cb_data->obj_type.buf, |
631 | path); | |
31deb28f | 632 | if (err < 0) { |
7ac4f3a0 | 633 | errors_found |= ERROR_OBJECT; |
16235e3b | 634 | free(contents); |
7ac4f3a0 JK |
635 | return 0; /* keep checking other objects */ |
636 | } | |
c68b489e JK |
637 | |
638 | if (!contents && type != OBJ_BLOB) | |
7ac4f3a0 | 639 | BUG("read_loose_object streamed a non-blob"); |
c68b489e | 640 | |
1ec5bfd2 SB |
641 | obj = parse_object_buffer(the_repository, oid, type, size, |
642 | contents, &eaten); | |
643 | ||
c68b489e JK |
644 | if (!obj) { |
645 | errors_found |= ERROR_OBJECT; | |
674ba340 | 646 | error(_("%s: object could not be parsed: %s"), |
76c1d9a0 | 647 | oid_to_hex(oid), path); |
7ac4f3a0 JK |
648 | if (!eaten) |
649 | free(contents); | |
c68b489e JK |
650 | return 0; /* keep checking other objects */ |
651 | } | |
652 | ||
092c55d0 JT |
653 | obj->flags &= ~(REACHABLE | SEEN); |
654 | obj->flags |= HAS_OBJ; | |
7ac4f3a0 | 655 | if (fsck_obj(obj, contents, size)) |
f0766bf9 | 656 | errors_found |= ERROR_OBJECT; |
7ac4f3a0 JK |
657 | |
658 | if (!eaten) | |
659 | free(contents); | |
660 | return 0; /* keep checking other objects, even if we saw an error */ | |
f0766bf9 JK |
661 | } |
662 | ||
663 | static int fsck_cruft(const char *basename, const char *path, void *data) | |
664 | { | |
665 | if (!starts_with(basename, "tmp_obj_")) | |
674ba340 | 666 | fprintf_ln(stderr, _("bad sha1 file: %s"), path); |
f0766bf9 JK |
667 | return 0; |
668 | } | |
669 | ||
31deb28f | 670 | static int fsck_subdir(unsigned int nr, const char *path, void *data) |
f0766bf9 | 671 | { |
31deb28f ÆAB |
672 | struct for_each_loose_cb *cb_data = data; |
673 | struct progress *progress = cb_data->progress; | |
f0766bf9 JK |
674 | display_progress(progress, nr + 1); |
675 | return 0; | |
676 | } | |
677 | ||
8a498a05 JH |
678 | static void fsck_object_dir(const char *path) |
679 | { | |
1e49f22f | 680 | struct progress *progress = NULL; |
31deb28f ÆAB |
681 | struct for_each_loose_cb cb_data = { |
682 | .obj_type = STRBUF_INIT, | |
683 | .progress = progress, | |
684 | }; | |
20f1eb6b JS |
685 | |
686 | if (verbose) | |
674ba340 | 687 | fprintf_ln(stderr, _("Checking object directory")); |
20f1eb6b | 688 | |
1e49f22f | 689 | if (show_progress) |
754dbc43 | 690 | progress = start_progress(_("Checking object directories"), 256); |
f0766bf9 JK |
691 | |
692 | for_each_loose_file_in_objdir(path, fsck_loose, fsck_cruft, fsck_subdir, | |
31deb28f | 693 | &cb_data); |
f0766bf9 | 694 | display_progress(progress, 256); |
1e49f22f | 695 | stop_progress(&progress); |
31deb28f | 696 | strbuf_release(&cb_data.obj_type); |
8a498a05 JH |
697 | } |
698 | ||
b29759d8 NTND |
699 | static int fsck_head_link(const char *head_ref_name, |
700 | const char **head_points_at, | |
a8c754d4 | 701 | struct object_id *head_oid) |
c3330383 | 702 | { |
8eb2d0be | 703 | int null_is_error = 0; |
8eb2d0be | 704 | |
20f1eb6b | 705 | if (verbose) |
3813a89f | 706 | fprintf_ln(stderr, _("Checking %s link"), head_ref_name); |
20f1eb6b | 707 | |
b29759d8 | 708 | *head_points_at = resolve_ref_unsafe(head_ref_name, 0, head_oid, NULL); |
a8c754d4 | 709 | if (!*head_points_at) { |
122f76f5 | 710 | errors_found |= ERROR_REFS; |
3813a89f | 711 | return error(_("invalid %s"), head_ref_name); |
122f76f5 | 712 | } |
b29759d8 | 713 | if (!strcmp(*head_points_at, head_ref_name)) |
8eb2d0be JH |
714 | /* detached HEAD */ |
715 | null_is_error = 1; | |
a8c754d4 | 716 | else if (!starts_with(*head_points_at, "refs/heads/")) { |
122f76f5 | 717 | errors_found |= ERROR_REFS; |
3813a89f | 718 | return error(_("%s points to something strange (%s)"), |
b29759d8 | 719 | head_ref_name, *head_points_at); |
122f76f5 | 720 | } |
a8c754d4 | 721 | if (is_null_oid(head_oid)) { |
122f76f5 JH |
722 | if (null_is_error) { |
723 | errors_found |= ERROR_REFS; | |
3813a89f | 724 | return error(_("%s: detached HEAD points at nothing"), |
b29759d8 | 725 | head_ref_name); |
122f76f5 | 726 | } |
3813a89f JH |
727 | fprintf_ln(stderr, |
728 | _("notice: %s points to an unborn branch (%s)"), | |
729 | head_ref_name, *head_points_at + 11); | |
8eb2d0be | 730 | } |
c3330383 LT |
731 | return 0; |
732 | } | |
733 | ||
53dc3f3e JH |
734 | static int fsck_cache_tree(struct cache_tree *it) |
735 | { | |
736 | int i; | |
737 | int err = 0; | |
738 | ||
20f1eb6b | 739 | if (verbose) |
674ba340 | 740 | fprintf_ln(stderr, _("Checking cache tree")); |
20f1eb6b | 741 | |
53dc3f3e | 742 | if (0 <= it->entry_count) { |
109cd76d | 743 | struct object *obj = parse_object(the_repository, &it->oid); |
6d60bbef | 744 | if (!obj) { |
674ba340 | 745 | error(_("%s: invalid sha1 pointer in cache-tree"), |
e0a92804 | 746 | oid_to_hex(&it->oid)); |
122f76f5 | 747 | errors_found |= ERROR_REFS; |
6d60bbef JH |
748 | return 1; |
749 | } | |
092c55d0 | 750 | obj->flags |= USED; |
73390290 | 751 | fsck_put_object_name(&fsck_walk_options, &it->oid, ":"); |
a1cdc251 | 752 | mark_object_reachable(obj); |
1974632c | 753 | if (obj->type != OBJ_TREE) |
674ba340 | 754 | err |= objerror(obj, _("non-tree in cache-tree")); |
53dc3f3e JH |
755 | } |
756 | for (i = 0; i < it->subtree_nr; i++) | |
757 | err |= fsck_cache_tree(it->down[i]->cache_tree); | |
758 | return err; | |
759 | } | |
760 | ||
5a5ea141 JH |
761 | static int fsck_resolve_undo(struct index_state *istate) |
762 | { | |
763 | struct string_list_item *item; | |
764 | struct string_list *resolve_undo = istate->resolve_undo; | |
765 | ||
766 | if (!resolve_undo) | |
767 | return 0; | |
768 | ||
769 | for_each_string_list_item(item, resolve_undo) { | |
770 | const char *path = item->string; | |
771 | struct resolve_undo_info *ru = item->util; | |
772 | int i; | |
773 | ||
774 | if (!ru) | |
775 | continue; | |
776 | for (i = 0; i < 3; i++) { | |
777 | struct object *obj; | |
778 | ||
779 | if (!ru->mode[i] || !S_ISREG(ru->mode[i])) | |
780 | continue; | |
781 | ||
782 | obj = parse_object(the_repository, &ru->oid[i]); | |
783 | if (!obj) { | |
784 | error(_("%s: invalid sha1 pointer in resolve-undo"), | |
785 | oid_to_hex(&ru->oid[i])); | |
786 | errors_found |= ERROR_REFS; | |
787 | } | |
788 | obj->flags |= USED; | |
789 | fsck_put_object_name(&fsck_walk_options, &ru->oid[i], | |
790 | ":(%d):%s", i, path); | |
791 | mark_object_reachable(obj); | |
792 | } | |
793 | } | |
794 | return 0; | |
795 | } | |
796 | ||
76c1d9a0 | 797 | static void mark_object_for_connectivity(const struct object_id *oid) |
3e3f8bd6 | 798 | { |
45a187cc | 799 | struct object *obj = lookup_unknown_object(the_repository, oid); |
3e3f8bd6 JK |
800 | obj->flags |= HAS_OBJ; |
801 | } | |
802 | ||
76c1d9a0 | 803 | static int mark_loose_for_connectivity(const struct object_id *oid, |
3e3f8bd6 JK |
804 | const char *path, |
805 | void *data) | |
806 | { | |
76c1d9a0 | 807 | mark_object_for_connectivity(oid); |
3e3f8bd6 JK |
808 | return 0; |
809 | } | |
810 | ||
76c1d9a0 | 811 | static int mark_packed_for_connectivity(const struct object_id *oid, |
3e3f8bd6 JK |
812 | struct packed_git *pack, |
813 | uint32_t pos, | |
814 | void *data) | |
815 | { | |
76c1d9a0 | 816 | mark_object_for_connectivity(oid); |
3e3f8bd6 JK |
817 | return 0; |
818 | } | |
819 | ||
5ac0a206 | 820 | static char const * const fsck_usage[] = { |
9c9b4f2f | 821 | N_("git fsck [<options>] [<object>...]"), |
5ac0a206 PH |
822 | NULL |
823 | }; | |
824 | ||
825 | static struct option fsck_opts[] = { | |
cf8fe315 | 826 | OPT__VERBOSE(&verbose, N_("be verbose")), |
d5d09d47 | 827 | OPT_BOOL(0, "unreachable", &show_unreachable, N_("show unreachable objects")), |
cf8fe315 | 828 | OPT_BOOL(0, "dangling", &show_dangling, N_("show dangling objects")), |
d5d09d47 SB |
829 | OPT_BOOL(0, "tags", &show_tags, N_("report tags")), |
830 | OPT_BOOL(0, "root", &show_root, N_("report root nodes")), | |
831 | OPT_BOOL(0, "cache", &keep_cache_objects, N_("make index objects head nodes")), | |
832 | OPT_BOOL(0, "reflogs", &include_reflogs, N_("make reflogs head nodes (default)")), | |
833 | OPT_BOOL(0, "full", &check_full, N_("also consider packs and alternate objects")), | |
02976bf8 | 834 | OPT_BOOL(0, "connectivity-only", &connectivity_only, N_("check only connectivity")), |
d5d09d47 SB |
835 | OPT_BOOL(0, "strict", &check_strict, N_("enable more strict checking")), |
836 | OPT_BOOL(0, "lost-found", &write_lost_and_found, | |
cf8fe315 NTND |
837 | N_("write dangling objects in .git/lost-found")), |
838 | OPT_BOOL(0, "progress", &show_progress, N_("show progress")), | |
90cf590f | 839 | OPT_BOOL(0, "name-objects", &name_objects, N_("show verbose names for reachable objects")), |
5ac0a206 PH |
840 | OPT_END(), |
841 | }; | |
e2b4f635 | 842 | |
baffc0e7 | 843 | int cmd_fsck(int argc, const char **argv, const char *prefix) |
20222118 | 844 | { |
78e7b98f | 845 | int i; |
263db403 | 846 | struct object_directory *odb; |
20222118 | 847 | |
8b4c0103 JT |
848 | /* fsck knows how to handle missing promisor objects */ |
849 | fetch_if_missing = 0; | |
850 | ||
e2b4f635 | 851 | errors_found = 0; |
6ebd1caf | 852 | read_replace_refs = 0; |
61e2b015 | 853 | |
37782920 | 854 | argc = parse_options(argc, argv, prefix, fsck_opts, fsck_usage, 0); |
1e49f22f | 855 | |
22410549 JS |
856 | fsck_walk_options.walk = mark_object; |
857 | fsck_obj_options.walk = mark_used; | |
858 | fsck_obj_options.error_func = fsck_error_func; | |
859 | if (check_strict) | |
860 | fsck_obj_options.strict = 1; | |
861 | ||
1e49f22f NTND |
862 | if (show_progress == -1) |
863 | show_progress = isatty(2); | |
864 | if (verbose) | |
865 | show_progress = 0; | |
866 | ||
5ac0a206 PH |
867 | if (write_lost_and_found) { |
868 | check_full = 1; | |
869 | include_reflogs = 0; | |
889262ea LT |
870 | } |
871 | ||
90cf590f | 872 | if (name_objects) |
a59cfb32 | 873 | fsck_enable_object_names(&fsck_walk_options); |
90cf590f | 874 | |
fb79f5bf | 875 | git_config(git_fsck_config, &fsck_obj_options); |
f30e4d85 | 876 | prepare_repo_settings(the_repository); |
2becf00f | 877 | |
3e3f8bd6 JK |
878 | if (connectivity_only) { |
879 | for_each_loose_object(mark_loose_for_connectivity, NULL, 0); | |
880 | for_each_packed_object(mark_packed_for_connectivity, NULL, 0); | |
881 | } else { | |
0b209034 | 882 | prepare_alt_odb(the_repository); |
f0eaf638 | 883 | for (odb = the_repository->objects->odb; odb; odb = odb->next) |
263db403 | 884 | fsck_object_dir(odb->path); |
e15ef669 | 885 | |
3e3f8bd6 JK |
886 | if (check_full) { |
887 | struct packed_git *p; | |
888 | uint32_t total = 0, count = 0; | |
889 | struct progress *progress = NULL; | |
e15ef669 | 890 | |
3e3f8bd6 | 891 | if (show_progress) { |
454ea2e4 | 892 | for (p = get_all_packs(the_repository); p; |
a80d72db | 893 | p = p->next) { |
3e3f8bd6 JK |
894 | if (open_pack_index(p)) |
895 | continue; | |
896 | total += p->num_objects; | |
897 | } | |
1e49f22f | 898 | |
3e3f8bd6 JK |
899 | progress = start_progress(_("Checking objects"), total); |
900 | } | |
454ea2e4 | 901 | for (p = get_all_packs(the_repository); p; |
a80d72db | 902 | p = p->next) { |
3e3f8bd6 | 903 | /* verify gives error messages itself */ |
94e10825 NTND |
904 | if (verify_pack(the_repository, |
905 | p, fsck_obj_buffer, | |
3e3f8bd6 JK |
906 | progress, count)) |
907 | errors_found |= ERROR_PACK; | |
908 | count += p->num_objects; | |
1e49f22f | 909 | } |
3e3f8bd6 | 910 | stop_progress(&progress); |
1e49f22f | 911 | } |
1995b5e0 JK |
912 | |
913 | if (fsck_finish(&fsck_obj_options)) | |
914 | errors_found |= ERROR_OBJECT; | |
bcee6fd8 LT |
915 | } |
916 | ||
3aed2fda | 917 | for (i = 0; i < argc; i++) { |
a6080a0a | 918 | const char *arg = argv[i]; |
aca6065c | 919 | struct object_id oid; |
920 | if (!get_oid(arg, &oid)) { | |
5abddd1e | 921 | struct object *obj = lookup_object(the_repository, |
d0229abd | 922 | &oid); |
e1a1388d | 923 | |
c2d17b3b | 924 | if (!obj || !(obj->flags & HAS_OBJ)) { |
096c9b8b JT |
925 | if (is_promisor_object(&oid)) |
926 | continue; | |
674ba340 | 927 | error(_("%s: object missing"), oid_to_hex(&oid)); |
c6c7b16d | 928 | errors_found |= ERROR_OBJECT; |
e1a1388d | 929 | continue; |
c6c7b16d | 930 | } |
e1a1388d | 931 | |
092c55d0 | 932 | obj->flags |= USED; |
73390290 | 933 | fsck_put_object_name(&fsck_walk_options, &oid, |
a59cfb32 | 934 | "%s", arg); |
271b8d25 | 935 | mark_object_reachable(obj); |
d9839e03 LT |
936 | continue; |
937 | } | |
674ba340 | 938 | error(_("invalid parameter: expected sha1, got '%s'"), arg); |
c6c7b16d | 939 | errors_found |= ERROR_OBJECT; |
d9839e03 | 940 | } |
d9839e03 | 941 | |
1024932f | 942 | /* |
d1af002d | 943 | * If we've not been given any explicit head information, do the |
e7bd907d LT |
944 | * default ones from .git/refs. We also consider the index file |
945 | * in this case (ie this implies --cache). | |
1024932f | 946 | */ |
c3271a0e | 947 | if (!argc) { |
1024932f LT |
948 | get_default_heads(); |
949 | keep_cache_objects = 1; | |
950 | } | |
951 | ||
ae7c0c92 | 952 | if (keep_cache_objects) { |
a33fc72f | 953 | verify_index_checksum = 1; |
00ec50e5 | 954 | verify_ce_order = 1; |
ae7c0c92 | 955 | read_cache(); |
2227ea17 DS |
956 | /* TODO: audit for interaction with sparse-index. */ |
957 | ensure_full_index(&the_index); | |
ae7c0c92 | 958 | for (i = 0; i < active_nr; i++) { |
8d9721c8 LT |
959 | unsigned int mode; |
960 | struct blob *blob; | |
ae7c0c92 | 961 | struct object *obj; |
8d9721c8 | 962 | |
7a51ed66 | 963 | mode = active_cache[i]->ce_mode; |
302b9282 | 964 | if (S_ISGITLINK(mode)) |
8d9721c8 | 965 | continue; |
da14a7ff SB |
966 | blob = lookup_blob(the_repository, |
967 | &active_cache[i]->oid); | |
ae7c0c92 JH |
968 | if (!blob) |
969 | continue; | |
970 | obj = &blob->object; | |
092c55d0 | 971 | obj->flags |= USED; |
73390290 | 972 | fsck_put_object_name(&fsck_walk_options, &obj->oid, |
a59cfb32 | 973 | ":%s", active_cache[i]->name); |
271b8d25 | 974 | mark_object_reachable(obj); |
ae7c0c92 | 975 | } |
53dc3f3e JH |
976 | if (active_cache_tree) |
977 | fsck_cache_tree(active_cache_tree); | |
5a5ea141 | 978 | fsck_resolve_undo(&the_index); |
ae7c0c92 JH |
979 | } |
980 | ||
8ba0bbb2 | 981 | check_connectivity(); |
e0fd51e1 | 982 | |
f30e4d85 | 983 | if (the_repository->settings.core_commit_graph) { |
e0fd51e1 | 984 | struct child_process commit_graph_verify = CHILD_PROCESS_INIT; |
e0fd51e1 | 985 | |
e0fd51e1 | 986 | prepare_alt_odb(the_repository); |
f0eaf638 | 987 | for (odb = the_repository->objects->odb; odb; odb = odb->next) { |
4d0984be | 988 | child_process_init(&commit_graph_verify); |
4d0984be | 989 | commit_graph_verify.git_cmd = 1; |
2b709893 ÆAB |
990 | strvec_pushl(&commit_graph_verify.args, "commit-graph", |
991 | "verify", "--object-dir", odb->path, NULL); | |
e0fd51e1 DS |
992 | if (run_command(&commit_graph_verify)) |
993 | errors_found |= ERROR_COMMIT_GRAPH; | |
994 | } | |
995 | } | |
996 | ||
dc557087 | 997 | if (the_repository->settings.core_multi_pack_index) { |
66ec0390 | 998 | struct child_process midx_verify = CHILD_PROCESS_INIT; |
66ec0390 | 999 | |
66ec0390 | 1000 | prepare_alt_odb(the_repository); |
f0eaf638 | 1001 | for (odb = the_repository->objects->odb; odb; odb = odb->next) { |
4d0984be | 1002 | child_process_init(&midx_verify); |
4d0984be | 1003 | midx_verify.git_cmd = 1; |
2b709893 ÆAB |
1004 | strvec_pushl(&midx_verify.args, "multi-pack-index", |
1005 | "verify", "--object-dir", odb->path, NULL); | |
66ec0390 | 1006 | if (run_command(&midx_verify)) |
e68a5272 | 1007 | errors_found |= ERROR_MULTI_PACK_INDEX; |
66ec0390 DS |
1008 | } |
1009 | } | |
1010 | ||
e2b4f635 | 1011 | return errors_found; |
20222118 | 1012 | } |