@matheusbsbs / matheus-bagliano / commits / b2f2039c2b
Fork 0

fsck: accept an oid instead of a "struct tree" for fsck_tree()

We don't actually look at the tree struct in fsck_tree() beyond its oid and type (which is obviously OBJ_TREE). Just taking an oid gives our callers more flexibility to avoid creating a struct, and makes it clear that we are fscking just what is in the buffer, not any pre-parsed bits from the struct. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Oct 18, 2019 at 01:02 UTC b2f2039c2b23ff2a417d404f205b9741870d4acd
1 file changed +15 -15
fsck.c
+15 -15
@@ -566,7 +566,7 @@ static int verify_ordered(unsigned mode1, const char *name1, unsigned mode2, con
566 return c1 < c2 ? 0 : TREE_UNORDERED;
567 }
568
569 -static int fsck_tree(struct tree *item,
569 +static int fsck_tree(const struct object_id *oid,
570 const char *buffer, unsigned long size,
571 struct fsck_options *options)
572 {
@@ -586,7 +586,7 @@ static int fsck_tree(struct tree *item,
586 const char *o_name;
587
588 if (init_tree_desc_gently(&desc, buffer, size)) {
589 - retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_BAD_TREE, "cannot be parsed as a tree");
589 + retval += report(options, oid, OBJ_TREE, FSCK_MSG_BAD_TREE, "cannot be parsed as a tree");
590 return retval;
591 }
592
@@ -613,13 +613,13 @@ static int fsck_tree(struct tree *item,
613 oidset_insert(&gitmodules_found, oid);
614 else
615 retval += report(options,
616 - &item->object.oid, item->object.type,
616 + oid, OBJ_TREE,
617 FSCK_MSG_GITMODULES_SYMLINK,
618 ".gitmodules is a symbolic link");
619 }
620
621 if (update_tree_entry_gently(&desc)) {
622 - retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_BAD_TREE, "cannot be parsed as a tree");
622 + retval += report(options, oid, OBJ_TREE, FSCK_MSG_BAD_TREE, "cannot be parsed as a tree");
623 break;
624 }
625
@@ -664,25 +664,25 @@ static int fsck_tree(struct tree *item,
664 }
665
666 if (has_null_sha1)
667 - retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_NULL_SHA1, "contains entries pointing to null sha1");
667 + retval += report(options, oid, OBJ_TREE, FSCK_MSG_NULL_SHA1, "contains entries pointing to null sha1");
668 if (has_full_path)
669 - retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_FULL_PATHNAME, "contains full pathnames");
669 + retval += report(options, oid, OBJ_TREE, FSCK_MSG_FULL_PATHNAME, "contains full pathnames");
670 if (has_empty_name)
671 - retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_EMPTY_NAME, "contains empty pathname");
671 + retval += report(options, oid, OBJ_TREE, FSCK_MSG_EMPTY_NAME, "contains empty pathname");
672 if (has_dot)
673 - retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_HAS_DOT, "contains '.'");
673 + retval += report(options, oid, OBJ_TREE, FSCK_MSG_HAS_DOT, "contains '.'");
674 if (has_dotdot)
675 - retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_HAS_DOTDOT, "contains '..'");
675 + retval += report(options, oid, OBJ_TREE, FSCK_MSG_HAS_DOTDOT, "contains '..'");
676 if (has_dotgit)
677 - retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_HAS_DOTGIT, "contains '.git'");
677 + retval += report(options, oid, OBJ_TREE, FSCK_MSG_HAS_DOTGIT, "contains '.git'");
678 if (has_zero_pad)
679 - retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_ZERO_PADDED_FILEMODE, "contains zero-padded file modes");
679 + retval += report(options, oid, OBJ_TREE, FSCK_MSG_ZERO_PADDED_FILEMODE, "contains zero-padded file modes");
680 if (has_bad_modes)
681 - retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_BAD_FILEMODE, "contains bad file modes");
681 + retval += report(options, oid, OBJ_TREE, FSCK_MSG_BAD_FILEMODE, "contains bad file modes");
682 if (has_dup_entries)
683 - retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_DUPLICATE_ENTRIES, "contains duplicate file entries");
683 + retval += report(options, oid, OBJ_TREE, FSCK_MSG_DUPLICATE_ENTRIES, "contains duplicate file entries");
684 if (not_properly_sorted)
685 - retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_TREE_NOT_SORTED, "not properly sorted");
685 + retval += report(options, oid, OBJ_TREE, FSCK_MSG_TREE_NOT_SORTED, "not properly sorted");
686 return retval;
687 }
688
@@ -982,7 +982,7 @@ int fsck_object(struct object *obj, void *data, unsigned long size,
982 if (obj->type == OBJ_BLOB)
983 return fsck_blob(&obj->oid, data, size, options);
984 if (obj->type == OBJ_TREE)
985 - return fsck_tree((struct tree *) obj, data, size, options);
985 + return fsck_tree(&obj->oid, data, size, options);
986 if (obj->type == OBJ_COMMIT)
987 return fsck_commit(&obj->oid, data, size, options);
988 if (obj->type == OBJ_TAG)