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>

brian m. carlson committed May 2, 2018 at 00:25 UTC c54f5ca97075fcaa11841e80855d55e0af29ea72
1 file changed +11 -9
fsck.c
+11 -9
@@ -711,30 +711,31 @@ static int fsck_ident(const char **ident, struct object *obj, struct fsck_option
711 static int fsck_commit_buffer(struct commit *commit, const char *buffer,
712 unsigned long size, struct fsck_options *options)
713 {
714 - unsigned char tree_sha1[20], sha1[20];
714 + struct object_id tree_oid, oid;
715 struct commit_graft *graft;
716 unsigned parent_count, parent_line_count = 0, author_count;
717 int err;
718 const char *buffer_begin = buffer;
719 + const char *p;
720
721 if (verify_headers(buffer, size, &commit->object, options))
722 return -1;
723
724 if (!skip_prefix(buffer, "tree ", &buffer))
725 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') {
727 err = report(options, &commit->object, FSCK_MSG_BAD_TREE_SHA1, "invalid 'tree' line format - bad sha1");
728 if (err)
729 return err;
730 }
730 - buffer += 41;
731 + buffer = p + 1;
732 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') {
734 err = report(options, &commit->object, FSCK_MSG_BAD_PARENT_SHA1, "invalid 'parent' line format - bad sha1");
735 if (err)
736 return err;
737 }
737 - buffer += 41;
738 + buffer = p + 1;
739 parent_line_count++;
740 }
741 graft = lookup_commit_graft(&commit->object.oid);
@@ -773,7 +774,7 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,
774 if (err)
775 return err;
776 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));
778 if (err)
779 return err;
780 }
@@ -799,11 +800,12 @@ static int fsck_commit(struct commit *commit, const char *data,
800 static int fsck_tag_buffer(struct tag *tag, const char *data,
801 unsigned long size, struct fsck_options *options)
802 {
802 - unsigned char sha1[20];
803 + struct object_id oid;
804 int ret = 0;
805 const char *buffer;
806 char *to_free = NULL, *eol;
807 struct strbuf sb = STRBUF_INIT;
808 + const char *p;
809
810 if (data)
811 buffer = data;
@@ -834,12 +836,12 @@ static int fsck_tag_buffer(struct tag *tag, const char *data,
836 ret = report(options, &tag->object, FSCK_MSG_MISSING_OBJECT, "invalid format - expected 'object' line");
837 goto done;
838 }
837 - if (get_sha1_hex(buffer, sha1) || buffer[40] != '\n') {
839 + if (parse_oid_hex(buffer, &oid, &p) || *p != '\n') {
840 ret = report(options, &tag->object, FSCK_MSG_BAD_OBJECT_SHA1, "invalid 'object' line format - bad sha1");
841 if (ret)
842 goto done;
843 }
842 - buffer += 41;
844 + buffer = p + 1;
845
846 if (!skip_prefix(buffer, "type ", &buffer)) {
847 ret = report(options, &tag->object, FSCK_MSG_MISSING_TYPE_ENTRY, "invalid format - expected 'type' line");