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

fsck: don't require an object struct in verify_headers()

We only need the oid and type to pass on to report(). Let's accept the broken-out parameters to give our callers more flexibility. 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:00 UTC cc579000bf289cea7f9c2e34fcb9cf67e8104616
1 file changed +7 -5
fsck.c
+7 -5
@@ -687,7 +687,8 @@ static int fsck_tree(struct tree *item,
687 }
688
689 static int verify_headers(const void *data, unsigned long size,
690 - struct object *obj, struct fsck_options *options)
690 + const struct object_id *oid, enum object_type type,
691 + struct fsck_options *options)
692 {
693 const char *buffer = (const char *)data;
694 unsigned long i;
@@ -695,7 +696,7 @@ static int verify_headers(const void *data, unsigned long size,
696 for (i = 0; i < size; i++) {
697 switch (buffer[i]) {
698 case '\0':
698 - return report(options, &obj->oid, obj->type,
699 + return report(options, oid, type,
700 FSCK_MSG_NUL_IN_HEADER,
701 "unterminated header: NUL at offset %ld", i);
702 case '\n':
@@ -713,7 +714,7 @@ static int verify_headers(const void *data, unsigned long size,
714 if (size && buffer[size - 1] == '\n')
715 return 0;
716
716 - return report(options, &obj->oid, obj->type,
717 + return report(options, oid, type,
718 FSCK_MSG_UNTERMINATED_HEADER, "unterminated header");
719 }
720
@@ -772,7 +773,8 @@ static int fsck_commit(struct commit *commit, const char *buffer,
773 const char *buffer_begin = buffer;
774 const char *p;
775
775 - if (verify_headers(buffer, size, &commit->object, options))
776 + if (verify_headers(buffer, size, &commit->object.oid,
777 + commit->object.type, options))
778 return -1;
779
780 if (!skip_prefix(buffer, "tree ", &buffer))
@@ -827,7 +829,7 @@ static int fsck_tag(struct tag *tag, const char *buffer,
829 struct strbuf sb = STRBUF_INIT;
830 const char *p;
831
830 - ret = verify_headers(buffer, size, &tag->object, options);
832 + ret = verify_headers(buffer, size, &tag->object.oid, tag->object.type, options);
833 if (ret)
834 goto done;
835