@matheusbsbs / matheus-bagliano / commits / 103fb6d43b
Fork 0

fsck: accept an oid instead of a "struct tag" for fsck_tag()

We don't actually look at the tag struct in fsck_tag() beyond its oid and type (which is obviously OBJ_TAG). Just taking an oid gives our callers more flexibility to avoid creating or parsing 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:01 UTC 103fb6d43bd6ec7049564cc39e4c0e495f9bfcb8
1 file changed +13 -14
fsck.c
+13 -14
@@ -820,7 +820,7 @@ static int fsck_commit(struct commit *commit, const char *buffer,
820 return 0;
821 }
822
823 -static int fsck_tag(struct tag *tag, const char *buffer,
823 +static int fsck_tag(const struct object_id *oid, const char *buffer,
824 unsigned long size, struct fsck_options *options)
825 {
826 struct object_id tagged_oid;
@@ -829,48 +829,48 @@ static int fsck_tag(struct tag *tag, const char *buffer,
829 struct strbuf sb = STRBUF_INIT;
830 const char *p;
831
832 - ret = verify_headers(buffer, size, &tag->object.oid, tag->object.type, options);
832 + ret = verify_headers(buffer, size, oid, OBJ_TAG, options);
833 if (ret)
834 goto done;
835
836 if (!skip_prefix(buffer, "object ", &buffer)) {
837 - ret = report(options, &tag->object.oid, tag->object.type, FSCK_MSG_MISSING_OBJECT, "invalid format - expected 'object' line");
837 + ret = report(options, oid, OBJ_TAG, FSCK_MSG_MISSING_OBJECT, "invalid format - expected 'object' line");
838 goto done;
839 }
840 if (parse_oid_hex(buffer, &tagged_oid, &p) || *p != '\n') {
841 - ret = report(options, &tag->object.oid, tag->object.type, FSCK_MSG_BAD_OBJECT_SHA1, "invalid 'object' line format - bad sha1");
841 + ret = report(options, oid, OBJ_TAG, FSCK_MSG_BAD_OBJECT_SHA1, "invalid 'object' line format - bad sha1");
842 if (ret)
843 goto done;
844 }
845 buffer = p + 1;
846
847 if (!skip_prefix(buffer, "type ", &buffer)) {
848 - ret = report(options, &tag->object.oid, tag->object.type, FSCK_MSG_MISSING_TYPE_ENTRY, "invalid format - expected 'type' line");
848 + ret = report(options, oid, OBJ_TAG, FSCK_MSG_MISSING_TYPE_ENTRY, "invalid format - expected 'type' line");
849 goto done;
850 }
851 eol = strchr(buffer, '\n');
852 if (!eol) {
853 - ret = report(options, &tag->object.oid, tag->object.type, FSCK_MSG_MISSING_TYPE, "invalid format - unexpected end after 'type' line");
853 + ret = report(options, oid, OBJ_TAG, FSCK_MSG_MISSING_TYPE, "invalid format - unexpected end after 'type' line");
854 goto done;
855 }
856 if (type_from_string_gently(buffer, eol - buffer, 1) < 0)
857 - ret = report(options, &tag->object.oid, tag->object.type, FSCK_MSG_BAD_TYPE, "invalid 'type' value");
857 + ret = report(options, oid, OBJ_TAG, FSCK_MSG_BAD_TYPE, "invalid 'type' value");
858 if (ret)
859 goto done;
860 buffer = eol + 1;
861
862 if (!skip_prefix(buffer, "tag ", &buffer)) {
863 - ret = report(options, &tag->object.oid, tag->object.type, FSCK_MSG_MISSING_TAG_ENTRY, "invalid format - expected 'tag' line");
863 + ret = report(options, oid, OBJ_TAG, FSCK_MSG_MISSING_TAG_ENTRY, "invalid format - expected 'tag' line");
864 goto done;
865 }
866 eol = strchr(buffer, '\n');
867 if (!eol) {
868 - ret = report(options, &tag->object.oid, tag->object.type, FSCK_MSG_MISSING_TAG, "invalid format - unexpected end after 'type' line");
868 + ret = report(options, oid, OBJ_TAG, FSCK_MSG_MISSING_TAG, "invalid format - unexpected end after 'type' line");
869 goto done;
870 }
871 strbuf_addf(&sb, "refs/tags/%.*s", (int)(eol - buffer), buffer);
872 if (check_refname_format(sb.buf, 0)) {
873 - ret = report(options, &tag->object.oid, tag->object.type,
873 + ret = report(options, oid, OBJ_TAG,
874 FSCK_MSG_BAD_TAG_NAME,
875 "invalid 'tag' name: %.*s",
876 (int)(eol - buffer), buffer);
@@ -881,12 +881,12 @@ static int fsck_tag(struct tag *tag, const char *buffer,
881
882 if (!skip_prefix(buffer, "tagger ", &buffer)) {
883 /* early tags do not contain 'tagger' lines; warn only */
884 - ret = report(options, &tag->object.oid, tag->object.type, FSCK_MSG_MISSING_TAGGER_ENTRY, "invalid format - expected 'tagger' line");
884 + ret = report(options, oid, OBJ_TAG, FSCK_MSG_MISSING_TAGGER_ENTRY, "invalid format - expected 'tagger' line");
885 if (ret)
886 goto done;
887 }
888 else
889 - ret = fsck_ident(&buffer, &tag->object.oid, tag->object.type, options);
889 + ret = fsck_ident(&buffer, oid, OBJ_TAG, options);
890
891 done:
892 strbuf_release(&sb);
@@ -987,8 +987,7 @@ int fsck_object(struct object *obj, void *data, unsigned long size,
987 return fsck_commit((struct commit *) obj, (const char *) data,
988 size, options);
989 if (obj->type == OBJ_TAG)
990 - return fsck_tag((struct tag *) obj, (const char *) data,
991 - size, options);
990 + return fsck_tag(&obj->oid, data, size, options);
991
992 return report(options, &obj->oid, obj->type,
993 FSCK_MSG_UNKNOWN_TYPE,