fsck.c: give "FOREACH_MSG_ID" a more specific name
[git/debian.git] / fsck.h
bloba7e092d3fb4f4c1c59d5f691872e2aedb71e5c26
1 #ifndef GIT_FSCK_H
2 #define GIT_FSCK_H
4 #include "oidset.h"
6 enum fsck_msg_type {
7 /* for internal use only */
8 FSCK_IGNORE,
9 FSCK_INFO,
10 FSCK_FATAL,
11 /* "public", fed to e.g. error_func callbacks */
12 FSCK_ERROR,
13 FSCK_WARN,
16 struct fsck_options;
17 struct object;
19 void fsck_set_msg_type(struct fsck_options *options,
20 const char *msg_id, const char *msg_type);
21 void fsck_set_msg_types(struct fsck_options *options, const char *values);
22 int is_valid_msg_type(const char *msg_id, const char *msg_type);
25 * callback function for fsck_walk
26 * type is the expected type of the object or OBJ_ANY
27 * the return value is:
28 * 0 everything OK
29 * <0 error signaled and abort
30 * >0 error signaled and do not abort
32 typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type,
33 void *data, struct fsck_options *options);
35 /* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */
36 typedef int (*fsck_error)(struct fsck_options *o,
37 const struct object_id *oid, enum object_type object_type,
38 enum fsck_msg_type msg_type, const char *message);
40 int fsck_error_function(struct fsck_options *o,
41 const struct object_id *oid, enum object_type object_type,
42 enum fsck_msg_type msg_type, const char *message);
44 struct fsck_options {
45 fsck_walk_func walk;
46 fsck_error error_func;
47 unsigned strict:1;
48 enum fsck_msg_type *msg_type;
49 struct oidset skiplist;
50 kh_oid_map_t *object_names;
53 #define FSCK_OPTIONS_DEFAULT { \
54 .skiplist = OIDSET_INIT, \
55 .error_func = fsck_error_function \
57 #define FSCK_OPTIONS_STRICT { \
58 .strict = 1, \
59 .error_func = fsck_error_function, \
62 /* descend in all linked child objects
63 * the return value is:
64 * -1 error in processing the object
65 * <0 return value of the callback, which lead to an abort
66 * >0 return value of the first signaled error >0 (in the case of no other errors)
67 * 0 everything OK
69 int fsck_walk(struct object *obj, void *data, struct fsck_options *options);
72 * Blob objects my pass a NULL data pointer, which indicates they are too large
73 * to fit in memory. All other types must pass a real buffer.
75 int fsck_object(struct object *obj, void *data, unsigned long size,
76 struct fsck_options *options);
78 void register_found_gitmodules(const struct object_id *oid);
81 * fsck a tag, and pass info about it back to the caller. This is
82 * exposed fsck_object() internals for git-mktag(1).
84 int fsck_tag_standalone(const struct object_id *oid, const char *buffer,
85 unsigned long size, struct fsck_options *options,
86 struct object_id *tagged_oid,
87 int *tag_type);
90 * Some fsck checks are context-dependent, and may end up queued; run this
91 * after completing all fsck_object() calls in order to resolve any remaining
92 * checks.
94 int fsck_finish(struct fsck_options *options);
97 * Subsystem for storing human-readable names for each object.
99 * If fsck_enable_object_names() has not been called, all other functions are
100 * noops.
102 * Use fsck_put_object_name() to seed initial names (e.g. from refnames); the
103 * fsck code will extend that while walking trees, etc.
105 * Use fsck_get_object_name() to get a single name (or NULL if none). Or the
106 * more convenient describe_object(), which always produces an output string
107 * with the oid combined with the name (if any). Note that the return value
108 * points to a rotating array of static buffers, and may be invalidated by a
109 * subsequent call.
111 void fsck_enable_object_names(struct fsck_options *options);
112 const char *fsck_get_object_name(struct fsck_options *options,
113 const struct object_id *oid);
114 __attribute__((format (printf,3,4)))
115 void fsck_put_object_name(struct fsck_options *options,
116 const struct object_id *oid,
117 const char *fmt, ...);
118 const char *fsck_describe_object(struct fsck_options *options,
119 const struct object_id *oid);
122 * git_config() callback for use by fsck-y tools that want to support
123 * fsck.<msg> fsck.skipList etc.
125 int git_fsck_config(const char *var, const char *value, void *cb);
127 #endif