Skip to content

Commit 103fb6d

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f648ee7 commit 103fb6d

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

fsck.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ static int fsck_commit(struct commit *commit, const char *buffer,
820820
return 0;
821821
}
822822

823-
static int fsck_tag(struct tag *tag, const char *buffer,
823+
static int fsck_tag(const struct object_id *oid, const char *buffer,
824824
unsigned long size, struct fsck_options *options)
825825
{
826826
struct object_id tagged_oid;
@@ -829,48 +829,48 @@ static int fsck_tag(struct tag *tag, const char *buffer,
829829
struct strbuf sb = STRBUF_INIT;
830830
const char *p;
831831

832-
ret = verify_headers(buffer, size, &tag->object.oid, tag->object.type, options);
832+
ret = verify_headers(buffer, size, oid, OBJ_TAG, options);
833833
if (ret)
834834
goto done;
835835

836836
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");
838838
goto done;
839839
}
840840
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");
842842
if (ret)
843843
goto done;
844844
}
845845
buffer = p + 1;
846846

847847
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");
849849
goto done;
850850
}
851851
eol = strchr(buffer, '\n');
852852
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");
854854
goto done;
855855
}
856856
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");
858858
if (ret)
859859
goto done;
860860
buffer = eol + 1;
861861

862862
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");
864864
goto done;
865865
}
866866
eol = strchr(buffer, '\n');
867867
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");
869869
goto done;
870870
}
871871
strbuf_addf(&sb, "refs/tags/%.*s", (int)(eol - buffer), buffer);
872872
if (check_refname_format(sb.buf, 0)) {
873-
ret = report(options, &tag->object.oid, tag->object.type,
873+
ret = report(options, oid, OBJ_TAG,
874874
FSCK_MSG_BAD_TAG_NAME,
875875
"invalid 'tag' name: %.*s",
876876
(int)(eol - buffer), buffer);
@@ -881,12 +881,12 @@ static int fsck_tag(struct tag *tag, const char *buffer,
881881

882882
if (!skip_prefix(buffer, "tagger ", &buffer)) {
883883
/* 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");
885885
if (ret)
886886
goto done;
887887
}
888888
else
889-
ret = fsck_ident(&buffer, &tag->object.oid, tag->object.type, options);
889+
ret = fsck_ident(&buffer, oid, OBJ_TAG, options);
890890

891891
done:
892892
strbuf_release(&sb);
@@ -987,8 +987,7 @@ int fsck_object(struct object *obj, void *data, unsigned long size,
987987
return fsck_commit((struct commit *) obj, (const char *) data,
988988
size, options);
989989
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);
992991

993992
return report(options, &obj->oid, obj->type,
994993
FSCK_MSG_UNKNOWN_TYPE,

0 commit comments

Comments
 (0)