fsck: accept an oid instead of a "struct blob" for fsck_blob()
We don't actually need any information from the object struct except its oid (and the type, of course, but that's implicitly OBJ_BLOB). This gives our callers more flexibility to drop the object structs, too. 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
6da40b22cae536211abcb943ff4f316e9129fcc9
1 file changed
+13
-13
fsck.c
+13
-13
@@ -890,7 +890,7 @@ done:
890
}
891
892
struct fsck_gitmodules_data {
893
- struct object *obj;
893
+ const struct object_id *oid;
894
struct fsck_options *options;
895
int ret;
896
};
@@ -909,21 +909,21 @@ static int fsck_gitmodules_fn(const char *var, const char *value, void *vdata)
909
name = xmemdupz(subsection, subsection_len);
910
if (check_submodule_name(name) < 0)
911
data->ret |= report(data->options,
912
- &data->obj->oid, data->obj->type,
912
+ data->oid, OBJ_BLOB,
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))
918
data->ret |= report(data->options,
919
- &data->obj->oid, data->obj->type,
919
+ data->oid, OBJ_BLOB,
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))
925
data->ret |= report(data->options,
926
- &data->obj->oid, data->obj->type,
926
+ data->oid, OBJ_BLOB,
927
FSCK_MSG_GITMODULES_PATH,
928
"disallowed submodule path: %s",
929
value);
@@ -932,17 +932,17 @@ static int fsck_gitmodules_fn(const char *var, const char *value, void *vdata)
932
return 0;
933
}
934
935
-static int fsck_blob(struct blob *blob, const char *buf,
935
+static int fsck_blob(const struct object_id *oid, const char *buf,
936
unsigned long size, struct fsck_options *options)
937
{
938
struct fsck_gitmodules_data data;
939
struct config_options config_opts = { 0 };
940
941
- if (!oidset_contains(&gitmodules_found, &blob->object.oid))
941
+ if (!oidset_contains(&gitmodules_found, oid))
942
return 0;
943
- oidset_insert(&gitmodules_done, &blob->object.oid);
943
+ oidset_insert(&gitmodules_done, oid);
944
945
- if (object_on_skiplist(options, &blob->object.oid))
945
+ if (object_on_skiplist(options, oid))
946
return 0;
947
948
if (!buf) {
@@ -951,18 +951,18 @@ 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
*/
954
- return report(options, &blob->object.oid, blob->object.type,
954
+ return report(options, oid, OBJ_BLOB,
955
FSCK_MSG_GITMODULES_LARGE,
956
".gitmodules too large to parse");
957
}
958
959
- data.obj = &blob->object;
959
+ data.oid = oid;
960
data.options = options;
961
data.ret = 0;
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))
965
- data.ret |= report(options, &blob->object.oid, blob->object.type,
965
+ data.ret |= report(options, oid, OBJ_BLOB,
966
FSCK_MSG_GITMODULES_PARSE,
967
"could not parse gitmodules blob");
968
@@ -976,7 +976,7 @@ int fsck_object(struct object *obj, void *data, unsigned long size,
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);
979
+ return fsck_blob(&obj->oid, data, size, options);
980
if (obj->type == OBJ_TREE)
981
return fsck_tree((struct tree *) obj, data, size, options);
982
if (obj->type == OBJ_COMMIT)
@@ -1042,7 +1042,7 @@ int fsck_finish(struct fsck_options *options)
1042
}
1043
1044
if (type == OBJ_BLOB)
1045
- ret |= fsck_blob(blob, buf, size, options);
1045
+ ret |= fsck_blob(&blob->object.oid, buf, size, options);
1046
else
1047
ret |= report(options,
1048
&blob->object.oid, blob->object.type,