Skip to content

Commit c54f5ca

Browse files
bk2204gitster
authored andcommitted
fsck: convert static functions to struct object_id
Convert two static functions to use struct object_id and parse_oid_hex, instead of relying on harcoded 20 and 40-based constants. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 3b683bc commit c54f5ca

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

fsck.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -711,30 +711,31 @@ static int fsck_ident(const char **ident, struct object *obj, struct fsck_option
711711
static int fsck_commit_buffer(struct commit *commit, const char *buffer,
712712
unsigned long size, struct fsck_options *options)
713713
{
714-
unsigned char tree_sha1[20], sha1[20];
714+
struct object_id tree_oid, oid;
715715
struct commit_graft *graft;
716716
unsigned parent_count, parent_line_count = 0, author_count;
717717
int err;
718718
const char *buffer_begin = buffer;
719+
const char *p;
719720

720721
if (verify_headers(buffer, size, &commit->object, options))
721722
return -1;
722723

723724
if (!skip_prefix(buffer, "tree ", &buffer))
724725
return report(options, &commit->object, FSCK_MSG_MISSING_TREE, "invalid format - expected 'tree' line");
725-
if (get_sha1_hex(buffer, tree_sha1) || buffer[40] != '\n') {
726+
if (parse_oid_hex(buffer, &tree_oid, &p) || *p != '\n') {
726727
err = report(options, &commit->object, FSCK_MSG_BAD_TREE_SHA1, "invalid 'tree' line format - bad sha1");
727728
if (err)
728729
return err;
729730
}
730-
buffer += 41;
731+
buffer = p + 1;
731732
while (skip_prefix(buffer, "parent ", &buffer)) {
732-
if (get_sha1_hex(buffer, sha1) || buffer[40] != '\n') {
733+
if (parse_oid_hex(buffer, &oid, &p) || *p != '\n') {
733734
err = report(options, &commit->object, FSCK_MSG_BAD_PARENT_SHA1, "invalid 'parent' line format - bad sha1");
734735
if (err)
735736
return err;
736737
}
737-
buffer += 41;
738+
buffer = p + 1;
738739
parent_line_count++;
739740
}
740741
graft = lookup_commit_graft(&commit->object.oid);
@@ -773,7 +774,7 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,
773774
if (err)
774775
return err;
775776
if (!commit->tree) {
776-
err = report(options, &commit->object, FSCK_MSG_BAD_TREE, "could not load commit's tree %s", sha1_to_hex(tree_sha1));
777+
err = report(options, &commit->object, FSCK_MSG_BAD_TREE, "could not load commit's tree %s", oid_to_hex(&tree_oid));
777778
if (err)
778779
return err;
779780
}
@@ -799,11 +800,12 @@ static int fsck_commit(struct commit *commit, const char *data,
799800
static int fsck_tag_buffer(struct tag *tag, const char *data,
800801
unsigned long size, struct fsck_options *options)
801802
{
802-
unsigned char sha1[20];
803+
struct object_id oid;
803804
int ret = 0;
804805
const char *buffer;
805806
char *to_free = NULL, *eol;
806807
struct strbuf sb = STRBUF_INIT;
808+
const char *p;
807809

808810
if (data)
809811
buffer = data;
@@ -834,12 +836,12 @@ static int fsck_tag_buffer(struct tag *tag, const char *data,
834836
ret = report(options, &tag->object, FSCK_MSG_MISSING_OBJECT, "invalid format - expected 'object' line");
835837
goto done;
836838
}
837-
if (get_sha1_hex(buffer, sha1) || buffer[40] != '\n') {
839+
if (parse_oid_hex(buffer, &oid, &p) || *p != '\n') {
838840
ret = report(options, &tag->object, FSCK_MSG_BAD_OBJECT_SHA1, "invalid 'object' line format - bad sha1");
839841
if (ret)
840842
goto done;
841843
}
842-
buffer += 41;
844+
buffer = p + 1;
843845

844846
if (!skip_prefix(buffer, "type ", &buffer)) {
845847
ret = report(options, &tag->object, FSCK_MSG_MISSING_TYPE_ENTRY, "invalid format - expected 'type' line");

0 commit comments

Comments
 (0)