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>
maint
Jeff King 2019-10-18 01:01:26 -04:00 committed by Junio C Hamano
parent f648ee7088
commit 103fb6d43b
1 changed files with 13 additions and 14 deletions

27
fsck.c
View File

@ -820,7 +820,7 @@ static int fsck_commit(struct commit *commit, const char *buffer,
return 0; return 0;
} }


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


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


if (!skip_prefix(buffer, "object ", &buffer)) { if (!skip_prefix(buffer, "object ", &buffer)) {
ret = report(options, &tag->object.oid, tag->object.type, FSCK_MSG_MISSING_OBJECT, "invalid format - expected 'object' line"); ret = report(options, oid, OBJ_TAG, FSCK_MSG_MISSING_OBJECT, "invalid format - expected 'object' line");
goto done; goto done;
} }
if (parse_oid_hex(buffer, &tagged_oid, &p) || *p != '\n') { if (parse_oid_hex(buffer, &tagged_oid, &p) || *p != '\n') {
ret = report(options, &tag->object.oid, tag->object.type, FSCK_MSG_BAD_OBJECT_SHA1, "invalid 'object' line format - bad sha1"); ret = report(options, oid, OBJ_TAG, FSCK_MSG_BAD_OBJECT_SHA1, "invalid 'object' line format - bad sha1");
if (ret) if (ret)
goto done; goto done;
} }
buffer = p + 1; buffer = p + 1;


if (!skip_prefix(buffer, "type ", &buffer)) { if (!skip_prefix(buffer, "type ", &buffer)) {
ret = report(options, &tag->object.oid, tag->object.type, FSCK_MSG_MISSING_TYPE_ENTRY, "invalid format - expected 'type' line"); ret = report(options, oid, OBJ_TAG, FSCK_MSG_MISSING_TYPE_ENTRY, "invalid format - expected 'type' line");
goto done; goto done;
} }
eol = strchr(buffer, '\n'); eol = strchr(buffer, '\n');
if (!eol) { if (!eol) {
ret = report(options, &tag->object.oid, tag->object.type, FSCK_MSG_MISSING_TYPE, "invalid format - unexpected end after 'type' line"); ret = report(options, oid, OBJ_TAG, FSCK_MSG_MISSING_TYPE, "invalid format - unexpected end after 'type' line");
goto done; goto done;
} }
if (type_from_string_gently(buffer, eol - buffer, 1) < 0) if (type_from_string_gently(buffer, eol - buffer, 1) < 0)
ret = report(options, &tag->object.oid, tag->object.type, FSCK_MSG_BAD_TYPE, "invalid 'type' value"); ret = report(options, oid, OBJ_TAG, FSCK_MSG_BAD_TYPE, "invalid 'type' value");
if (ret) if (ret)
goto done; goto done;
buffer = eol + 1; buffer = eol + 1;


if (!skip_prefix(buffer, "tag ", &buffer)) { if (!skip_prefix(buffer, "tag ", &buffer)) {
ret = report(options, &tag->object.oid, tag->object.type, FSCK_MSG_MISSING_TAG_ENTRY, "invalid format - expected 'tag' line"); ret = report(options, oid, OBJ_TAG, FSCK_MSG_MISSING_TAG_ENTRY, "invalid format - expected 'tag' line");
goto done; goto done;
} }
eol = strchr(buffer, '\n'); eol = strchr(buffer, '\n');
if (!eol) { if (!eol) {
ret = report(options, &tag->object.oid, tag->object.type, FSCK_MSG_MISSING_TAG, "invalid format - unexpected end after 'type' line"); ret = report(options, oid, OBJ_TAG, FSCK_MSG_MISSING_TAG, "invalid format - unexpected end after 'type' line");
goto done; goto done;
} }
strbuf_addf(&sb, "refs/tags/%.*s", (int)(eol - buffer), buffer); strbuf_addf(&sb, "refs/tags/%.*s", (int)(eol - buffer), buffer);
if (check_refname_format(sb.buf, 0)) { if (check_refname_format(sb.buf, 0)) {
ret = report(options, &tag->object.oid, tag->object.type, ret = report(options, oid, OBJ_TAG,
FSCK_MSG_BAD_TAG_NAME, FSCK_MSG_BAD_TAG_NAME,
"invalid 'tag' name: %.*s", "invalid 'tag' name: %.*s",
(int)(eol - buffer), buffer); (int)(eol - buffer), buffer);
@ -881,12 +881,12 @@ static int fsck_tag(struct tag *tag, const char *buffer,


if (!skip_prefix(buffer, "tagger ", &buffer)) { if (!skip_prefix(buffer, "tagger ", &buffer)) {
/* early tags do not contain 'tagger' lines; warn only */ /* early tags do not contain 'tagger' lines; warn only */
ret = report(options, &tag->object.oid, tag->object.type, FSCK_MSG_MISSING_TAGGER_ENTRY, "invalid format - expected 'tagger' line"); ret = report(options, oid, OBJ_TAG, FSCK_MSG_MISSING_TAGGER_ENTRY, "invalid format - expected 'tagger' line");
if (ret) if (ret)
goto done; goto done;
} }
else else
ret = fsck_ident(&buffer, &tag->object.oid, tag->object.type, options); ret = fsck_ident(&buffer, oid, OBJ_TAG, options);


done: done:
strbuf_release(&sb); strbuf_release(&sb);
@ -987,8 +987,7 @@ int fsck_object(struct object *obj, void *data, unsigned long size,
return fsck_commit((struct commit *) obj, (const char *) data, return fsck_commit((struct commit *) obj, (const char *) data,
size, options); size, options);
if (obj->type == OBJ_TAG) if (obj->type == OBJ_TAG)
return fsck_tag((struct tag *) obj, (const char *) data, return fsck_tag(&obj->oid, data, size, options);
size, options);


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