summaryrefslogtreecommitdiffstats
path: root/fsck.c
diff options
context:
space:
mode:
authorshejialuo <shejialuo@gmail.com>2024-08-08 13:26:47 +0200
committerJunio C Hamano <gitster@pobox.com>2024-08-08 18:36:52 +0200
commit0ec5dfe8c45be2efd6350b3a1a3885c795a85578 (patch)
tree3ff59262b6e68189c98e5cd3029323f5b00d2ae8 /fsck.c
parentfsck: rename objects-related fsck error functions (diff)
downloadgit-0ec5dfe8c45be2efd6350b3a1a3885c795a85578.tar.xz
git-0ec5dfe8c45be2efd6350b3a1a3885c795a85578.zip
fsck: make "fsck_error" callback generic
The "fsck_error" callback is designed to report the objects-related error messages. It accepts two parameter "oid" and "object_type" which is not generic. In order to provide a unified callback which can report either objects or refs, remove the objects-related parameters and add the generic parameter "void *fsck_report". Create a new "fsck_object_report" structure which incorporates the removed parameters "oid" and "object_type". Then change the corresponding references to adapt to new "fsck_error" callback. Mentored-by: Patrick Steinhardt <ps@pks.im> Mentored-by: Karthik Nayak <karthik.188@gmail.com> Signed-off-by: shejialuo <shejialuo@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'fsck.c')
-rw-r--r--fsck.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/fsck.c b/fsck.c
index 8347842cfb..cca6ae144f 100644
--- a/fsck.c
+++ b/fsck.c
@@ -232,6 +232,10 @@ static int report(struct fsck_options *options,
enum fsck_msg_id msg_id, const char *fmt, ...)
{
va_list ap;
+ struct fsck_object_report report = {
+ .oid = oid,
+ .object_type = object_type
+ };
struct strbuf sb = STRBUF_INIT;
enum fsck_msg_type msg_type = fsck_msg_type(msg_id, options);
int result;
@@ -252,7 +256,7 @@ static int report(struct fsck_options *options,
va_start(ap, fmt);
strbuf_vaddf(&sb, fmt, ap);
- result = options->error_func(options, oid, object_type,
+ result = options->error_func(options, &report,
msg_type, msg_id, sb.buf);
strbuf_release(&sb);
va_end(ap);
@@ -1201,12 +1205,14 @@ int fsck_buffer(const struct object_id *oid, enum object_type type,
}
int fsck_objects_error_function(struct fsck_options *o,
- const struct object_id *oid,
- enum object_type object_type UNUSED,
- enum fsck_msg_type msg_type,
- enum fsck_msg_id msg_id UNUSED,
- const char *message)
+ void *fsck_report,
+ enum fsck_msg_type msg_type,
+ enum fsck_msg_id msg_id UNUSED,
+ const char *message)
{
+ struct fsck_object_report *report = fsck_report;
+ const struct object_id *oid = report->oid;
+
if (msg_type == FSCK_WARN) {
warning("object %s: %s", fsck_describe_object(o, oid), message);
return 0;
@@ -1304,16 +1310,16 @@ int git_fsck_config(const char *var, const char *value,
*/
int fsck_objects_error_cb_print_missing_gitmodules(struct fsck_options *o,
- const struct object_id *oid,
- enum object_type object_type,
+ void *fsck_report,
enum fsck_msg_type msg_type,
enum fsck_msg_id msg_id,
const char *message)
{
if (msg_id == FSCK_MSG_GITMODULES_MISSING) {
- puts(oid_to_hex(oid));
+ struct fsck_object_report *report = fsck_report;
+ puts(oid_to_hex(report->oid));
return 0;
}
- return fsck_objects_error_function(o, oid, object_type,
+ return fsck_objects_error_function(o, fsck_report,
msg_type, msg_id, message);
}