Skip to content

Commit

Permalink
fsck: accept an oid instead of a "struct tag" for fsck_tag()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
peff authored and gitster committed Oct 28, 2019
1 parent f648ee7 commit 103fb6d
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions fsck.c
Expand Up @@ -820,7 +820,7 @@ static int fsck_commit(struct commit *commit, const char *buffer,
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)
{
struct object_id tagged_oid;
Expand All @@ -829,48 +829,48 @@ static int fsck_tag(struct tag *tag, const char *buffer,
struct strbuf sb = STRBUF_INIT;
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)
goto done;

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;
}
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)
goto done;
}
buffer = p + 1;

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;
}
eol = strchr(buffer, '\n');
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;
}
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)
goto done;
buffer = eol + 1;

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;
}
eol = strchr(buffer, '\n');
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;
}
strbuf_addf(&sb, "refs/tags/%.*s", (int)(eol - buffer), buffer);
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,
"invalid 'tag' name: %.*s",
(int)(eol - buffer), buffer);
Expand All @@ -881,12 +881,12 @@ static int fsck_tag(struct tag *tag, const char *buffer,

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

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

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

0 comments on commit 103fb6d

Please sign in to comment.