fsck: don't require an object struct for report()
The report() function really only cares about the oid and type of the object, not the full object struct. Let's convert it to take those two items separately, which gives our callers more flexibility. This makes some already-long lines even longer. I've mostly left them, as our eventual goal is to shrink these down as we continue refactoring (e.g., "&item->object" becomes "&item->object.oid, item->object.type", but will eventually shrink down to "oid, type"). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Oct 18, 2019 at 00:59 UTC
38370253fd43f494ca628e47b4d9c6e629990fc7
1 file changed
+69
-59
fsck.c
+69
-59
@@ -283,9 +283,10 @@ static int object_on_skiplist(struct fsck_options *opts,
283
return opts && oid && oidset_contains(&opts->skiplist, oid);
284
}
285
286
-__attribute__((format (printf, 4, 5)))
287
-static int report(struct fsck_options *options, struct object *object,
288
- enum fsck_msg_id id, const char *fmt, ...)
286
+__attribute__((format (printf, 5, 6)))
287
+static int report(struct fsck_options *options,
288
+ const struct object_id *oid, enum object_type object_type,
289
+ enum fsck_msg_id id, const char *fmt, ...)
290
{
291
va_list ap;
292
struct strbuf sb = STRBUF_INIT;
@@ -294,7 +295,7 @@ static int report(struct fsck_options *options, struct object *object,
295
if (msg_type == FSCK_IGNORE)
296
return 0;
297
297
- if (object_on_skiplist(options, &object->oid))
298
+ if (object_on_skiplist(options, oid))
299
return 0;
300
301
if (msg_type == FSCK_FATAL)
@@ -306,7 +307,7 @@ static int report(struct fsck_options *options, struct object *object,
307
308
va_start(ap, fmt);
309
strbuf_vaddf(&sb, fmt, ap);
309
- result = options->error_func(options, &object->oid, object->type,
310
+ result = options->error_func(options, oid, object_type,
311
msg_type, sb.buf);
312
strbuf_release(&sb);
313
va_end(ap);
@@ -585,7 +586,7 @@ static int fsck_tree(struct tree *item,
586
const char *o_name;
587
588
if (init_tree_desc_gently(&desc, buffer, size)) {
588
- retval += report(options, &item->object, FSCK_MSG_BAD_TREE, "cannot be parsed as a tree");
589
+ retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_BAD_TREE, "cannot be parsed as a tree");
590
return retval;
591
}
592
@@ -611,13 +612,14 @@ static int fsck_tree(struct tree *item,
612
if (!S_ISLNK(mode))
613
oidset_insert(&gitmodules_found, oid);
614
else
614
- retval += report(options, &item->object,
615
+ retval += report(options,
616
+ &item->object.oid, item->object.type,
617
FSCK_MSG_GITMODULES_SYMLINK,
618
".gitmodules is a symbolic link");
619
}
620
621
if (update_tree_entry_gently(&desc)) {
620
- retval += report(options, &item->object, FSCK_MSG_BAD_TREE, "cannot be parsed as a tree");
622
+ retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_BAD_TREE, "cannot be parsed as a tree");
623
break;
624
}
625
@@ -662,25 +664,25 @@ static int fsck_tree(struct tree *item,
664
}
665
666
if (has_null_sha1)
665
- retval += report(options, &item->object, FSCK_MSG_NULL_SHA1, "contains entries pointing to null sha1");
667
+ retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_NULL_SHA1, "contains entries pointing to null sha1");
668
if (has_full_path)
667
- retval += report(options, &item->object, FSCK_MSG_FULL_PATHNAME, "contains full pathnames");
669
+ retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_FULL_PATHNAME, "contains full pathnames");
670
if (has_empty_name)
669
- retval += report(options, &item->object, FSCK_MSG_EMPTY_NAME, "contains empty pathname");
671
+ retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_EMPTY_NAME, "contains empty pathname");
672
if (has_dot)
671
- retval += report(options, &item->object, FSCK_MSG_HAS_DOT, "contains '.'");
673
+ retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_HAS_DOT, "contains '.'");
674
if (has_dotdot)
673
- retval += report(options, &item->object, FSCK_MSG_HAS_DOTDOT, "contains '..'");
675
+ retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_HAS_DOTDOT, "contains '..'");
676
if (has_dotgit)
675
- retval += report(options, &item->object, FSCK_MSG_HAS_DOTGIT, "contains '.git'");
677
+ retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_HAS_DOTGIT, "contains '.git'");
678
if (has_zero_pad)
677
- retval += report(options, &item->object, FSCK_MSG_ZERO_PADDED_FILEMODE, "contains zero-padded file modes");
679
+ retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_ZERO_PADDED_FILEMODE, "contains zero-padded file modes");
680
if (has_bad_modes)
679
- retval += report(options, &item->object, FSCK_MSG_BAD_FILEMODE, "contains bad file modes");
681
+ retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_BAD_FILEMODE, "contains bad file modes");
682
if (has_dup_entries)
681
- retval += report(options, &item->object, FSCK_MSG_DUPLICATE_ENTRIES, "contains duplicate file entries");
683
+ retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_DUPLICATE_ENTRIES, "contains duplicate file entries");
684
if (not_properly_sorted)
683
- retval += report(options, &item->object, FSCK_MSG_TREE_NOT_SORTED, "not properly sorted");
685
+ retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_TREE_NOT_SORTED, "not properly sorted");
686
return retval;
687
}
688
@@ -693,7 +695,7 @@ static int verify_headers(const void *data, unsigned long size,
695
for (i = 0; i < size; i++) {
696
switch (buffer[i]) {
697
case '\0':
696
- return report(options, obj,
698
+ return report(options, &obj->oid, obj->type,
699
FSCK_MSG_NUL_IN_HEADER,
700
"unterminated header: NUL at offset %ld", i);
701
case '\n':
@@ -711,7 +713,7 @@ static int verify_headers(const void *data, unsigned long size,
713
if (size && buffer[size - 1] == '\n')
714
return 0;
715
714
- return report(options, obj,
716
+ return report(options, &obj->oid, obj->type,
717
FSCK_MSG_UNTERMINATED_HEADER, "unterminated header");
718
}
719
@@ -725,28 +727,28 @@ static int fsck_ident(const char **ident, struct object *obj, struct fsck_option
727
(*ident)++;
728
729
if (*p == '<')
728
- return report(options, obj, FSCK_MSG_MISSING_NAME_BEFORE_EMAIL, "invalid author/committer line - missing space before email");
730
+ return report(options, &obj->oid, obj->type, FSCK_MSG_MISSING_NAME_BEFORE_EMAIL, "invalid author/committer line - missing space before email");
731
p += strcspn(p, "<>\n");
732
if (*p == '>')
731
- return report(options, obj, FSCK_MSG_BAD_NAME, "invalid author/committer line - bad name");
733
+ return report(options, &obj->oid, obj->type, FSCK_MSG_BAD_NAME, "invalid author/committer line - bad name");
734
if (*p != '<')
733
- return report(options, obj, FSCK_MSG_MISSING_EMAIL, "invalid author/committer line - missing email");
735
+ return report(options, &obj->oid, obj->type, FSCK_MSG_MISSING_EMAIL, "invalid author/committer line - missing email");
736
if (p[-1] != ' ')
735
- return report(options, obj, FSCK_MSG_MISSING_SPACE_BEFORE_EMAIL, "invalid author/committer line - missing space before email");
737
+ return report(options, &obj->oid, obj->type, FSCK_MSG_MISSING_SPACE_BEFORE_EMAIL, "invalid author/committer line - missing space before email");
738
p++;
739
p += strcspn(p, "<>\n");
740
if (*p != '>')
739
- return report(options, obj, FSCK_MSG_BAD_EMAIL, "invalid author/committer line - bad email");
741
+ return report(options, &obj->oid, obj->type, FSCK_MSG_BAD_EMAIL, "invalid author/committer line - bad email");
742
p++;
743
if (*p != ' ')
742
- return report(options, obj, FSCK_MSG_MISSING_SPACE_BEFORE_DATE, "invalid author/committer line - missing space before date");
744
+ return report(options, &obj->oid, obj->type, FSCK_MSG_MISSING_SPACE_BEFORE_DATE, "invalid author/committer line - missing space before date");
745
p++;
746
if (*p == '0' && p[1] != ' ')
745
- return report(options, obj, FSCK_MSG_ZERO_PADDED_DATE, "invalid author/committer line - zero-padded date");
747
+ return report(options, &obj->oid, obj->type, FSCK_MSG_ZERO_PADDED_DATE, "invalid author/committer line - zero-padded date");
748
if (date_overflows(parse_timestamp(p, &end, 10)))
747
- return report(options, obj, FSCK_MSG_BAD_DATE_OVERFLOW, "invalid author/committer line - date causes integer overflow");
749
+ return report(options, &obj->oid, obj->type, FSCK_MSG_BAD_DATE_OVERFLOW, "invalid author/committer line - date causes integer overflow");
750
if ((end == p || *end != ' '))
749
- return report(options, obj, FSCK_MSG_BAD_DATE, "invalid author/committer line - bad date");
751
+ return report(options, &obj->oid, obj->type, FSCK_MSG_BAD_DATE, "invalid author/committer line - bad date");
752
p = end + 1;
753
if ((*p != '+' && *p != '-') ||
754
!isdigit(p[1]) ||
@@ -754,7 +756,7 @@ static int fsck_ident(const char **ident, struct object *obj, struct fsck_option
756
!isdigit(p[3]) ||
757
!isdigit(p[4]) ||
758
(p[5] != '\n'))
757
- return report(options, obj, FSCK_MSG_BAD_TIMEZONE, "invalid author/committer line - bad time zone");
759
+ return report(options, &obj->oid, obj->type, FSCK_MSG_BAD_TIMEZONE, "invalid author/committer line - bad time zone");
760
p += 6;
761
return 0;
762
}
@@ -772,16 +774,16 @@ static int fsck_commit(struct commit *commit, const char *buffer,
774
return -1;
775
776
if (!skip_prefix(buffer, "tree ", &buffer))
775
- return report(options, &commit->object, FSCK_MSG_MISSING_TREE, "invalid format - expected 'tree' line");
777
+ return report(options, &commit->object.oid, commit->object.type, FSCK_MSG_MISSING_TREE, "invalid format - expected 'tree' line");
778
if (parse_oid_hex(buffer, &tree_oid, &p) || *p != '\n') {
777
- err = report(options, &commit->object, FSCK_MSG_BAD_TREE_SHA1, "invalid 'tree' line format - bad sha1");
779
+ err = report(options, &commit->object.oid, commit->object.type, FSCK_MSG_BAD_TREE_SHA1, "invalid 'tree' line format - bad sha1");
780
if (err)
781
return err;
782
}
783
buffer = p + 1;
784
while (skip_prefix(buffer, "parent ", &buffer)) {
785
if (parse_oid_hex(buffer, &oid, &p) || *p != '\n') {
784
- err = report(options, &commit->object, FSCK_MSG_BAD_PARENT_SHA1, "invalid 'parent' line format - bad sha1");
786
+ err = report(options, &commit->object.oid, commit->object.type, FSCK_MSG_BAD_PARENT_SHA1, "invalid 'parent' line format - bad sha1");
787
if (err)
788
return err;
789
}
@@ -795,18 +797,18 @@ static int fsck_commit(struct commit *commit, const char *buffer,
797
return err;
798
}
799
if (author_count < 1)
798
- err = report(options, &commit->object, FSCK_MSG_MISSING_AUTHOR, "invalid format - expected 'author' line");
800
+ err = report(options, &commit->object.oid, commit->object.type, FSCK_MSG_MISSING_AUTHOR, "invalid format - expected 'author' line");
801
else if (author_count > 1)
800
- err = report(options, &commit->object, FSCK_MSG_MULTIPLE_AUTHORS, "invalid format - multiple 'author' lines");
802
+ err = report(options, &commit->object.oid, commit->object.type, FSCK_MSG_MULTIPLE_AUTHORS, "invalid format - multiple 'author' lines");
803
if (err)
804
return err;
805
if (!skip_prefix(buffer, "committer ", &buffer))
804
- return report(options, &commit->object, FSCK_MSG_MISSING_COMMITTER, "invalid format - expected 'committer' line");
806
+ 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);
808
if (err)
809
return err;
810
if (memchr(buffer_begin, '\0', size)) {
809
- err = report(options, &commit->object, FSCK_MSG_NUL_IN_COMMIT,
811
+ err = report(options, &commit->object.oid, commit->object.type, FSCK_MSG_NUL_IN_COMMIT,
812
"NUL byte in the commit object body");
813
if (err)
814
return err;
@@ -828,45 +830,46 @@ static int fsck_tag(struct tag *tag, const char *buffer,
830
goto done;
831
832
if (!skip_prefix(buffer, "object ", &buffer)) {
831
- ret = report(options, &tag->object, FSCK_MSG_MISSING_OBJECT, "invalid format - expected 'object' line");
833
+ ret = report(options, &tag->object.oid, tag->object.type, FSCK_MSG_MISSING_OBJECT, "invalid format - expected 'object' line");
834
goto done;
835
}
836
if (parse_oid_hex(buffer, &oid, &p) || *p != '\n') {
835
- ret = report(options, &tag->object, FSCK_MSG_BAD_OBJECT_SHA1, "invalid 'object' line format - bad sha1");
837
+ ret = report(options, &tag->object.oid, tag->object.type, FSCK_MSG_BAD_OBJECT_SHA1, "invalid 'object' line format - bad sha1");
838
if (ret)
839
goto done;
840
}
841
buffer = p + 1;
842
843
if (!skip_prefix(buffer, "type ", &buffer)) {
842
- ret = report(options, &tag->object, FSCK_MSG_MISSING_TYPE_ENTRY, "invalid format - expected 'type' line");
844
+ ret = report(options, &tag->object.oid, tag->object.type, FSCK_MSG_MISSING_TYPE_ENTRY, "invalid format - expected 'type' line");
845
goto done;
846
}
847
eol = strchr(buffer, '\n');
848
if (!eol) {
847
- ret = report(options, &tag->object, FSCK_MSG_MISSING_TYPE, "invalid format - unexpected end after 'type' line");
849
+ ret = report(options, &tag->object.oid, tag->object.type, FSCK_MSG_MISSING_TYPE, "invalid format - unexpected end after 'type' line");
850
goto done;
851
}
852
if (type_from_string_gently(buffer, eol - buffer, 1) < 0)
851
- ret = report(options, &tag->object, FSCK_MSG_BAD_TYPE, "invalid 'type' value");
853
+ ret = report(options, &tag->object.oid, tag->object.type, FSCK_MSG_BAD_TYPE, "invalid 'type' value");
854
if (ret)
855
goto done;
856
buffer = eol + 1;
857
858
if (!skip_prefix(buffer, "tag ", &buffer)) {
857
- ret = report(options, &tag->object, FSCK_MSG_MISSING_TAG_ENTRY, "invalid format - expected 'tag' line");
859
+ ret = report(options, &tag->object.oid, tag->object.type, FSCK_MSG_MISSING_TAG_ENTRY, "invalid format - expected 'tag' line");
860
goto done;
861
}
862
eol = strchr(buffer, '\n');
863
if (!eol) {
862
- ret = report(options, &tag->object, FSCK_MSG_MISSING_TAG, "invalid format - unexpected end after 'type' line");
864
+ ret = report(options, &tag->object.oid, tag->object.type, FSCK_MSG_MISSING_TAG, "invalid format - unexpected end after 'type' line");
865
goto done;
866
}
867
strbuf_addf(&sb, "refs/tags/%.*s", (int)(eol - buffer), buffer);
868
if (check_refname_format(sb.buf, 0)) {
867
- ret = report(options, &tag->object, FSCK_MSG_BAD_TAG_NAME,
868
- "invalid 'tag' name: %.*s",
869
- (int)(eol - buffer), buffer);
869
+ ret = report(options, &tag->object.oid, tag->object.type,
870
+ FSCK_MSG_BAD_TAG_NAME,
871
+ "invalid 'tag' name: %.*s",
872
+ (int)(eol - buffer), buffer);
873
if (ret)
874
goto done;
875
}
@@ -874,7 +877,7 @@ static int fsck_tag(struct tag *tag, const char *buffer,
877
878
if (!skip_prefix(buffer, "tagger ", &buffer)) {
879
/* early tags do not contain 'tagger' lines; warn only */
877
- ret = report(options, &tag->object, FSCK_MSG_MISSING_TAGGER_ENTRY, "invalid format - expected 'tagger' line");
880
+ ret = report(options, &tag->object.oid, tag->object.type, FSCK_MSG_MISSING_TAGGER_ENTRY, "invalid format - expected 'tagger' line");
881
if (ret)
882
goto done;
883
}
@@ -905,19 +908,22 @@ static int fsck_gitmodules_fn(const char *var, const char *value, void *vdata)
908
909
name = xmemdupz(subsection, subsection_len);
910
if (check_submodule_name(name) < 0)
908
- data->ret |= report(data->options, data->obj,
911
+ data->ret |= report(data->options,
912
+ &data->obj->oid, data->obj->type,
913
FSCK_MSG_GITMODULES_NAME,
914
"disallowed submodule name: %s",
915
name);
916
if (!strcmp(key, "url") && value &&
917
looks_like_command_line_option(value))
914
- data->ret |= report(data->options, data->obj,
918
+ data->ret |= report(data->options,
919
+ &data->obj->oid, data->obj->type,
920
FSCK_MSG_GITMODULES_URL,
921
"disallowed submodule url: %s",
922
value);
923
if (!strcmp(key, "path") && value &&
924
looks_like_command_line_option(value))
920
- data->ret |= report(data->options, data->obj,
925
+ data->ret |= report(data->options,
926
+ &data->obj->oid, data->obj->type,
927
FSCK_MSG_GITMODULES_PATH,
928
"disallowed submodule path: %s",
929
value);
@@ -945,7 +951,7 @@ static int fsck_blob(struct blob *blob, const char *buf,
951
* blob too gigantic to load into memory. Let's just consider
952
* that an error.
953
*/
948
- return report(options, &blob->object,
954
+ return report(options, &blob->object.oid, blob->object.type,
955
FSCK_MSG_GITMODULES_LARGE,
956
".gitmodules too large to parse");
957
}
@@ -956,7 +962,7 @@ static int fsck_blob(struct blob *blob, const char *buf,
962
config_opts.error_action = CONFIG_ERROR_SILENT;
963
if (git_config_from_mem(fsck_gitmodules_fn, CONFIG_ORIGIN_BLOB,
964
".gitmodules", buf, size, &data, &config_opts))
959
- data.ret |= report(options, &blob->object,
965
+ data.ret |= report(options, &blob->object.oid, blob->object.type,
966
FSCK_MSG_GITMODULES_PARSE,
967
"could not parse gitmodules blob");
968
@@ -967,7 +973,7 @@ int fsck_object(struct object *obj, void *data, unsigned long size,
973
struct fsck_options *options)
974
{
975
if (!obj)
970
- return report(options, obj, FSCK_MSG_BAD_OBJECT_SHA1, "no valid object to fsck");
976
+ return report(options, NULL, OBJ_NONE, FSCK_MSG_BAD_OBJECT_SHA1, "no valid object to fsck");
977
978
if (obj->type == OBJ_BLOB)
979
return fsck_blob((struct blob *)obj, data, size, options);
@@ -980,8 +986,10 @@ int fsck_object(struct object *obj, void *data, unsigned long size,
986
return fsck_tag((struct tag *) obj, (const char *) data,
987
size, options);
988
983
- return report(options, obj, FSCK_MSG_UNKNOWN_TYPE, "unknown type '%d' (internal fsck error)",
984
- obj->type);
989
+ return report(options, &obj->oid, obj->type,
990
+ FSCK_MSG_UNKNOWN_TYPE,
991
+ "unknown type '%d' (internal fsck error)",
992
+ obj->type);
993
}
994
995
int fsck_error_function(struct fsck_options *o,
@@ -1016,7 +1024,7 @@ int fsck_finish(struct fsck_options *options)
1024
blob = lookup_blob(the_repository, oid);
1025
if (!blob) {
1026
struct object *obj = lookup_unknown_object(oid);
1019
- ret |= report(options, obj,
1027
+ ret |= report(options, &obj->oid, obj->type,
1028
FSCK_MSG_GITMODULES_BLOB,
1029
"non-blob found at .gitmodules");
1030
continue;
@@ -1026,7 +1034,8 @@ int fsck_finish(struct fsck_options *options)
1034
if (!buf) {
1035
if (is_promisor_object(&blob->object.oid))
1036
continue;
1029
- ret |= report(options, &blob->object,
1037
+ ret |= report(options,
1038
+ &blob->object.oid, blob->object.type,
1039
FSCK_MSG_GITMODULES_MISSING,
1040
"unable to read .gitmodules blob");
1041
continue;
@@ -1035,7 +1044,8 @@ int fsck_finish(struct fsck_options *options)
1044
if (type == OBJ_BLOB)
1045
ret |= fsck_blob(blob, buf, size, options);
1046
else
1038
- ret |= report(options, &blob->object,
1047
+ ret |= report(options,
1048
+ &blob->object.oid, blob->object.type,
1049
FSCK_MSG_GITMODULES_BLOB,
1050
"non-blob found at .gitmodules");
1051
free(buf);