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>
Martin Koegler committed
Feb 25, 2008 at 22:46 UTC
d6ffc8d784d41977397a49ce5333cfe7db1e9c2c
2 files changed
+31
fsck.c
+29
@@ -304,3 +304,32 @@ int fsck_object(struct object *obj, int strict, fsck_error error_func)
304
return error_func(obj, FSCK_ERROR, "unknown type '%d' (internal fsck error)",
305
obj->type);
306
}
307
+
308
+int fsck_error_function(struct object *obj, int type, const char *fmt, ...)
309
+{
310
+ va_list ap;
311
+ int len;
312
+ struct strbuf sb;
313
+
314
+ strbuf_init(&sb, 0);
315
+ strbuf_addf(&sb, "object %s:", obj->sha1?sha1_to_hex(obj->sha1):"(null)");
316
+
317
+ va_start(ap, fmt);
318
+ len = vsnprintf(sb.buf + sb.len, strbuf_avail(&sb), fmt, ap);
319
+ va_end(ap);
320
+
321
+ if (len < 0)
322
+ len = 0;
323
+ if (len >= strbuf_avail(&sb)) {
324
+ strbuf_grow(&sb, len + 2);
325
+ va_start(ap, fmt);
326
+ len = vsnprintf(sb.buf + sb.len, strbuf_avail(&sb), fmt, ap);
327
+ va_end(ap);
328
+ if (len >= strbuf_avail(&sb))
329
+ die("this should not happen, your snprintf is broken");
330
+ }
331
+
332
+ error(sb.buf);
333
+ strbuf_release(&sb);
334
+ return 1;
335
+}
fsck.h
+2
@@ -17,6 +17,8 @@ typedef int (*fsck_walk_func)(struct object *obj, int type, void *data);
17
/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */
18
typedef int (*fsck_error)(struct object *obj, int type, const char *err, ...);
19
20
+int fsck_error_function(struct object *obj, int type, const char *fmt, ...);
21
+
22
/* descend in all linked child objects
23
* the return value is:
24
* -1 error in processing the object