]> git.ipfire.org Git - thirdparty/git.git/commitdiff
fsck: only provide oid/type in fsck_error callback
authorJeff King <peff@peff.net>
Fri, 18 Oct 2019 04:58:40 +0000 (00:58 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 28 Oct 2019 05:05:18 +0000 (14:05 +0900)
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>
builtin/fsck.c
fsck.c
fsck.h

index 59c77c1baa3811055e02949dac7e01b55374625e..8d13794b1412c82f3a19331548b4b2cb26da349b 100644 (file)
@@ -104,23 +104,26 @@ static int objerror(struct object *obj, const char *err)
 }
 
 static int fsck_error_func(struct fsck_options *o,
-       struct object *obj, int type, const char *message)
+                          const struct object_id *oid,
+                          enum object_type object_type,
+                          int msg_type, const char *message)
 {
-       switch (type) {
+       switch (msg_type) {
        case FSCK_WARN:
                /* TRANSLATORS: e.g. warning in tree 01bfda: <more explanation> */
                fprintf_ln(stderr, _("warning in %s %s: %s"),
-                          printable_type(&obj->oid, obj->type),
-                          describe_object(&obj->oid), message);
+                          printable_type(oid, object_type),
+                          describe_object(oid), message);
                return 0;
        case FSCK_ERROR:
                /* TRANSLATORS: e.g. error in tree 01bfda: <more explanation> */
                fprintf_ln(stderr, _("error in %s %s: %s"),
-                          printable_type(&obj->oid, obj->type),
-                          describe_object(&obj->oid), message);
+                          printable_type(oid, object_type),
+                          describe_object(oid), message);
                return 1;
        default:
-               BUG("%d (FSCK_IGNORE?) should never trigger this callback", type);
+               BUG("%d (FSCK_IGNORE?) should never trigger this callback",
+                   msg_type);
        }
 }
 
diff --git a/fsck.c b/fsck.c
index 124c0184d4ea22e6a3245665814f801db270096e..c036ba09ab9cb02a39b7fcfb2655579b68011592 100644 (file)
--- a/fsck.c
+++ b/fsck.c
@@ -305,7 +305,8 @@ static int report(struct fsck_options *options, struct object *object,
 
        va_start(ap, fmt);
        strbuf_vaddf(&sb, fmt, ap);
-       result = options->error_func(options, object, msg_type, sb.buf);
+       result = options->error_func(options, &object->oid, object->type,
+                                    msg_type, sb.buf);
        strbuf_release(&sb);
        va_end(ap);
 
@@ -983,13 +984,15 @@ int fsck_object(struct object *obj, void *data, unsigned long size,
 }
 
 int fsck_error_function(struct fsck_options *o,
-       struct object *obj, int msg_type, const char *message)
+                       const struct object_id *oid,
+                       enum object_type object_type,
+                       int msg_type, const char *message)
 {
        if (msg_type == FSCK_WARN) {
-               warning("object %s: %s", fsck_describe_object(o, &obj->oid), message);
+               warning("object %s: %s", fsck_describe_object(o, oid), message);
                return 0;
        }
-       error("object %s: %s", fsck_describe_object(o, &obj->oid), message);
+       error("object %s: %s", fsck_describe_object(o, oid), message);
        return 1;
 }
 
diff --git a/fsck.h b/fsck.h
index 36cfa463af2cd2791c17ec5a3aafa7321ded108b..69cf715e798ce29085b529b88374c5de75e69529 100644 (file)
--- a/fsck.h
+++ b/fsck.h
@@ -27,10 +27,12 @@ typedef int (*fsck_walk_func)(struct object *obj, int type, void *data, struct f
 
 /* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */
 typedef int (*fsck_error)(struct fsck_options *o,
-       struct object *obj, int type, const char *message);
+                         const struct object_id *oid, enum object_type object_type,
+                         int msg_type, const char *message);
 
 int fsck_error_function(struct fsck_options *o,
-       struct object *obj, int type, const char *message);
+                       const struct object_id *oid, enum object_type object_type,
+                       int msg_type, const char *message);
 
 struct fsck_options {
        fsck_walk_func walk;