fsck: don't require an object struct for fsck_ident()
The only thing we do with the struct is pass its oid and type to report(). We can just take those explicitly, which gives our callers more flexibility. 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:00 UTC
7854399366fa36854de8e6962a441b02009c10e4
1 file changed
+16
-14
fsck.c
+16
-14
@@ -717,7 +717,9 @@ static int verify_headers(const void *data, unsigned long size,
717
FSCK_MSG_UNTERMINATED_HEADER, "unterminated header");
718
}
719
720
-static int fsck_ident(const char **ident, struct object *obj, struct fsck_options *options)
720
+static int fsck_ident(const char **ident,
721
+ const struct object_id *oid, enum object_type type,
722
+ struct fsck_options *options)
723
{
724
const char *p = *ident;
725
char *end;
@@ -727,28 +729,28 @@ static int fsck_ident(const char **ident, struct object *obj, struct fsck_option
729
(*ident)++;
730
731
if (*p == '<')
730
- return report(options, &obj->oid, obj->type, FSCK_MSG_MISSING_NAME_BEFORE_EMAIL, "invalid author/committer line - missing space before email");
732
+ return report(options, oid, type, FSCK_MSG_MISSING_NAME_BEFORE_EMAIL, "invalid author/committer line - missing space before email");
733
p += strcspn(p, "<>\n");
734
if (*p == '>')
733
- return report(options, &obj->oid, obj->type, FSCK_MSG_BAD_NAME, "invalid author/committer line - bad name");
735
+ return report(options, oid, type, FSCK_MSG_BAD_NAME, "invalid author/committer line - bad name");
736
if (*p != '<')
735
- return report(options, &obj->oid, obj->type, FSCK_MSG_MISSING_EMAIL, "invalid author/committer line - missing email");
737
+ return report(options, oid, type, FSCK_MSG_MISSING_EMAIL, "invalid author/committer line - missing email");
738
if (p[-1] != ' ')
737
- return report(options, &obj->oid, obj->type, FSCK_MSG_MISSING_SPACE_BEFORE_EMAIL, "invalid author/committer line - missing space before email");
739
+ return report(options, oid, type, FSCK_MSG_MISSING_SPACE_BEFORE_EMAIL, "invalid author/committer line - missing space before email");
740
p++;
741
p += strcspn(p, "<>\n");
742
if (*p != '>')
741
- return report(options, &obj->oid, obj->type, FSCK_MSG_BAD_EMAIL, "invalid author/committer line - bad email");
743
+ return report(options, oid, type, FSCK_MSG_BAD_EMAIL, "invalid author/committer line - bad email");
744
p++;
745
if (*p != ' ')
744
- return report(options, &obj->oid, obj->type, FSCK_MSG_MISSING_SPACE_BEFORE_DATE, "invalid author/committer line - missing space before date");
746
+ return report(options, oid, type, FSCK_MSG_MISSING_SPACE_BEFORE_DATE, "invalid author/committer line - missing space before date");
747
p++;
748
if (*p == '0' && p[1] != ' ')
747
- return report(options, &obj->oid, obj->type, FSCK_MSG_ZERO_PADDED_DATE, "invalid author/committer line - zero-padded date");
749
+ return report(options, oid, type, FSCK_MSG_ZERO_PADDED_DATE, "invalid author/committer line - zero-padded date");
750
if (date_overflows(parse_timestamp(p, &end, 10)))
749
- return report(options, &obj->oid, obj->type, FSCK_MSG_BAD_DATE_OVERFLOW, "invalid author/committer line - date causes integer overflow");
751
+ return report(options, oid, type, FSCK_MSG_BAD_DATE_OVERFLOW, "invalid author/committer line - date causes integer overflow");
752
if ((end == p || *end != ' '))
751
- return report(options, &obj->oid, obj->type, FSCK_MSG_BAD_DATE, "invalid author/committer line - bad date");
753
+ return report(options, oid, type, FSCK_MSG_BAD_DATE, "invalid author/committer line - bad date");
754
p = end + 1;
755
if ((*p != '+' && *p != '-') ||
756
!isdigit(p[1]) ||
@@ -756,7 +758,7 @@ static int fsck_ident(const char **ident, struct object *obj, struct fsck_option
758
!isdigit(p[3]) ||
759
!isdigit(p[4]) ||
760
(p[5] != '\n'))
759
- return report(options, &obj->oid, obj->type, FSCK_MSG_BAD_TIMEZONE, "invalid author/committer line - bad time zone");
761
+ return report(options, oid, type, FSCK_MSG_BAD_TIMEZONE, "invalid author/committer line - bad time zone");
762
p += 6;
763
return 0;
764
}
@@ -792,7 +794,7 @@ static int fsck_commit(struct commit *commit, const char *buffer,
794
author_count = 0;
795
while (skip_prefix(buffer, "author ", &buffer)) {
796
author_count++;
795
- err = fsck_ident(&buffer, &commit->object, options);
797
+ err = fsck_ident(&buffer, &commit->object.oid, commit->object.type, options);
798
if (err)
799
return err;
800
}
@@ -804,7 +806,7 @@ static int fsck_commit(struct commit *commit, const char *buffer,
806
return err;
807
if (!skip_prefix(buffer, "committer ", &buffer))
808
return report(options, &commit->object.oid, commit->object.type, FSCK_MSG_MISSING_COMMITTER, "invalid format - expected 'committer' line");
807
- err = fsck_ident(&buffer, &commit->object, options);
809
+ err = fsck_ident(&buffer, &commit->object.oid, commit->object.type, options);
810
if (err)
811
return err;
812
if (memchr(buffer_begin, '\0', size)) {
@@ -882,7 +884,7 @@ static int fsck_tag(struct tag *tag, const char *buffer,
884
goto done;
885
}
886
else
885
- ret = fsck_ident(&buffer, &tag->object, options);
887
+ ret = fsck_ident(&buffer, &tag->object.oid, tag->object.type, options);
888
889
done:
890
strbuf_release(&sb);