Skip to content

Commit 394d5d3

Browse files
avargitster
authored andcommitted
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/[email protected]/ Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 44e07da commit 394d5d3

File tree

5 files changed

+14
-6
lines changed

5 files changed

+14
-6
lines changed

builtin/fsck.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ static int objerror(struct object *obj, const char *err)
8484
static int fsck_error_func(struct fsck_options *o,
8585
const struct object_id *oid,
8686
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)
8890
{
8991
switch (msg_type) {
9092
case FSCK_WARN:

builtin/index-pack.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1717,6 +1717,7 @@ static int print_dangling_gitmodules(struct fsck_options *o,
17171717
const struct object_id *oid,
17181718
enum object_type object_type,
17191719
enum fsck_msg_type msg_type,
1720+
enum fsck_msg_id msg_id,
17201721
const char *message)
17211722
{
17221723
/*
@@ -1727,7 +1728,7 @@ static int print_dangling_gitmodules(struct fsck_options *o,
17271728
printf("%s\n", oid_to_hex(oid));
17281729
return 0;
17291730
}
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);
17311732
}
17321733

17331734
int cmd_index_pack(int argc, const char **argv, const char *prefix)

builtin/mktag.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ static int mktag_fsck_error_func(struct fsck_options *o,
1818
const struct object_id *oid,
1919
enum object_type object_type,
2020
enum fsck_msg_type msg_type,
21+
enum fsck_msg_id msg_id,
2122
const char *message)
2223
{
2324
switch (msg_type) {

fsck.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ static int report(struct fsck_options *options,
227227
va_start(ap, fmt);
228228
strbuf_vaddf(&sb, fmt, ap);
229229
result = options->error_func(options, oid, object_type,
230-
msg_type, sb.buf);
230+
msg_type, msg_id, sb.buf);
231231
strbuf_release(&sb);
232232
va_end(ap);
233233

@@ -1180,7 +1180,9 @@ int fsck_object(struct object *obj, void *data, unsigned long size,
11801180
int fsck_error_function(struct fsck_options *o,
11811181
const struct object_id *oid,
11821182
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)
11841186
{
11851187
if (msg_type == FSCK_WARN) {
11861188
warning("object %s: %s", fsck_describe_object(o, oid), message);

fsck.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,13 @@ typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type,
101101
/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */
102102
typedef int (*fsck_error)(struct fsck_options *o,
103103
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);
105106

106107
int fsck_error_function(struct fsck_options *o,
107108
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);
109111

110112
struct fsck_options {
111113
fsck_walk_func walk;

0 commit comments

Comments
 (0)