Skip to content

Commit c5b4269

Browse files
peffgitster
authored andcommitted
fsck: accept an oid instead of a "struct commit" for fsck_commit()
We don't actually look at the commit struct in fsck_commit() beyond its oid and type (which is obviously OBJ_COMMIT). 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 103fb6d commit c5b4269

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

fsck.c

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -764,30 +764,30 @@ static int fsck_ident(const char **ident,
764764
return 0;
765765
}
766766

767-
static int fsck_commit(struct commit *commit, const char *buffer,
768-
unsigned long size, struct fsck_options *options)
767+
static int fsck_commit(const struct object_id *oid,
768+
const char *buffer, unsigned long size,
769+
struct fsck_options *options)
769770
{
770771
struct object_id tree_oid, parent_oid;
771772
unsigned author_count;
772773
int err;
773774
const char *buffer_begin = buffer;
774775
const char *p;
775776

776-
if (verify_headers(buffer, size, &commit->object.oid,
777-
commit->object.type, options))
777+
if (verify_headers(buffer, size, oid, OBJ_COMMIT, options))
778778
return -1;
779779

780780
if (!skip_prefix(buffer, "tree ", &buffer))
781-
return report(options, &commit->object.oid, commit->object.type, FSCK_MSG_MISSING_TREE, "invalid format - expected 'tree' line");
781+
return report(options, oid, OBJ_COMMIT, FSCK_MSG_MISSING_TREE, "invalid format - expected 'tree' line");
782782
if (parse_oid_hex(buffer, &tree_oid, &p) || *p != '\n') {
783-
err = report(options, &commit->object.oid, commit->object.type, FSCK_MSG_BAD_TREE_SHA1, "invalid 'tree' line format - bad sha1");
783+
err = report(options, oid, OBJ_COMMIT, FSCK_MSG_BAD_TREE_SHA1, "invalid 'tree' line format - bad sha1");
784784
if (err)
785785
return err;
786786
}
787787
buffer = p + 1;
788788
while (skip_prefix(buffer, "parent ", &buffer)) {
789789
if (parse_oid_hex(buffer, &parent_oid, &p) || *p != '\n') {
790-
err = report(options, &commit->object.oid, commit->object.type, FSCK_MSG_BAD_PARENT_SHA1, "invalid 'parent' line format - bad sha1");
790+
err = report(options, oid, OBJ_COMMIT, FSCK_MSG_BAD_PARENT_SHA1, "invalid 'parent' line format - bad sha1");
791791
if (err)
792792
return err;
793793
}
@@ -796,23 +796,23 @@ static int fsck_commit(struct commit *commit, const char *buffer,
796796
author_count = 0;
797797
while (skip_prefix(buffer, "author ", &buffer)) {
798798
author_count++;
799-
err = fsck_ident(&buffer, &commit->object.oid, commit->object.type, options);
799+
err = fsck_ident(&buffer, oid, OBJ_COMMIT, options);
800800
if (err)
801801
return err;
802802
}
803803
if (author_count < 1)
804-
err = report(options, &commit->object.oid, commit->object.type, FSCK_MSG_MISSING_AUTHOR, "invalid format - expected 'author' line");
804+
err = report(options, oid, OBJ_COMMIT, FSCK_MSG_MISSING_AUTHOR, "invalid format - expected 'author' line");
805805
else if (author_count > 1)
806-
err = report(options, &commit->object.oid, commit->object.type, FSCK_MSG_MULTIPLE_AUTHORS, "invalid format - multiple 'author' lines");
806+
err = report(options, oid, OBJ_COMMIT, FSCK_MSG_MULTIPLE_AUTHORS, "invalid format - multiple 'author' lines");
807807
if (err)
808808
return err;
809809
if (!skip_prefix(buffer, "committer ", &buffer))
810-
return report(options, &commit->object.oid, commit->object.type, FSCK_MSG_MISSING_COMMITTER, "invalid format - expected 'committer' line");
811-
err = fsck_ident(&buffer, &commit->object.oid, commit->object.type, options);
810+
return report(options, oid, OBJ_COMMIT, FSCK_MSG_MISSING_COMMITTER, "invalid format - expected 'committer' line");
811+
err = fsck_ident(&buffer, oid, OBJ_COMMIT, options);
812812
if (err)
813813
return err;
814814
if (memchr(buffer_begin, '\0', size)) {
815-
err = report(options, &commit->object.oid, commit->object.type, FSCK_MSG_NUL_IN_COMMIT,
815+
err = report(options, oid, OBJ_COMMIT, FSCK_MSG_NUL_IN_COMMIT,
816816
"NUL byte in the commit object body");
817817
if (err)
818818
return err;
@@ -984,8 +984,7 @@ int fsck_object(struct object *obj, void *data, unsigned long size,
984984
if (obj->type == OBJ_TREE)
985985
return fsck_tree((struct tree *) obj, data, size, options);
986986
if (obj->type == OBJ_COMMIT)
987-
return fsck_commit((struct commit *) obj, (const char *) data,
988-
size, options);
987+
return fsck_commit(&obj->oid, data, size, options);
989988
if (obj->type == OBJ_TAG)
990989
return fsck_tag(&obj->oid, data, size, options);
991990

0 commit comments

Comments
 (0)