Skip to content

Commit c99ba49

Browse files
dschogitster
authored andcommitted
fsck: introduce identifiers for fsck messages
Instead of specifying whether a message by the fsck machinery constitutes an error or a warning, let's specify an identifier relating to the concrete problem that was encountered. This is necessary for upcoming support to be able to demote certain errors to warnings. In the process, simplify the requirements on the calling code: instead of having to handle full-blown varargs in every callback, we now send a string buffer ready to be used by the callback. We could use a simple enum for the message IDs here, but we want to guarantee that the enum values are associated with the appropriate message types (i.e. error or warning?). Besides, we want to introduce a parser in the next commit that maps the string representation to the enum value, hence we use the slightly ugly preprocessor construct that is extensible for use with said parser. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2241054 commit c99ba49

File tree

3 files changed

+154
-78
lines changed

3 files changed

+154
-78
lines changed

builtin/fsck.c

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,33 +46,23 @@ static int show_dangling = 1;
4646
#define DIRENT_SORT_HINT(de) ((de)->d_ino)
4747
#endif
4848

49-
static void objreport(struct object *obj, const char *severity,
50-
const char *err, va_list params)
49+
static void objreport(struct object *obj, const char *msg_type,
50+
const char *err)
5151
{
52-
fprintf(stderr, "%s in %s %s: ",
53-
severity, typename(obj->type), sha1_to_hex(obj->sha1));
54-
vfprintf(stderr, err, params);
55-
fputs("\n", stderr);
52+
fprintf(stderr, "%s in %s %s: %s\n",
53+
msg_type, typename(obj->type), sha1_to_hex(obj->sha1), err);
5654
}
5755

58-
__attribute__((format (printf, 2, 3)))
59-
static int objerror(struct object *obj, const char *err, ...)
56+
static int objerror(struct object *obj, const char *err)
6057
{
61-
va_list params;
62-
va_start(params, err);
6358
errors_found |= ERROR_OBJECT;
64-
objreport(obj, "error", err, params);
65-
va_end(params);
59+
objreport(obj, "error", err);
6660
return -1;
6761
}
6862

69-
__attribute__((format (printf, 3, 4)))
70-
static int fsck_error_func(struct object *obj, int type, const char *err, ...)
63+
static int fsck_error_func(struct object *obj, int type, const char *message)
7164
{
72-
va_list params;
73-
va_start(params, err);
74-
objreport(obj, (type == FSCK_WARN) ? "warning" : "error", err, params);
75-
va_end(params);
65+
objreport(obj, (type == FSCK_WARN) ? "warning" : "error", message);
7666
return (type == FSCK_WARN) ? 0 : 1;
7767
}
7868

0 commit comments

Comments
 (0)