fsck.c: pass along the fsck_msg_id in the fsck_error callback

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>

Ævar Arnfjörð Bjarmason committed Mar 28, 2021 at 15:15 UTC 394d5d31b0d3096aed4513bdacf48fb73003f1df
5 files changed +14 -6
builtin/fsck.c
+3 -1
@@ -84,7 +84,9 @@ static int objerror(struct object *obj, const char *err)
84 static int fsck_error_func(struct fsck_options *o,
85 const struct object_id *oid,
86 enum object_type object_type,
87 - enum fsck_msg_type msg_type, const char *message)
87 + enum fsck_msg_type msg_type,
88 + enum fsck_msg_id msg_id,
89 + const char *message)
90 {
91 switch (msg_type) {
92 case FSCK_WARN:
builtin/index-pack.c
+2 -1
@@ -1717,6 +1717,7 @@ static int print_dangling_gitmodules(struct fsck_options *o,
1717 const struct object_id *oid,
1718 enum object_type object_type,
1719 enum fsck_msg_type msg_type,
1720 + enum fsck_msg_id msg_id,
1721 const char *message)
1722 {
1723 /*
@@ -1727,7 +1728,7 @@ static int print_dangling_gitmodules(struct fsck_options *o,
1728 printf("%s\n", oid_to_hex(oid));
1729 return 0;
1730 }
1730 - return fsck_error_function(o, oid, object_type, msg_type, message);
1731 + return fsck_error_function(o, oid, object_type, msg_type, msg_id, message);
1732 }
1733
1734 int cmd_index_pack(int argc, const char **argv, const char *prefix)
builtin/mktag.c
+1
@@ -18,6 +18,7 @@ static int mktag_fsck_error_func(struct fsck_options *o,
18 const struct object_id *oid,
19 enum object_type object_type,
20 enum fsck_msg_type msg_type,
21 + enum fsck_msg_id msg_id,
22 const char *message)
23 {
24 switch (msg_type) {
fsck.c
+4 -2
@@ -227,7 +227,7 @@ static int report(struct fsck_options *options,
227 va_start(ap, fmt);
228 strbuf_vaddf(&sb, fmt, ap);
229 result = options->error_func(options, oid, object_type,
230 - msg_type, sb.buf);
230 + msg_type, msg_id, sb.buf);
231 strbuf_release(&sb);
232 va_end(ap);
233
@@ -1180,7 +1180,9 @@ int fsck_object(struct object *obj, void *data, unsigned long size,
1180 int fsck_error_function(struct fsck_options *o,
1181 const struct object_id *oid,
1182 enum object_type object_type,
1183 - enum fsck_msg_type msg_type, const char *message)
1183 + enum fsck_msg_type msg_type,
1184 + enum fsck_msg_id msg_id,
1185 + const char *message)
1186 {
1187 if (msg_type == FSCK_WARN) {
1188 warning("object %s: %s", fsck_describe_object(o, oid), message);
fsck.h
+4 -2
@@ -101,11 +101,13 @@ typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type,
101 /* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */
102 typedef int (*fsck_error)(struct fsck_options *o,
103 const struct object_id *oid, enum object_type object_type,
104 - enum fsck_msg_type msg_type, const char *message);
104 + enum fsck_msg_type msg_type, enum fsck_msg_id msg_id,
105 + const char *message);
106
107 int fsck_error_function(struct fsck_options *o,
108 const struct object_id *oid, enum object_type object_type,
108 - enum fsck_msg_type msg_type, const char *message);
109 + enum fsck_msg_type msg_type, enum fsck_msg_id msg_id,
110 + const char *message);
111
112 struct fsck_options {
113 fsck_walk_func walk;