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 <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
22410549fc
commit
c99ba492f1
@ -46,33 +46,23 @@ static int show_dangling = 1;
|
||||
#define DIRENT_SORT_HINT(de) ((de)->d_ino)
|
||||
#endif
|
||||
|
||||
static void objreport(struct object *obj, const char *severity,
|
||||
const char *err, va_list params)
|
||||
static void objreport(struct object *obj, const char *msg_type,
|
||||
const char *err)
|
||||
{
|
||||
fprintf(stderr, "%s in %s %s: ",
|
||||
severity, typename(obj->type), sha1_to_hex(obj->sha1));
|
||||
vfprintf(stderr, err, params);
|
||||
fputs("\n", stderr);
|
||||
fprintf(stderr, "%s in %s %s: %s\n",
|
||||
msg_type, typename(obj->type), sha1_to_hex(obj->sha1), err);
|
||||
}
|
||||
|
||||
__attribute__((format (printf, 2, 3)))
|
||||
static int objerror(struct object *obj, const char *err, ...)
|
||||
static int objerror(struct object *obj, const char *err)
|
||||
{
|
||||
va_list params;
|
||||
va_start(params, err);
|
||||
errors_found |= ERROR_OBJECT;
|
||||
objreport(obj, "error", err, params);
|
||||
va_end(params);
|
||||
objreport(obj, "error", err);
|
||||
return -1;
|
||||
}
|
||||
|
||||
__attribute__((format (printf, 3, 4)))
|
||||
static int fsck_error_func(struct object *obj, int type, const char *err, ...)
|
||||
static int fsck_error_func(struct object *obj, int type, const char *message)
|
||||
{
|
||||
va_list params;
|
||||
va_start(params, err);
|
||||
objreport(obj, (type == FSCK_WARN) ? "warning" : "error", err, params);
|
||||
va_end(params);
|
||||
objreport(obj, (type == FSCK_WARN) ? "warning" : "error", message);
|
||||
return (type == FSCK_WARN) ? 0 : 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user