Git fork
at reftables-rust 1410 lines 38 kB view raw
1#define USE_THE_REPOSITORY_VARIABLE 2 3#include "git-compat-util.h" 4#include "date.h" 5#include "dir.h" 6#include "environment.h" 7#include "hex.h" 8#include "odb.h" 9#include "path.h" 10#include "repository.h" 11#include "object.h" 12#include "attr.h" 13#include "blob.h" 14#include "tree.h" 15#include "tree-walk.h" 16#include "commit.h" 17#include "tag.h" 18#include "fsck.h" 19#include "refs.h" 20#include "url.h" 21#include "utf8.h" 22#include "oidset.h" 23#include "packfile.h" 24#include "submodule-config.h" 25#include "config.h" 26#include "help.h" 27 28static ssize_t max_tree_entry_len = 4096; 29 30#define STR(x) #x 31#define MSG_ID(id, msg_type) { STR(id), NULL, NULL, FSCK_##msg_type }, 32static struct { 33 const char *id_string; 34 const char *downcased; 35 const char *camelcased; 36 enum fsck_msg_type msg_type; 37} msg_id_info[FSCK_MSG_MAX + 1] = { 38 FOREACH_FSCK_MSG_ID(MSG_ID) 39 { NULL, NULL, NULL, -1 } 40}; 41#undef MSG_ID 42#undef STR 43 44static void prepare_msg_ids(void) 45{ 46 int i; 47 48 if (msg_id_info[0].downcased) 49 return; 50 51 /* convert id_string to lower case, without underscores. */ 52 for (i = 0; i < FSCK_MSG_MAX; i++) { 53 const char *p = msg_id_info[i].id_string; 54 int len = strlen(p); 55 char *q = xmalloc(len); 56 57 msg_id_info[i].downcased = q; 58 while (*p) 59 if (*p == '_') 60 p++; 61 else 62 *(q)++ = tolower(*(p)++); 63 *q = '\0'; 64 65 p = msg_id_info[i].id_string; 66 q = xmalloc(len); 67 msg_id_info[i].camelcased = q; 68 while (*p) { 69 if (*p == '_') { 70 p++; 71 if (*p) 72 *q++ = *p++; 73 } else { 74 *q++ = tolower(*p++); 75 } 76 } 77 *q = '\0'; 78 } 79} 80 81static int parse_msg_id(const char *text) 82{ 83 int i; 84 85 prepare_msg_ids(); 86 87 for (i = 0; i < FSCK_MSG_MAX; i++) 88 if (!strcmp(text, msg_id_info[i].downcased)) 89 return i; 90 91 return -1; 92} 93 94void list_config_fsck_msg_ids(struct string_list *list, const char *prefix) 95{ 96 int i; 97 98 prepare_msg_ids(); 99 100 for (i = 0; i < FSCK_MSG_MAX; i++) 101 list_config_item(list, prefix, msg_id_info[i].camelcased); 102} 103 104static enum fsck_msg_type fsck_msg_type(enum fsck_msg_id msg_id, 105 struct fsck_options *options) 106{ 107 assert(msg_id >= 0 && msg_id < FSCK_MSG_MAX); 108 109 if (!options->msg_type) { 110 enum fsck_msg_type msg_type = msg_id_info[msg_id].msg_type; 111 112 if (options->strict && msg_type == FSCK_WARN) 113 msg_type = FSCK_ERROR; 114 return msg_type; 115 } 116 117 return options->msg_type[msg_id]; 118} 119 120static enum fsck_msg_type parse_msg_type(const char *str) 121{ 122 if (!strcmp(str, "error")) 123 return FSCK_ERROR; 124 else if (!strcmp(str, "warn")) 125 return FSCK_WARN; 126 else if (!strcmp(str, "ignore")) 127 return FSCK_IGNORE; 128 else 129 die("Unknown fsck message type: '%s'", str); 130} 131 132int is_valid_msg_type(const char *msg_id, const char *msg_type) 133{ 134 if (parse_msg_id(msg_id) < 0) 135 return 0; 136 parse_msg_type(msg_type); 137 return 1; 138} 139 140void fsck_set_msg_type_from_ids(struct fsck_options *options, 141 enum fsck_msg_id msg_id, 142 enum fsck_msg_type msg_type) 143{ 144 if (!options->msg_type) { 145 int i; 146 enum fsck_msg_type *severity; 147 ALLOC_ARRAY(severity, FSCK_MSG_MAX); 148 for (i = 0; i < FSCK_MSG_MAX; i++) 149 severity[i] = fsck_msg_type(i, options); 150 options->msg_type = severity; 151 } 152 153 options->msg_type[msg_id] = msg_type; 154} 155 156void fsck_set_msg_type(struct fsck_options *options, 157 const char *msg_id_str, const char *msg_type_str) 158{ 159 int msg_id = parse_msg_id(msg_id_str); 160 char *to_free = NULL; 161 enum fsck_msg_type msg_type; 162 163 if (msg_id < 0) 164 die("Unhandled message id: %s", msg_id_str); 165 166 if (msg_id == FSCK_MSG_LARGE_PATHNAME) { 167 const char *colon = strchr(msg_type_str, ':'); 168 if (colon) { 169 msg_type_str = to_free = 170 xmemdupz(msg_type_str, colon - msg_type_str); 171 colon++; 172 if (!git_parse_ssize_t(colon, &max_tree_entry_len)) 173 die("unable to parse max tree entry len: %s", colon); 174 } 175 } 176 msg_type = parse_msg_type(msg_type_str); 177 178 if (msg_type != FSCK_ERROR && msg_id_info[msg_id].msg_type == FSCK_FATAL) 179 die("Cannot demote %s to %s", msg_id_str, msg_type_str); 180 181 fsck_set_msg_type_from_ids(options, msg_id, msg_type); 182 free(to_free); 183} 184 185void fsck_set_msg_types(struct fsck_options *options, const char *values) 186{ 187 char *buf = xstrdup(values), *to_free = buf; 188 int done = 0; 189 190 while (!done) { 191 int len = strcspn(buf, " ,|"), equal; 192 193 done = !buf[len]; 194 if (!len) { 195 buf++; 196 continue; 197 } 198 buf[len] = '\0'; 199 200 for (equal = 0; 201 equal < len && buf[equal] != '=' && buf[equal] != ':'; 202 equal++) 203 buf[equal] = tolower(buf[equal]); 204 buf[equal] = '\0'; 205 206 if (!strcmp(buf, "skiplist")) { 207 if (equal == len) 208 die("skiplist requires a path"); 209 oidset_parse_file(&options->skip_oids, buf + equal + 1, 210 the_repository->hash_algo); 211 buf += len + 1; 212 continue; 213 } 214 215 if (equal == len) 216 die("Missing '=': '%s'", buf); 217 218 fsck_set_msg_type(options, buf, buf + equal + 1); 219 buf += len + 1; 220 } 221 free(to_free); 222} 223 224static int object_on_skiplist(struct fsck_options *opts, 225 const struct object_id *oid) 226{ 227 return opts && oid && oidset_contains(&opts->skip_oids, oid); 228} 229 230/* 231 * Provide the common functionality for either fscking refs or objects. 232 * It will get the current msg error type and call the error_func callback 233 * which is registered in the "fsck_options" struct. 234 */ 235static int fsck_vreport(struct fsck_options *options, 236 void *fsck_report, 237 enum fsck_msg_id msg_id, const char *fmt, va_list ap) 238{ 239 struct strbuf sb = STRBUF_INIT; 240 enum fsck_msg_type msg_type = fsck_msg_type(msg_id, options); 241 int result; 242 243 if (msg_type == FSCK_IGNORE) 244 return 0; 245 246 if (msg_type == FSCK_FATAL) 247 msg_type = FSCK_ERROR; 248 else if (msg_type == FSCK_INFO) 249 msg_type = FSCK_WARN; 250 251 prepare_msg_ids(); 252 strbuf_addf(&sb, "%s: ", msg_id_info[msg_id].camelcased); 253 254 strbuf_vaddf(&sb, fmt, ap); 255 result = options->error_func(options, fsck_report, 256 msg_type, msg_id, sb.buf); 257 strbuf_release(&sb); 258 259 return result; 260} 261 262__attribute__((format (printf, 5, 6))) 263static int report(struct fsck_options *options, 264 const struct object_id *oid, enum object_type object_type, 265 enum fsck_msg_id msg_id, const char *fmt, ...) 266{ 267 va_list ap; 268 struct fsck_object_report report = { 269 .oid = oid, 270 .object_type = object_type 271 }; 272 int result; 273 274 if (object_on_skiplist(options, oid)) 275 return 0; 276 277 va_start(ap, fmt); 278 result = fsck_vreport(options, &report, msg_id, fmt, ap); 279 va_end(ap); 280 281 return result; 282} 283 284int fsck_report_ref(struct fsck_options *options, 285 struct fsck_ref_report *report, 286 enum fsck_msg_id msg_id, 287 const char *fmt, ...) 288{ 289 va_list ap; 290 int result; 291 va_start(ap, fmt); 292 result = fsck_vreport(options, report, msg_id, fmt, ap); 293 va_end(ap); 294 return result; 295} 296 297void fsck_enable_object_names(struct fsck_options *options) 298{ 299 if (!options->object_names) 300 options->object_names = kh_init_oid_map(); 301} 302 303const char *fsck_get_object_name(struct fsck_options *options, 304 const struct object_id *oid) 305{ 306 khiter_t pos; 307 if (!options->object_names) 308 return NULL; 309 pos = kh_get_oid_map(options->object_names, *oid); 310 if (pos >= kh_end(options->object_names)) 311 return NULL; 312 return kh_value(options->object_names, pos); 313} 314 315void fsck_put_object_name(struct fsck_options *options, 316 const struct object_id *oid, 317 const char *fmt, ...) 318{ 319 va_list ap; 320 struct strbuf buf = STRBUF_INIT; 321 khiter_t pos; 322 int hashret; 323 324 if (!options->object_names) 325 return; 326 327 pos = kh_put_oid_map(options->object_names, *oid, &hashret); 328 if (!hashret) 329 return; 330 va_start(ap, fmt); 331 strbuf_vaddf(&buf, fmt, ap); 332 kh_value(options->object_names, pos) = strbuf_detach(&buf, NULL); 333 va_end(ap); 334} 335 336const char *fsck_describe_object(struct fsck_options *options, 337 const struct object_id *oid) 338{ 339 static struct strbuf bufs[] = { 340 STRBUF_INIT, STRBUF_INIT, STRBUF_INIT, STRBUF_INIT 341 }; 342 static int b = 0; 343 struct strbuf *buf; 344 const char *name = fsck_get_object_name(options, oid); 345 346 buf = bufs + b; 347 b = (b + 1) % ARRAY_SIZE(bufs); 348 strbuf_reset(buf); 349 strbuf_addstr(buf, oid_to_hex(oid)); 350 if (name) 351 strbuf_addf(buf, " (%s)", name); 352 353 return buf->buf; 354} 355 356static int fsck_walk_tree(struct tree *tree, void *data, struct fsck_options *options) 357{ 358 struct tree_desc desc; 359 struct name_entry entry; 360 int res = 0; 361 const char *name; 362 363 if (parse_tree(tree)) 364 return -1; 365 366 name = fsck_get_object_name(options, &tree->object.oid); 367 if (init_tree_desc_gently(&desc, &tree->object.oid, 368 tree->buffer, tree->size, 0)) 369 return -1; 370 while (tree_entry_gently(&desc, &entry)) { 371 struct object *obj; 372 int result; 373 374 if (S_ISGITLINK(entry.mode)) 375 continue; 376 377 if (S_ISDIR(entry.mode)) { 378 obj = (struct object *)lookup_tree(the_repository, &entry.oid); 379 if (name && obj) 380 fsck_put_object_name(options, &entry.oid, "%s%s/", 381 name, entry.path); 382 result = options->walk(obj, OBJ_TREE, data, options); 383 } 384 else if (S_ISREG(entry.mode) || S_ISLNK(entry.mode)) { 385 obj = (struct object *)lookup_blob(the_repository, &entry.oid); 386 if (name && obj) 387 fsck_put_object_name(options, &entry.oid, "%s%s", 388 name, entry.path); 389 result = options->walk(obj, OBJ_BLOB, data, options); 390 } 391 else { 392 result = error("in tree %s: entry %s has bad mode %.6o", 393 fsck_describe_object(options, &tree->object.oid), 394 entry.path, entry.mode); 395 } 396 if (result < 0) 397 return result; 398 if (!res) 399 res = result; 400 } 401 return res; 402} 403 404static int fsck_walk_commit(struct commit *commit, void *data, struct fsck_options *options) 405{ 406 int counter = 0, generation = 0, name_prefix_len = 0; 407 struct commit_list *parents; 408 int res; 409 int result; 410 const char *name; 411 412 if (repo_parse_commit(the_repository, commit)) 413 return -1; 414 415 name = fsck_get_object_name(options, &commit->object.oid); 416 if (name) 417 fsck_put_object_name(options, get_commit_tree_oid(commit), 418 "%s:", name); 419 420 result = options->walk((struct object *) repo_get_commit_tree(the_repository, commit), 421 OBJ_TREE, data, options); 422 if (result < 0) 423 return result; 424 res = result; 425 426 parents = commit->parents; 427 if (name && parents) { 428 int len = strlen(name), power; 429 430 if (len && name[len - 1] == '^') { 431 generation = 1; 432 name_prefix_len = len - 1; 433 } 434 else { /* parse ~<generation> suffix */ 435 for (generation = 0, power = 1; 436 len && isdigit(name[len - 1]); 437 power *= 10) 438 generation += power * (name[--len] - '0'); 439 if (power > 1 && len && name[len - 1] == '~') 440 name_prefix_len = len - 1; 441 else { 442 /* Maybe a non-first parent, e.g. HEAD^2 */ 443 generation = 0; 444 name_prefix_len = len; 445 } 446 } 447 } 448 449 while (parents) { 450 if (name) { 451 struct object_id *oid = &parents->item->object.oid; 452 453 if (counter++) 454 fsck_put_object_name(options, oid, "%s^%d", 455 name, counter); 456 else if (generation > 0) 457 fsck_put_object_name(options, oid, "%.*s~%d", 458 name_prefix_len, name, 459 generation + 1); 460 else 461 fsck_put_object_name(options, oid, "%s^", name); 462 } 463 result = options->walk((struct object *)parents->item, OBJ_COMMIT, data, options); 464 if (result < 0) 465 return result; 466 if (!res) 467 res = result; 468 parents = parents->next; 469 } 470 return res; 471} 472 473static int fsck_walk_tag(struct tag *tag, void *data, struct fsck_options *options) 474{ 475 const char *name = fsck_get_object_name(options, &tag->object.oid); 476 477 if (parse_tag(tag)) 478 return -1; 479 if (name) 480 fsck_put_object_name(options, &tag->tagged->oid, "%s", name); 481 return options->walk(tag->tagged, OBJ_ANY, data, options); 482} 483 484int fsck_walk(struct object *obj, void *data, struct fsck_options *options) 485{ 486 if (!obj) 487 return -1; 488 489 if (obj->type == OBJ_NONE) 490 parse_object(the_repository, &obj->oid); 491 492 switch (obj->type) { 493 case OBJ_BLOB: 494 return 0; 495 case OBJ_TREE: 496 return fsck_walk_tree((struct tree *)obj, data, options); 497 case OBJ_COMMIT: 498 return fsck_walk_commit((struct commit *)obj, data, options); 499 case OBJ_TAG: 500 return fsck_walk_tag((struct tag *)obj, data, options); 501 default: 502 error("Unknown object type for %s", 503 fsck_describe_object(options, &obj->oid)); 504 return -1; 505 } 506} 507 508struct name_stack { 509 const char **names; 510 size_t nr, alloc; 511}; 512 513static void name_stack_push(struct name_stack *stack, const char *name) 514{ 515 ALLOC_GROW(stack->names, stack->nr + 1, stack->alloc); 516 stack->names[stack->nr++] = name; 517} 518 519static const char *name_stack_pop(struct name_stack *stack) 520{ 521 return stack->nr ? stack->names[--stack->nr] : NULL; 522} 523 524static void name_stack_clear(struct name_stack *stack) 525{ 526 FREE_AND_NULL(stack->names); 527 stack->nr = stack->alloc = 0; 528} 529 530/* 531 * The entries in a tree are ordered in the _path_ order, 532 * which means that a directory entry is ordered by adding 533 * a slash to the end of it. 534 * 535 * So a directory called "a" is ordered _after_ a file 536 * called "a.c", because "a/" sorts after "a.c". 537 */ 538#define TREE_UNORDERED (-1) 539#define TREE_HAS_DUPS (-2) 540 541static int is_less_than_slash(unsigned char c) 542{ 543 return '\0' < c && c < '/'; 544} 545 546static int verify_ordered(unsigned mode1, const char *name1, 547 unsigned mode2, const char *name2, 548 struct name_stack *candidates) 549{ 550 int len1 = strlen(name1); 551 int len2 = strlen(name2); 552 int len = len1 < len2 ? len1 : len2; 553 unsigned char c1, c2; 554 int cmp; 555 556 cmp = memcmp(name1, name2, len); 557 if (cmp < 0) 558 return 0; 559 if (cmp > 0) 560 return TREE_UNORDERED; 561 562 /* 563 * Ok, the first <len> characters are the same. 564 * Now we need to order the next one, but turn 565 * a '\0' into a '/' for a directory entry. 566 */ 567 c1 = name1[len]; 568 c2 = name2[len]; 569 if (!c1 && !c2) 570 /* 571 * git-write-tree used to write out a nonsense tree that has 572 * entries with the same name, one blob and one tree. Make 573 * sure we do not have duplicate entries. 574 */ 575 return TREE_HAS_DUPS; 576 if (!c1 && S_ISDIR(mode1)) 577 c1 = '/'; 578 if (!c2 && S_ISDIR(mode2)) 579 c2 = '/'; 580 581 /* 582 * There can be non-consecutive duplicates due to the implicitly 583 * added slash, e.g.: 584 * 585 * foo 586 * foo.bar 587 * foo.bar.baz 588 * foo.bar/ 589 * foo/ 590 * 591 * Record non-directory candidates (like "foo" and "foo.bar" in 592 * the example) on a stack and check directory candidates (like 593 * foo/" and "foo.bar/") against that stack. 594 */ 595 if (!c1 && is_less_than_slash(c2)) { 596 name_stack_push(candidates, name1); 597 } else if (c2 == '/' && is_less_than_slash(c1)) { 598 for (;;) { 599 const char *p; 600 const char *f_name = name_stack_pop(candidates); 601 602 if (!f_name) 603 break; 604 if (!skip_prefix(name2, f_name, &p)) 605 continue; 606 if (!*p) 607 return TREE_HAS_DUPS; 608 if (is_less_than_slash(*p)) { 609 name_stack_push(candidates, f_name); 610 break; 611 } 612 } 613 } 614 615 return c1 < c2 ? 0 : TREE_UNORDERED; 616} 617 618static int fsck_tree(const struct object_id *tree_oid, 619 const char *buffer, unsigned long size, 620 struct fsck_options *options) 621{ 622 int retval = 0; 623 int has_null_sha1 = 0; 624 int has_full_path = 0; 625 int has_empty_name = 0; 626 int has_dot = 0; 627 int has_dotdot = 0; 628 int has_dotgit = 0; 629 int has_zero_pad = 0; 630 int has_bad_modes = 0; 631 int has_dup_entries = 0; 632 int not_properly_sorted = 0; 633 int has_large_name = 0; 634 struct tree_desc desc; 635 unsigned o_mode; 636 const char *o_name; 637 struct name_stack df_dup_candidates = { NULL }; 638 639 if (init_tree_desc_gently(&desc, tree_oid, buffer, size, 640 TREE_DESC_RAW_MODES)) { 641 retval += report(options, tree_oid, OBJ_TREE, 642 FSCK_MSG_BAD_TREE, 643 "cannot be parsed as a tree"); 644 return retval; 645 } 646 647 o_mode = 0; 648 o_name = NULL; 649 650 while (desc.size) { 651 unsigned short mode; 652 const char *name, *backslash; 653 const struct object_id *entry_oid; 654 655 entry_oid = tree_entry_extract(&desc, &name, &mode); 656 657 has_null_sha1 |= is_null_oid(entry_oid); 658 has_full_path |= !!strchr(name, '/'); 659 has_empty_name |= !*name; 660 has_dot |= !strcmp(name, "."); 661 has_dotdot |= !strcmp(name, ".."); 662 has_dotgit |= is_hfs_dotgit(name) || is_ntfs_dotgit(name); 663 has_zero_pad |= *(char *)desc.buffer == '0'; 664 has_large_name |= tree_entry_len(&desc.entry) > max_tree_entry_len; 665 666 if (is_hfs_dotgitmodules(name) || is_ntfs_dotgitmodules(name)) { 667 if (!S_ISLNK(mode)) 668 oidset_insert(&options->gitmodules_found, 669 entry_oid); 670 else 671 retval += report(options, 672 tree_oid, OBJ_TREE, 673 FSCK_MSG_GITMODULES_SYMLINK, 674 ".gitmodules is a symbolic link"); 675 } 676 677 if (is_hfs_dotgitattributes(name) || is_ntfs_dotgitattributes(name)) { 678 if (!S_ISLNK(mode)) 679 oidset_insert(&options->gitattributes_found, 680 entry_oid); 681 else 682 retval += report(options, tree_oid, OBJ_TREE, 683 FSCK_MSG_GITATTRIBUTES_SYMLINK, 684 ".gitattributes is a symlink"); 685 } 686 687 if (S_ISLNK(mode)) { 688 if (is_hfs_dotgitignore(name) || 689 is_ntfs_dotgitignore(name)) 690 retval += report(options, tree_oid, OBJ_TREE, 691 FSCK_MSG_GITIGNORE_SYMLINK, 692 ".gitignore is a symlink"); 693 if (is_hfs_dotmailmap(name) || 694 is_ntfs_dotmailmap(name)) 695 retval += report(options, tree_oid, OBJ_TREE, 696 FSCK_MSG_MAILMAP_SYMLINK, 697 ".mailmap is a symlink"); 698 } 699 700 if ((backslash = strchr(name, '\\'))) { 701 while (backslash) { 702 backslash++; 703 has_dotgit |= is_ntfs_dotgit(backslash); 704 if (is_ntfs_dotgitmodules(backslash)) { 705 if (!S_ISLNK(mode)) 706 oidset_insert(&options->gitmodules_found, 707 entry_oid); 708 else 709 retval += report(options, tree_oid, OBJ_TREE, 710 FSCK_MSG_GITMODULES_SYMLINK, 711 ".gitmodules is a symbolic link"); 712 } 713 backslash = strchr(backslash, '\\'); 714 } 715 } 716 717 if (update_tree_entry_gently(&desc)) { 718 retval += report(options, tree_oid, OBJ_TREE, 719 FSCK_MSG_BAD_TREE, 720 "cannot be parsed as a tree"); 721 break; 722 } 723 724 switch (mode) { 725 /* 726 * Standard modes.. 727 */ 728 case S_IFREG | 0755: 729 case S_IFREG | 0644: 730 case S_IFLNK: 731 case S_IFDIR: 732 case S_IFGITLINK: 733 break; 734 /* 735 * This is nonstandard, but we had a few of these 736 * early on when we honored the full set of mode 737 * bits.. 738 */ 739 case S_IFREG | 0664: 740 if (!options->strict) 741 break; 742 /* fallthrough */ 743 default: 744 has_bad_modes = 1; 745 } 746 747 if (o_name) { 748 switch (verify_ordered(o_mode, o_name, mode, name, 749 &df_dup_candidates)) { 750 case TREE_UNORDERED: 751 not_properly_sorted = 1; 752 break; 753 case TREE_HAS_DUPS: 754 has_dup_entries = 1; 755 break; 756 default: 757 break; 758 } 759 } 760 761 o_mode = mode; 762 o_name = name; 763 } 764 765 name_stack_clear(&df_dup_candidates); 766 767 if (has_null_sha1) 768 retval += report(options, tree_oid, OBJ_TREE, 769 FSCK_MSG_NULL_SHA1, 770 "contains entries pointing to null sha1"); 771 if (has_full_path) 772 retval += report(options, tree_oid, OBJ_TREE, 773 FSCK_MSG_FULL_PATHNAME, 774 "contains full pathnames"); 775 if (has_empty_name) 776 retval += report(options, tree_oid, OBJ_TREE, 777 FSCK_MSG_EMPTY_NAME, 778 "contains empty pathname"); 779 if (has_dot) 780 retval += report(options, tree_oid, OBJ_TREE, 781 FSCK_MSG_HAS_DOT, 782 "contains '.'"); 783 if (has_dotdot) 784 retval += report(options, tree_oid, OBJ_TREE, 785 FSCK_MSG_HAS_DOTDOT, 786 "contains '..'"); 787 if (has_dotgit) 788 retval += report(options, tree_oid, OBJ_TREE, 789 FSCK_MSG_HAS_DOTGIT, 790 "contains '.git'"); 791 if (has_zero_pad) 792 retval += report(options, tree_oid, OBJ_TREE, 793 FSCK_MSG_ZERO_PADDED_FILEMODE, 794 "contains zero-padded file modes"); 795 if (has_bad_modes) 796 retval += report(options, tree_oid, OBJ_TREE, 797 FSCK_MSG_BAD_FILEMODE, 798 "contains bad file modes"); 799 if (has_dup_entries) 800 retval += report(options, tree_oid, OBJ_TREE, 801 FSCK_MSG_DUPLICATE_ENTRIES, 802 "contains duplicate file entries"); 803 if (not_properly_sorted) 804 retval += report(options, tree_oid, OBJ_TREE, 805 FSCK_MSG_TREE_NOT_SORTED, 806 "not properly sorted"); 807 if (has_large_name) 808 retval += report(options, tree_oid, OBJ_TREE, 809 FSCK_MSG_LARGE_PATHNAME, 810 "contains excessively large pathname"); 811 return retval; 812} 813 814/* 815 * Confirm that the headers of a commit or tag object end in a reasonable way, 816 * either with the usual "\n\n" separator, or at least with a trailing newline 817 * on the final header line. 818 * 819 * This property is important for the memory safety of our callers. It allows 820 * them to scan the buffer linewise without constantly checking the remaining 821 * size as long as: 822 * 823 * - they check that there are bytes left in the buffer at the start of any 824 * line (i.e., that the last newline they saw was not the final one we 825 * found here) 826 * 827 * - any intra-line scanning they do will stop at a newline, which will worst 828 * case hit the newline we found here as the end-of-header. This makes it 829 * OK for them to use helpers like parse_oid_hex(), or even skip_prefix(). 830 */ 831static int verify_headers(const void *data, unsigned long size, 832 const struct object_id *oid, enum object_type type, 833 struct fsck_options *options) 834{ 835 const char *buffer = (const char *)data; 836 unsigned long i; 837 838 for (i = 0; i < size; i++) { 839 switch (buffer[i]) { 840 case '\0': 841 return report(options, oid, type, 842 FSCK_MSG_NUL_IN_HEADER, 843 "unterminated header: NUL at offset %ld", i); 844 case '\n': 845 if (i + 1 < size && buffer[i + 1] == '\n') 846 return 0; 847 } 848 } 849 850 /* 851 * We did not find double-LF that separates the header 852 * and the body. Not having a body is not a crime but 853 * we do want to see the terminating LF for the last header 854 * line. 855 */ 856 if (size && buffer[size - 1] == '\n') 857 return 0; 858 859 return report(options, oid, type, 860 FSCK_MSG_UNTERMINATED_HEADER, "unterminated header"); 861} 862 863static int fsck_ident(const char **ident, 864 const struct object_id *oid, enum object_type type, 865 struct fsck_options *options) 866{ 867 const char *p = *ident; 868 char *end; 869 870 *ident = strchrnul(*ident, '\n'); 871 if (**ident == '\n') 872 (*ident)++; 873 874 if (*p == '<') 875 return report(options, oid, type, FSCK_MSG_MISSING_NAME_BEFORE_EMAIL, "invalid author/committer line - missing space before email"); 876 p += strcspn(p, "<>\n"); 877 if (*p == '>') 878 return report(options, oid, type, FSCK_MSG_BAD_NAME, "invalid author/committer line - bad name"); 879 if (*p != '<') 880 return report(options, oid, type, FSCK_MSG_MISSING_EMAIL, "invalid author/committer line - missing email"); 881 if (p[-1] != ' ') 882 return report(options, oid, type, FSCK_MSG_MISSING_SPACE_BEFORE_EMAIL, "invalid author/committer line - missing space before email"); 883 p++; 884 p += strcspn(p, "<>\n"); 885 if (*p != '>') 886 return report(options, oid, type, FSCK_MSG_BAD_EMAIL, "invalid author/committer line - bad email"); 887 p++; 888 if (*p != ' ') 889 return report(options, oid, type, FSCK_MSG_MISSING_SPACE_BEFORE_DATE, "invalid author/committer line - missing space before date"); 890 p++; 891 /* 892 * Our timestamp parser is based on the C strto*() functions, which 893 * will happily eat whitespace, including the newline that is supposed 894 * to prevent us walking past the end of the buffer. So do our own 895 * scan, skipping linear whitespace but not newlines, and then 896 * confirming we found a digit. We _could_ be even more strict here, 897 * as we really expect only a single space, but since we have 898 * traditionally allowed extra whitespace, we'll continue to do so. 899 */ 900 while (*p == ' ' || *p == '\t') 901 p++; 902 if (!isdigit(*p)) 903 return report(options, oid, type, FSCK_MSG_BAD_DATE, 904 "invalid author/committer line - bad date"); 905 if (*p == '0' && p[1] != ' ') 906 return report(options, oid, type, FSCK_MSG_ZERO_PADDED_DATE, "invalid author/committer line - zero-padded date"); 907 if (date_overflows(parse_timestamp(p, &end, 10))) 908 return report(options, oid, type, FSCK_MSG_BAD_DATE_OVERFLOW, "invalid author/committer line - date causes integer overflow"); 909 if ((end == p || *end != ' ')) 910 return report(options, oid, type, FSCK_MSG_BAD_DATE, "invalid author/committer line - bad date"); 911 p = end + 1; 912 if ((*p != '+' && *p != '-') || 913 !isdigit(p[1]) || 914 !isdigit(p[2]) || 915 !isdigit(p[3]) || 916 !isdigit(p[4]) || 917 (p[5] != '\n')) 918 return report(options, oid, type, FSCK_MSG_BAD_TIMEZONE, "invalid author/committer line - bad time zone"); 919 p += 6; 920 return 0; 921} 922 923static int fsck_commit(const struct object_id *oid, 924 const char *buffer, unsigned long size, 925 struct fsck_options *options) 926{ 927 struct object_id tree_oid, parent_oid; 928 unsigned author_count; 929 int err; 930 const char *buffer_begin = buffer; 931 const char *buffer_end = buffer + size; 932 const char *p; 933 934 /* 935 * We _must_ stop parsing immediately if this reports failure, as the 936 * memory safety of the rest of the function depends on it. See the 937 * comment above the definition of verify_headers() for more details. 938 */ 939 if (verify_headers(buffer, size, oid, OBJ_COMMIT, options)) 940 return -1; 941 942 if (buffer >= buffer_end || !skip_prefix(buffer, "tree ", &buffer)) 943 return report(options, oid, OBJ_COMMIT, FSCK_MSG_MISSING_TREE, "invalid format - expected 'tree' line"); 944 if (parse_oid_hex(buffer, &tree_oid, &p) || *p != '\n') { 945 err = report(options, oid, OBJ_COMMIT, FSCK_MSG_BAD_TREE_SHA1, "invalid 'tree' line format - bad sha1"); 946 if (err) 947 return err; 948 } 949 buffer = p + 1; 950 while (buffer < buffer_end && skip_prefix(buffer, "parent ", &buffer)) { 951 if (parse_oid_hex(buffer, &parent_oid, &p) || *p != '\n') { 952 err = report(options, oid, OBJ_COMMIT, FSCK_MSG_BAD_PARENT_SHA1, "invalid 'parent' line format - bad sha1"); 953 if (err) 954 return err; 955 } 956 buffer = p + 1; 957 } 958 author_count = 0; 959 while (buffer < buffer_end && skip_prefix(buffer, "author ", &buffer)) { 960 author_count++; 961 err = fsck_ident(&buffer, oid, OBJ_COMMIT, options); 962 if (err) 963 return err; 964 } 965 if (author_count < 1) 966 err = report(options, oid, OBJ_COMMIT, FSCK_MSG_MISSING_AUTHOR, "invalid format - expected 'author' line"); 967 else if (author_count > 1) 968 err = report(options, oid, OBJ_COMMIT, FSCK_MSG_MULTIPLE_AUTHORS, "invalid format - multiple 'author' lines"); 969 if (err) 970 return err; 971 if (buffer >= buffer_end || !skip_prefix(buffer, "committer ", &buffer)) 972 return report(options, oid, OBJ_COMMIT, FSCK_MSG_MISSING_COMMITTER, "invalid format - expected 'committer' line"); 973 err = fsck_ident(&buffer, oid, OBJ_COMMIT, options); 974 if (err) 975 return err; 976 if (memchr(buffer_begin, '\0', size)) { 977 err = report(options, oid, OBJ_COMMIT, FSCK_MSG_NUL_IN_COMMIT, 978 "NUL byte in the commit object body"); 979 if (err) 980 return err; 981 } 982 return 0; 983} 984 985static int fsck_tag(const struct object_id *oid, const char *buffer, 986 unsigned long size, struct fsck_options *options) 987{ 988 struct object_id tagged_oid; 989 int tagged_type; 990 return fsck_tag_standalone(oid, buffer, size, options, &tagged_oid, 991 &tagged_type); 992} 993 994int fsck_tag_standalone(const struct object_id *oid, const char *buffer, 995 unsigned long size, struct fsck_options *options, 996 struct object_id *tagged_oid, 997 int *tagged_type) 998{ 999 int ret = 0; 1000 char *eol; 1001 struct strbuf sb = STRBUF_INIT; 1002 const char *buffer_end = buffer + size; 1003 const char *p; 1004 1005 /* 1006 * We _must_ stop parsing immediately if this reports failure, as the 1007 * memory safety of the rest of the function depends on it. See the 1008 * comment above the definition of verify_headers() for more details. 1009 */ 1010 ret = verify_headers(buffer, size, oid, OBJ_TAG, options); 1011 if (ret) 1012 goto done; 1013 1014 if (buffer >= buffer_end || !skip_prefix(buffer, "object ", &buffer)) { 1015 ret = report(options, oid, OBJ_TAG, FSCK_MSG_MISSING_OBJECT, "invalid format - expected 'object' line"); 1016 goto done; 1017 } 1018 if (parse_oid_hex(buffer, tagged_oid, &p) || *p != '\n') { 1019 ret = report(options, oid, OBJ_TAG, FSCK_MSG_BAD_OBJECT_SHA1, "invalid 'object' line format - bad sha1"); 1020 if (ret) 1021 goto done; 1022 } 1023 buffer = p + 1; 1024 1025 if (buffer >= buffer_end || !skip_prefix(buffer, "type ", &buffer)) { 1026 ret = report(options, oid, OBJ_TAG, FSCK_MSG_MISSING_TYPE_ENTRY, "invalid format - expected 'type' line"); 1027 goto done; 1028 } 1029 eol = memchr(buffer, '\n', buffer_end - buffer); 1030 if (!eol) { 1031 ret = report(options, oid, OBJ_TAG, FSCK_MSG_MISSING_TYPE, "invalid format - unexpected end after 'type' line"); 1032 goto done; 1033 } 1034 *tagged_type = type_from_string_gently(buffer, eol - buffer, 1); 1035 if (*tagged_type < 0) 1036 ret = report(options, oid, OBJ_TAG, FSCK_MSG_BAD_TYPE, "invalid 'type' value"); 1037 if (ret) 1038 goto done; 1039 buffer = eol + 1; 1040 1041 if (buffer >= buffer_end || !skip_prefix(buffer, "tag ", &buffer)) { 1042 ret = report(options, oid, OBJ_TAG, FSCK_MSG_MISSING_TAG_ENTRY, "invalid format - expected 'tag' line"); 1043 goto done; 1044 } 1045 eol = memchr(buffer, '\n', buffer_end - buffer); 1046 if (!eol) { 1047 ret = report(options, oid, OBJ_TAG, FSCK_MSG_MISSING_TAG, "invalid format - unexpected end after 'type' line"); 1048 goto done; 1049 } 1050 strbuf_addf(&sb, "refs/tags/%.*s", (int)(eol - buffer), buffer); 1051 if (check_refname_format(sb.buf, 0)) { 1052 ret = report(options, oid, OBJ_TAG, 1053 FSCK_MSG_BAD_TAG_NAME, 1054 "invalid 'tag' name: %.*s", 1055 (int)(eol - buffer), buffer); 1056 if (ret) 1057 goto done; 1058 } 1059 buffer = eol + 1; 1060 1061 if (buffer >= buffer_end || !skip_prefix(buffer, "tagger ", &buffer)) { 1062 /* early tags do not contain 'tagger' lines; warn only */ 1063 ret = report(options, oid, OBJ_TAG, FSCK_MSG_MISSING_TAGGER_ENTRY, "invalid format - expected 'tagger' line"); 1064 if (ret) 1065 goto done; 1066 } 1067 else 1068 ret = fsck_ident(&buffer, oid, OBJ_TAG, options); 1069 1070 if (buffer < buffer_end && (skip_prefix(buffer, "gpgsig ", &buffer) || skip_prefix(buffer, "gpgsig-sha256 ", &buffer))) { 1071 eol = memchr(buffer, '\n', buffer_end - buffer); 1072 if (!eol) { 1073 ret = report(options, oid, OBJ_TAG, FSCK_MSG_BAD_GPGSIG, "invalid format - unexpected end after 'gpgsig' or 'gpgsig-sha256' line"); 1074 goto done; 1075 } 1076 buffer = eol + 1; 1077 1078 while (buffer < buffer_end && starts_with(buffer, " ")) { 1079 eol = memchr(buffer, '\n', buffer_end - buffer); 1080 if (!eol) { 1081 ret = report(options, oid, OBJ_TAG, FSCK_MSG_BAD_HEADER_CONTINUATION, "invalid format - unexpected end in 'gpgsig' or 'gpgsig-sha256' continuation line"); 1082 goto done; 1083 } 1084 buffer = eol + 1; 1085 } 1086 } 1087 1088 if (buffer < buffer_end && !starts_with(buffer, "\n")) { 1089 /* 1090 * The verify_headers() check will allow 1091 * e.g. "[...]tagger <tagger>\nsome 1092 * garbage\n\nmessage" to pass, thinking "some 1093 * garbage" could be a custom header. E.g. "mktag" 1094 * doesn't want any unknown headers. 1095 */ 1096 ret = report(options, oid, OBJ_TAG, FSCK_MSG_EXTRA_HEADER_ENTRY, "invalid format - extra header(s) after 'tagger'"); 1097 if (ret) 1098 goto done; 1099 } 1100 1101done: 1102 strbuf_release(&sb); 1103 return ret; 1104} 1105 1106struct fsck_gitmodules_data { 1107 const struct object_id *oid; 1108 struct fsck_options *options; 1109 int ret; 1110}; 1111 1112static int fsck_gitmodules_fn(const char *var, const char *value, 1113 const struct config_context *ctx UNUSED, 1114 void *vdata) 1115{ 1116 struct fsck_gitmodules_data *data = vdata; 1117 const char *subsection, *key; 1118 size_t subsection_len; 1119 char *name; 1120 1121 if (parse_config_key(var, "submodule", &subsection, &subsection_len, &key) < 0 || 1122 !subsection) 1123 return 0; 1124 1125 name = xmemdupz(subsection, subsection_len); 1126 if (check_submodule_name(name) < 0) 1127 data->ret |= report(data->options, 1128 data->oid, OBJ_BLOB, 1129 FSCK_MSG_GITMODULES_NAME, 1130 "disallowed submodule name: %s", 1131 name); 1132 if (!strcmp(key, "url") && value && 1133 check_submodule_url(value) < 0) 1134 data->ret |= report(data->options, 1135 data->oid, OBJ_BLOB, 1136 FSCK_MSG_GITMODULES_URL, 1137 "disallowed submodule url: %s", 1138 value); 1139 if (!strcmp(key, "path") && value && 1140 looks_like_command_line_option(value)) 1141 data->ret |= report(data->options, 1142 data->oid, OBJ_BLOB, 1143 FSCK_MSG_GITMODULES_PATH, 1144 "disallowed submodule path: %s", 1145 value); 1146 if (!strcmp(key, "update") && value && 1147 parse_submodule_update_type(value) == SM_UPDATE_COMMAND) 1148 data->ret |= report(data->options, data->oid, OBJ_BLOB, 1149 FSCK_MSG_GITMODULES_UPDATE, 1150 "disallowed submodule update setting: %s", 1151 value); 1152 free(name); 1153 1154 return 0; 1155} 1156 1157static int fsck_blob(const struct object_id *oid, const char *buf, 1158 unsigned long size, struct fsck_options *options) 1159{ 1160 int ret = 0; 1161 1162 if (object_on_skiplist(options, oid)) 1163 return 0; 1164 1165 if (oidset_contains(&options->gitmodules_found, oid)) { 1166 struct config_options config_opts = { 0 }; 1167 struct fsck_gitmodules_data data; 1168 1169 oidset_insert(&options->gitmodules_done, oid); 1170 1171 if (!buf) { 1172 /* 1173 * A missing buffer here is a sign that the caller found the 1174 * blob too gigantic to load into memory. Let's just consider 1175 * that an error. 1176 */ 1177 return report(options, oid, OBJ_BLOB, 1178 FSCK_MSG_GITMODULES_LARGE, 1179 ".gitmodules too large to parse"); 1180 } 1181 1182 data.oid = oid; 1183 data.options = options; 1184 data.ret = 0; 1185 config_opts.error_action = CONFIG_ERROR_SILENT; 1186 if (git_config_from_mem(fsck_gitmodules_fn, CONFIG_ORIGIN_BLOB, 1187 ".gitmodules", buf, size, &data, 1188 CONFIG_SCOPE_UNKNOWN, &config_opts)) 1189 data.ret |= report(options, oid, OBJ_BLOB, 1190 FSCK_MSG_GITMODULES_PARSE, 1191 "could not parse gitmodules blob"); 1192 ret |= data.ret; 1193 } 1194 1195 if (oidset_contains(&options->gitattributes_found, oid)) { 1196 const char *ptr; 1197 1198 oidset_insert(&options->gitattributes_done, oid); 1199 1200 if (!buf || size > ATTR_MAX_FILE_SIZE) { 1201 /* 1202 * A missing buffer here is a sign that the caller found the 1203 * blob too gigantic to load into memory. Let's just consider 1204 * that an error. 1205 */ 1206 return report(options, oid, OBJ_BLOB, 1207 FSCK_MSG_GITATTRIBUTES_LARGE, 1208 ".gitattributes too large to parse"); 1209 } 1210 1211 for (ptr = buf; *ptr; ) { 1212 const char *eol = strchrnul(ptr, '\n'); 1213 if (eol - ptr >= ATTR_MAX_LINE_LENGTH) { 1214 ret |= report(options, oid, OBJ_BLOB, 1215 FSCK_MSG_GITATTRIBUTES_LINE_LENGTH, 1216 ".gitattributes has too long lines to parse"); 1217 break; 1218 } 1219 1220 ptr = *eol ? eol + 1 : eol; 1221 } 1222 } 1223 1224 return ret; 1225} 1226 1227int fsck_object(struct object *obj, void *data, unsigned long size, 1228 struct fsck_options *options) 1229{ 1230 if (!obj) 1231 return report(options, NULL, OBJ_NONE, FSCK_MSG_BAD_OBJECT_SHA1, "no valid object to fsck"); 1232 1233 return fsck_buffer(&obj->oid, obj->type, data, size, options); 1234} 1235 1236int fsck_buffer(const struct object_id *oid, enum object_type type, 1237 const void *data, unsigned long size, 1238 struct fsck_options *options) 1239{ 1240 if (type == OBJ_BLOB) 1241 return fsck_blob(oid, data, size, options); 1242 if (type == OBJ_TREE) 1243 return fsck_tree(oid, data, size, options); 1244 if (type == OBJ_COMMIT) 1245 return fsck_commit(oid, data, size, options); 1246 if (type == OBJ_TAG) 1247 return fsck_tag(oid, data, size, options); 1248 1249 return report(options, oid, type, 1250 FSCK_MSG_UNKNOWN_TYPE, 1251 "unknown type '%d' (internal fsck error)", 1252 type); 1253} 1254 1255int fsck_objects_error_function(struct fsck_options *o, 1256 void *fsck_report, 1257 enum fsck_msg_type msg_type, 1258 enum fsck_msg_id msg_id UNUSED, 1259 const char *message) 1260{ 1261 struct fsck_object_report *report = fsck_report; 1262 const struct object_id *oid = report->oid; 1263 1264 if (msg_type == FSCK_WARN) { 1265 warning("object %s: %s", fsck_describe_object(o, oid), message); 1266 return 0; 1267 } 1268 error("object %s: %s", fsck_describe_object(o, oid), message); 1269 return 1; 1270} 1271 1272int fsck_refs_error_function(struct fsck_options *options UNUSED, 1273 void *fsck_report, 1274 enum fsck_msg_type msg_type, 1275 enum fsck_msg_id msg_id UNUSED, 1276 const char *message) 1277{ 1278 struct fsck_ref_report *report = fsck_report; 1279 struct strbuf sb = STRBUF_INIT; 1280 int ret = 0; 1281 1282 strbuf_addstr(&sb, report->path); 1283 1284 if (report->oid) 1285 strbuf_addf(&sb, " -> (%s)", oid_to_hex(report->oid)); 1286 else if (report->referent) 1287 strbuf_addf(&sb, " -> (%s)", report->referent); 1288 1289 if (msg_type == FSCK_WARN) 1290 warning("%s: %s", sb.buf, message); 1291 else 1292 ret = error("%s: %s", sb.buf, message); 1293 1294 strbuf_release(&sb); 1295 return ret; 1296} 1297 1298static int fsck_blobs(struct oidset *blobs_found, struct oidset *blobs_done, 1299 enum fsck_msg_id msg_missing, enum fsck_msg_id msg_type, 1300 struct fsck_options *options, const char *blob_type) 1301{ 1302 int ret = 0; 1303 struct oidset_iter iter; 1304 const struct object_id *oid; 1305 1306 oidset_iter_init(blobs_found, &iter); 1307 while ((oid = oidset_iter_next(&iter))) { 1308 enum object_type type; 1309 unsigned long size; 1310 char *buf; 1311 1312 if (oidset_contains(blobs_done, oid)) 1313 continue; 1314 1315 buf = odb_read_object(the_repository->objects, oid, &type, &size); 1316 if (!buf) { 1317 if (is_promisor_object(the_repository, oid)) 1318 continue; 1319 ret |= report(options, 1320 oid, OBJ_BLOB, msg_missing, 1321 "unable to read %s blob", blob_type); 1322 continue; 1323 } 1324 1325 if (type == OBJ_BLOB) 1326 ret |= fsck_blob(oid, buf, size, options); 1327 else 1328 ret |= report(options, oid, type, msg_type, 1329 "non-blob found at %s", blob_type); 1330 free(buf); 1331 } 1332 1333 oidset_clear(blobs_found); 1334 oidset_clear(blobs_done); 1335 1336 return ret; 1337} 1338 1339int fsck_finish(struct fsck_options *options) 1340{ 1341 int ret = 0; 1342 1343 ret |= fsck_blobs(&options->gitmodules_found, &options->gitmodules_done, 1344 FSCK_MSG_GITMODULES_MISSING, FSCK_MSG_GITMODULES_BLOB, 1345 options, ".gitmodules"); 1346 ret |= fsck_blobs(&options->gitattributes_found, &options->gitattributes_done, 1347 FSCK_MSG_GITATTRIBUTES_MISSING, FSCK_MSG_GITATTRIBUTES_BLOB, 1348 options, ".gitattributes"); 1349 1350 return ret; 1351} 1352 1353void fsck_options_clear(struct fsck_options *options) 1354{ 1355 free(options->msg_type); 1356 oidset_clear(&options->skip_oids); 1357 oidset_clear(&options->gitmodules_found); 1358 oidset_clear(&options->gitmodules_done); 1359 oidset_clear(&options->gitattributes_found); 1360 oidset_clear(&options->gitattributes_done); 1361 kh_clear_oid_map(options->object_names); 1362} 1363 1364int git_fsck_config(const char *var, const char *value, 1365 const struct config_context *ctx, void *cb) 1366{ 1367 struct fsck_options *options = cb; 1368 const char *msg_id; 1369 1370 if (strcmp(var, "fsck.skiplist") == 0) { 1371 char *path; 1372 struct strbuf sb = STRBUF_INIT; 1373 1374 if (git_config_pathname(&path, var, value)) 1375 return -1; 1376 strbuf_addf(&sb, "skiplist=%s", path); 1377 free(path); 1378 fsck_set_msg_types(options, sb.buf); 1379 strbuf_release(&sb); 1380 return 0; 1381 } 1382 1383 if (skip_prefix(var, "fsck.", &msg_id)) { 1384 if (!value) 1385 return config_error_nonbool(var); 1386 fsck_set_msg_type(options, msg_id, value); 1387 return 0; 1388 } 1389 1390 return git_default_config(var, value, ctx, cb); 1391} 1392 1393/* 1394 * Custom error callbacks that are used in more than one place. 1395 */ 1396 1397int fsck_objects_error_cb_print_missing_gitmodules(struct fsck_options *o, 1398 void *fsck_report, 1399 enum fsck_msg_type msg_type, 1400 enum fsck_msg_id msg_id, 1401 const char *message) 1402{ 1403 if (msg_id == FSCK_MSG_GITMODULES_MISSING) { 1404 struct fsck_object_report *report = fsck_report; 1405 puts(oid_to_hex(report->oid)); 1406 return 0; 1407 } 1408 return fsck_objects_error_function(o, fsck_report, 1409 msg_type, msg_id, message); 1410}