]> git.ipfire.org Git - thirdparty/git.git/blob - fsck.h
fsck.c: add an fsck_set_msg_type() API that takes enums
[thirdparty/git.git] / fsck.h
1 #ifndef GIT_FSCK_H
2 #define GIT_FSCK_H
3
4 #include "oidset.h"
5
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,
14 };
15
16 #define FOREACH_FSCK_MSG_ID(FUNC) \
17 /* fatal errors */ \
18 FUNC(NUL_IN_HEADER, FATAL) \
19 FUNC(UNTERMINATED_HEADER, FATAL) \
20 /* errors */ \
21 FUNC(BAD_DATE, ERROR) \
22 FUNC(BAD_DATE_OVERFLOW, ERROR) \
23 FUNC(BAD_EMAIL, ERROR) \
24 FUNC(BAD_NAME, ERROR) \
25 FUNC(BAD_OBJECT_SHA1, ERROR) \
26 FUNC(BAD_PARENT_SHA1, ERROR) \
27 FUNC(BAD_TAG_OBJECT, ERROR) \
28 FUNC(BAD_TIMEZONE, ERROR) \
29 FUNC(BAD_TREE, ERROR) \
30 FUNC(BAD_TREE_SHA1, ERROR) \
31 FUNC(BAD_TYPE, ERROR) \
32 FUNC(DUPLICATE_ENTRIES, ERROR) \
33 FUNC(MISSING_AUTHOR, ERROR) \
34 FUNC(MISSING_COMMITTER, ERROR) \
35 FUNC(MISSING_EMAIL, ERROR) \
36 FUNC(MISSING_NAME_BEFORE_EMAIL, ERROR) \
37 FUNC(MISSING_OBJECT, ERROR) \
38 FUNC(MISSING_SPACE_BEFORE_DATE, ERROR) \
39 FUNC(MISSING_SPACE_BEFORE_EMAIL, ERROR) \
40 FUNC(MISSING_TAG, ERROR) \
41 FUNC(MISSING_TAG_ENTRY, ERROR) \
42 FUNC(MISSING_TREE, ERROR) \
43 FUNC(MISSING_TREE_OBJECT, ERROR) \
44 FUNC(MISSING_TYPE, ERROR) \
45 FUNC(MISSING_TYPE_ENTRY, ERROR) \
46 FUNC(MULTIPLE_AUTHORS, ERROR) \
47 FUNC(TREE_NOT_SORTED, ERROR) \
48 FUNC(UNKNOWN_TYPE, ERROR) \
49 FUNC(ZERO_PADDED_DATE, ERROR) \
50 FUNC(GITMODULES_MISSING, ERROR) \
51 FUNC(GITMODULES_BLOB, ERROR) \
52 FUNC(GITMODULES_LARGE, ERROR) \
53 FUNC(GITMODULES_NAME, ERROR) \
54 FUNC(GITMODULES_SYMLINK, ERROR) \
55 FUNC(GITMODULES_URL, ERROR) \
56 FUNC(GITMODULES_PATH, ERROR) \
57 FUNC(GITMODULES_UPDATE, ERROR) \
58 /* warnings */ \
59 FUNC(BAD_FILEMODE, WARN) \
60 FUNC(EMPTY_NAME, WARN) \
61 FUNC(FULL_PATHNAME, WARN) \
62 FUNC(HAS_DOT, WARN) \
63 FUNC(HAS_DOTDOT, WARN) \
64 FUNC(HAS_DOTGIT, WARN) \
65 FUNC(NULL_SHA1, WARN) \
66 FUNC(ZERO_PADDED_FILEMODE, WARN) \
67 FUNC(NUL_IN_COMMIT, WARN) \
68 /* infos (reported as warnings, but ignored by default) */ \
69 FUNC(GITMODULES_PARSE, INFO) \
70 FUNC(BAD_TAG_NAME, INFO) \
71 FUNC(MISSING_TAGGER_ENTRY, INFO) \
72 /* ignored (elevated when requested) */ \
73 FUNC(EXTRA_HEADER_ENTRY, IGNORE)
74
75 #define MSG_ID(id, msg_type) FSCK_MSG_##id,
76 enum fsck_msg_id {
77 FOREACH_FSCK_MSG_ID(MSG_ID)
78 FSCK_MSG_MAX
79 };
80 #undef MSG_ID
81
82 struct fsck_options;
83 struct object;
84
85 void fsck_set_msg_type_from_ids(struct fsck_options *options,
86 enum fsck_msg_id msg_id,
87 enum fsck_msg_type msg_type);
88 void fsck_set_msg_type(struct fsck_options *options,
89 const char *msg_id, const char *msg_type);
90 void fsck_set_msg_types(struct fsck_options *options, const char *values);
91 int is_valid_msg_type(const char *msg_id, const char *msg_type);
92
93 /*
94 * callback function for fsck_walk
95 * type is the expected type of the object or OBJ_ANY
96 * the return value is:
97 * 0 everything OK
98 * <0 error signaled and abort
99 * >0 error signaled and do not abort
100 */
101 typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type,
102 void *data, struct fsck_options *options);
103
104 /* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */
105 typedef int (*fsck_error)(struct fsck_options *o,
106 const struct object_id *oid, enum object_type object_type,
107 enum fsck_msg_type msg_type, enum fsck_msg_id msg_id,
108 const char *message);
109
110 int fsck_error_function(struct fsck_options *o,
111 const struct object_id *oid, enum object_type object_type,
112 enum fsck_msg_type msg_type, enum fsck_msg_id msg_id,
113 const char *message);
114
115 struct fsck_options {
116 fsck_walk_func walk;
117 fsck_error error_func;
118 unsigned strict:1;
119 enum fsck_msg_type *msg_type;
120 struct oidset skiplist;
121 kh_oid_map_t *object_names;
122 };
123
124 #define FSCK_OPTIONS_DEFAULT { \
125 .skiplist = OIDSET_INIT, \
126 .error_func = fsck_error_function \
127 }
128 #define FSCK_OPTIONS_STRICT { \
129 .strict = 1, \
130 .error_func = fsck_error_function, \
131 }
132
133 /* descend in all linked child objects
134 * the return value is:
135 * -1 error in processing the object
136 * <0 return value of the callback, which lead to an abort
137 * >0 return value of the first signaled error >0 (in the case of no other errors)
138 * 0 everything OK
139 */
140 int fsck_walk(struct object *obj, void *data, struct fsck_options *options);
141
142 /*
143 * Blob objects my pass a NULL data pointer, which indicates they are too large
144 * to fit in memory. All other types must pass a real buffer.
145 */
146 int fsck_object(struct object *obj, void *data, unsigned long size,
147 struct fsck_options *options);
148
149 void register_found_gitmodules(const struct object_id *oid);
150
151 /*
152 * fsck a tag, and pass info about it back to the caller. This is
153 * exposed fsck_object() internals for git-mktag(1).
154 */
155 int fsck_tag_standalone(const struct object_id *oid, const char *buffer,
156 unsigned long size, struct fsck_options *options,
157 struct object_id *tagged_oid,
158 int *tag_type);
159
160 /*
161 * Some fsck checks are context-dependent, and may end up queued; run this
162 * after completing all fsck_object() calls in order to resolve any remaining
163 * checks.
164 */
165 int fsck_finish(struct fsck_options *options);
166
167 /*
168 * Subsystem for storing human-readable names for each object.
169 *
170 * If fsck_enable_object_names() has not been called, all other functions are
171 * noops.
172 *
173 * Use fsck_put_object_name() to seed initial names (e.g. from refnames); the
174 * fsck code will extend that while walking trees, etc.
175 *
176 * Use fsck_get_object_name() to get a single name (or NULL if none). Or the
177 * more convenient describe_object(), which always produces an output string
178 * with the oid combined with the name (if any). Note that the return value
179 * points to a rotating array of static buffers, and may be invalidated by a
180 * subsequent call.
181 */
182 void fsck_enable_object_names(struct fsck_options *options);
183 const char *fsck_get_object_name(struct fsck_options *options,
184 const struct object_id *oid);
185 __attribute__((format (printf,3,4)))
186 void fsck_put_object_name(struct fsck_options *options,
187 const struct object_id *oid,
188 const char *fmt, ...);
189 const char *fsck_describe_object(struct fsck_options *options,
190 const struct object_id *oid);
191
192 /*
193 * git_config() callback for use by fsck-y tools that want to support
194 * fsck.<msg> fsck.skipList etc.
195 */
196 int git_fsck_config(const char *var, const char *value, void *cb);
197
198 #endif