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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Oct 18, 2019 at 01:01 UTC
c5b4269b57df38b26a3b851833e94abce08583e7
1 file changed
+14
-15
fsck.c
+14
-15
@@ -764,8 +764,9 @@ static int fsck_ident(const char **ident,
764
return 0;
765
}
766
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)
770
{
771
struct object_id tree_oid, parent_oid;
772
unsigned author_count;
@@ -773,21 +774,20 @@ static int fsck_commit(struct commit *commit, const char *buffer,
774
const char *buffer_begin = buffer;
775
const char *p;
776
776
- if (verify_headers(buffer, size, &commit->object.oid,
777
- commit->object.type, options))
777
+ if (verify_headers(buffer, size, oid, OBJ_COMMIT, options))
778
return -1;
779
780
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");
782
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");
784
if (err)
785
return err;
786
}
787
buffer = p + 1;
788
while (skip_prefix(buffer, "parent ", &buffer)) {
789
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");
791
if (err)
792
return err;
793
}
@@ -796,23 +796,23 @@ static int fsck_commit(struct commit *commit, const char *buffer,
796
author_count = 0;
797
while (skip_prefix(buffer, "author ", &buffer)) {
798
author_count++;
799
- err = fsck_ident(&buffer, &commit->object.oid, commit->object.type, options);
799
+ err = fsck_ident(&buffer, oid, OBJ_COMMIT, options);
800
if (err)
801
return err;
802
}
803
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");
805
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");
807
if (err)
808
return err;
809
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);
812
if (err)
813
return err;
814
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,
816
"NUL byte in the commit object body");
817
if (err)
818
return err;
@@ -984,8 +984,7 @@ int fsck_object(struct object *obj, void *data, unsigned long size,
984
if (obj->type == OBJ_TREE)
985
return fsck_tree((struct tree *) obj, data, size, options);
986
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);
988
if (obj->type == OBJ_TAG)
989
return fsck_tag(&obj->oid, data, size, options);
990