diff options
author | Martin Koegler <mkoegler@auto.tuwien.ac.at> | 2008-02-25 22:46:09 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2008-02-25 23:57:35 -0800 |
commit | d6ffc8d784d41977397a49ce5333cfe7db1e9c2c (patch) | |
tree | 5d9c63ed4d3798f9273b8f08b2d3ccf5ce7a208b /fsck.c | |
parent | ba002f3b28ab9febea432d4c415dbe581836d9a0 (diff) | |
download | git-d6ffc8d784d41977397a49ce5333cfe7db1e9c2c.tar.gz |
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>
Diffstat (limited to 'fsck.c')
-rw-r--r-- | fsck.c | 29 |
1 files changed, 29 insertions, 0 deletions
@@ -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; +} |