]> git.ipfire.org Git - thirdparty/git.git/commitdiff
fsck.c: pass along the fsck_msg_id in the fsck_error callback
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Sun, 28 Mar 2021 13:15:46 +0000 (15:15 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 29 Mar 2021 02:03:10 +0000 (19:03 -0700)
Change the fsck_error callback to also pass along the
fsck_msg_id. Before this change the only way to get the message id was
to parse it back out of the "message".

Let's pass it down explicitly for the benefit of callers that might
want to use it, as discussed in [1].

Passing the msg_type is now redundant, as you can always get it back
from the msg_id, but I'm not changing that convention. It's really
common to need the msg_type, and the report() function itself (which
calls "fsck_error") needs to call fsck_msg_type() to discover
it. Let's not needlessly re-do that work in the user callback.

1. https://lore.kernel.org/git/87blcja2ha.fsf@evledraar.gmail.com/

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/fsck.c
builtin/index-pack.c
builtin/mktag.c
fsck.c
fsck.h

index 17940a4e24aa48dc5f3b3a46a705fb3bf530160f..70ff95837aee4f40271a4de596c63dd4fa02b18f 100644 (file)
@@ -84,7 +84,9 @@ static int objerror(struct object *obj, const char *err)
 static int fsck_error_func(struct fsck_options *o,
                           const struct object_id *oid,
                           enum object_type object_type,
-                          enum fsck_msg_type msg_type, const char *message)
+                          enum fsck_msg_type msg_type,
+                          enum fsck_msg_id msg_id,
+                          const char *message)
 {
        switch (msg_type) {
        case FSCK_WARN:
index 56b8efaa89ba8a3738b06981a581cfbd18897105..2b2266a4b7debf9064efdbd56b732031b04456c2 100644 (file)
@@ -1717,6 +1717,7 @@ static int print_dangling_gitmodules(struct fsck_options *o,
                                     const struct object_id *oid,
                                     enum object_type object_type,
                                     enum fsck_msg_type msg_type,
+                                    enum fsck_msg_id msg_id,
                                     const char *message)
 {
        /*
@@ -1727,7 +1728,7 @@ static int print_dangling_gitmodules(struct fsck_options *o,
                printf("%s\n", oid_to_hex(oid));
                return 0;
        }
-       return fsck_error_function(o, oid, object_type, msg_type, message);
+       return fsck_error_function(o, oid, object_type, msg_type, msg_id, message);
 }
 
 int cmd_index_pack(int argc, const char **argv, const char *prefix)
index 052a510ad7f34423e6c75db3ba768ad837d7a87f..96e63bc772ae2f051b629edc4f76f6634edce671 100644 (file)
@@ -18,6 +18,7 @@ static int mktag_fsck_error_func(struct fsck_options *o,
                                 const struct object_id *oid,
                                 enum object_type object_type,
                                 enum fsck_msg_type msg_type,
+                                enum fsck_msg_id msg_id,
                                 const char *message)
 {
        switch (msg_type) {
diff --git a/fsck.c b/fsck.c
index 150fe467e4340f72740853141198f80d3b54f9a3..23a77fe2e0fbd4fa7b05bdbaa72b430ba1deca0f 100644 (file)
--- a/fsck.c
+++ b/fsck.c
@@ -227,7 +227,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,
-                                    msg_type, sb.buf);
+                                    msg_type, msg_id, sb.buf);
        strbuf_release(&sb);
        va_end(ap);
 
@@ -1180,7 +1180,9 @@ int fsck_object(struct object *obj, void *data, unsigned long size,
 int fsck_error_function(struct fsck_options *o,
                        const struct object_id *oid,
                        enum object_type object_type,
-                       enum fsck_msg_type msg_type, const char *message)
+                       enum fsck_msg_type msg_type,
+                       enum fsck_msg_id msg_id,
+                       const char *message)
 {
        if (msg_type == FSCK_WARN) {
                warning("object %s: %s", fsck_describe_object(o, oid), message);
diff --git a/fsck.h b/fsck.h
index 66c4a71139a97bc5d6ca1b1bcf814a9b1a173da9..fa2d4955ab3b04308eb738d83ad080c9b25bf1a3 100644 (file)
--- a/fsck.h
+++ b/fsck.h
@@ -101,11 +101,13 @@ typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type,
 /* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */
 typedef int (*fsck_error)(struct fsck_options *o,
                          const struct object_id *oid, enum object_type object_type,
-                         enum fsck_msg_type msg_type, const char *message);
+                         enum fsck_msg_type msg_type, enum fsck_msg_id msg_id,
+                         const char *message);
 
 int fsck_error_function(struct fsck_options *o,
                        const struct object_id *oid, enum object_type object_type,
-                       enum fsck_msg_type msg_type, const char *message);
+                       enum fsck_msg_type msg_type, enum fsck_msg_id msg_id,
+                       const char *message);
 
 struct fsck_options {
        fsck_walk_func walk;