зеркало из https://github.com/microsoft/git.git
add common fsck error printing function
Signed-off-by: Martin Koegler <mkoegler@auto.tuwien.ac.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Родитель
ba002f3b28
Коммит
d6ffc8d784
29
fsck.c
29
fsck.c
|
@ -304,3 +304,32 @@ int fsck_object(struct object *obj, int strict, fsck_error error_func)
|
|||
return error_func(obj, FSCK_ERROR, "unknown type '%d' (internal fsck error)",
|
||||
obj->type);
|
||||
}
|
||||
|
||||
int fsck_error_function(struct object *obj, int type, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int len;
|
||||
struct strbuf sb;
|
||||
|
||||
strbuf_init(&sb, 0);
|
||||
strbuf_addf(&sb, "object %s:", obj->sha1?sha1_to_hex(obj->sha1):"(null)");
|
||||
|
||||
va_start(ap, fmt);
|
||||
len = vsnprintf(sb.buf + sb.len, strbuf_avail(&sb), fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
if (len < 0)
|
||||
len = 0;
|
||||
if (len >= strbuf_avail(&sb)) {
|
||||
strbuf_grow(&sb, len + 2);
|
||||
va_start(ap, fmt);
|
||||
len = vsnprintf(sb.buf + sb.len, strbuf_avail(&sb), fmt, ap);
|
||||
va_end(ap);
|
||||
if (len >= strbuf_avail(&sb))
|
||||
die("this should not happen, your snprintf is broken");
|
||||
}
|
||||
|
||||
error(sb.buf);
|
||||
strbuf_release(&sb);
|
||||
return 1;
|
||||
}
|
||||
|
|
2
fsck.h
2
fsck.h
|
@ -17,6 +17,8 @@ typedef int (*fsck_walk_func)(struct object *obj, int type, void *data);
|
|||
/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */
|
||||
typedef int (*fsck_error)(struct object *obj, int type, const char *err, ...);
|
||||
|
||||
int fsck_error_function(struct object *obj, int type, const char *fmt, ...);
|
||||
|
||||
/* descend in all linked child objects
|
||||
* the return value is:
|
||||
* -1 error in processing the object
|
||||
|
|
Загрузка…
Ссылка в новой задаче