fsck: only provide oid/type in fsck_error callback
None of the callbacks actually care about having a "struct object"; they're happy with just the oid and type information. So let's give ourselves more flexibility to avoid having a "struct object" by just passing the broken-down fields. Note that the callback already takes a "type" field for the fsck message type. We'll rename that to "msg_type" (and use "object_type" for the object type) to make the distinction explicit. 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:58 UTC
5afc4b1dc622d574bcd67b5845789a0b5875431a
3 files changed
+21
-13
builtin/fsck.c
+10
-7
@@ -104,23 +104,26 @@ static int objerror(struct object *obj, const char *err)
104
}
105
106
static int fsck_error_func(struct fsck_options *o,
107
- struct object *obj, int type, const char *message)
107
+ const struct object_id *oid,
108
+ enum object_type object_type,
109
+ int msg_type, const char *message)
110
{
109
- switch (type) {
111
+ switch (msg_type) {
112
case FSCK_WARN:
113
/* TRANSLATORS: e.g. warning in tree 01bfda: <more explanation> */
114
fprintf_ln(stderr, _("warning in %s %s: %s"),
113
- printable_type(&obj->oid, obj->type),
114
- describe_object(&obj->oid), message);
115
+ printable_type(oid, object_type),
116
+ describe_object(oid), message);
117
return 0;
118
case FSCK_ERROR:
119
/* TRANSLATORS: e.g. error in tree 01bfda: <more explanation> */
120
fprintf_ln(stderr, _("error in %s %s: %s"),
119
- printable_type(&obj->oid, obj->type),
120
- describe_object(&obj->oid), message);
121
+ printable_type(oid, object_type),
122
+ describe_object(oid), message);
123
return 1;
124
default:
123
- BUG("%d (FSCK_IGNORE?) should never trigger this callback", type);
125
+ BUG("%d (FSCK_IGNORE?) should never trigger this callback",
126
+ msg_type);
127
}
128
}
129
fsck.c
+7
-4
@@ -305,7 +305,8 @@ static int report(struct fsck_options *options, struct object *object,
305
306
va_start(ap, fmt);
307
strbuf_vaddf(&sb, fmt, ap);
308
- result = options->error_func(options, object, msg_type, sb.buf);
308
+ result = options->error_func(options, &object->oid, object->type,
309
+ msg_type, sb.buf);
310
strbuf_release(&sb);
311
va_end(ap);
312
@@ -983,13 +984,15 @@ int fsck_object(struct object *obj, void *data, unsigned long size,
984
}
985
986
int fsck_error_function(struct fsck_options *o,
986
- struct object *obj, int msg_type, const char *message)
987
+ const struct object_id *oid,
988
+ enum object_type object_type,
989
+ int msg_type, const char *message)
990
{
991
if (msg_type == FSCK_WARN) {
989
- warning("object %s: %s", fsck_describe_object(o, &obj->oid), message);
992
+ warning("object %s: %s", fsck_describe_object(o, oid), message);
993
return 0;
994
}
992
- error("object %s: %s", fsck_describe_object(o, &obj->oid), message);
995
+ error("object %s: %s", fsck_describe_object(o, oid), message);
996
return 1;
997
}
998
fsck.h
+4
-2
@@ -27,10 +27,12 @@ typedef int (*fsck_walk_func)(struct object *obj, int type, void *data, struct f
27
28
/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */
29
typedef int (*fsck_error)(struct fsck_options *o,
30
- struct object *obj, int type, const char *message);
30
+ const struct object_id *oid, enum object_type object_type,
31
+ int msg_type, const char *message);
32
33
int fsck_error_function(struct fsck_options *o,
33
- struct object *obj, int type, const char *message);
34
+ const struct object_id *oid, enum object_type object_type,
35
+ int msg_type, const char *message);
36
37
struct fsck_options {
38
fsck_walk_func walk;