]> git.ipfire.org Git - thirdparty/git.git/blame - fsck.h
The fourth batch
[thirdparty/git.git] / fsck.h
CommitLineData
355885d5
MK
1#ifndef GIT_FSCK_H
2#define GIT_FSCK_H
3
a64215b6 4#include "object.h"
3b41fb0c
RS
5#include "oidset.h"
6
1b32b59f 7enum fsck_msg_type {
30cf618e
ÆAB
8 /* for internal use only */
9 FSCK_IGNORE,
10 FSCK_INFO,
11 FSCK_FATAL,
12 /* "public", fed to e.g. error_func callbacks */
13 FSCK_ERROR,
1b32b59f 14 FSCK_WARN,
1b32b59f 15};
ba002f3b 16
f6534dbd
JC
17/*
18 * Documentation/fsck-msgids.txt documents these; when
19 * modifying this list in any way, make sure to keep the
20 * two in sync.
21 */
22
44e07da8
ÆAB
23#define FOREACH_FSCK_MSG_ID(FUNC) \
24 /* fatal errors */ \
25 FUNC(NUL_IN_HEADER, FATAL) \
26 FUNC(UNTERMINATED_HEADER, FATAL) \
27 /* errors */ \
28 FUNC(BAD_DATE, ERROR) \
29 FUNC(BAD_DATE_OVERFLOW, ERROR) \
30 FUNC(BAD_EMAIL, ERROR) \
31 FUNC(BAD_NAME, ERROR) \
32 FUNC(BAD_OBJECT_SHA1, ERROR) \
33 FUNC(BAD_PARENT_SHA1, ERROR) \
44e07da8
ÆAB
34 FUNC(BAD_TIMEZONE, ERROR) \
35 FUNC(BAD_TREE, ERROR) \
36 FUNC(BAD_TREE_SHA1, ERROR) \
37 FUNC(BAD_TYPE, ERROR) \
38 FUNC(DUPLICATE_ENTRIES, ERROR) \
39 FUNC(MISSING_AUTHOR, ERROR) \
40 FUNC(MISSING_COMMITTER, ERROR) \
41 FUNC(MISSING_EMAIL, ERROR) \
42 FUNC(MISSING_NAME_BEFORE_EMAIL, ERROR) \
43 FUNC(MISSING_OBJECT, ERROR) \
44 FUNC(MISSING_SPACE_BEFORE_DATE, ERROR) \
45 FUNC(MISSING_SPACE_BEFORE_EMAIL, ERROR) \
46 FUNC(MISSING_TAG, ERROR) \
47 FUNC(MISSING_TAG_ENTRY, ERROR) \
48 FUNC(MISSING_TREE, ERROR) \
44e07da8
ÆAB
49 FUNC(MISSING_TYPE, ERROR) \
50 FUNC(MISSING_TYPE_ENTRY, ERROR) \
51 FUNC(MULTIPLE_AUTHORS, ERROR) \
52 FUNC(TREE_NOT_SORTED, ERROR) \
53 FUNC(UNKNOWN_TYPE, ERROR) \
54 FUNC(ZERO_PADDED_DATE, ERROR) \
55 FUNC(GITMODULES_MISSING, ERROR) \
56 FUNC(GITMODULES_BLOB, ERROR) \
57 FUNC(GITMODULES_LARGE, ERROR) \
58 FUNC(GITMODULES_NAME, ERROR) \
59 FUNC(GITMODULES_SYMLINK, ERROR) \
60 FUNC(GITMODULES_URL, ERROR) \
61 FUNC(GITMODULES_PATH, ERROR) \
62 FUNC(GITMODULES_UPDATE, ERROR) \
27ab4784
PS
63 FUNC(GITATTRIBUTES_MISSING, ERROR) \
64 FUNC(GITATTRIBUTES_LARGE, ERROR) \
65 FUNC(GITATTRIBUTES_LINE_LENGTH, ERROR) \
66 FUNC(GITATTRIBUTES_BLOB, ERROR) \
a33fea08
JS
67 FUNC(SYMLINK_TARGET_MISSING, ERROR) \
68 FUNC(SYMLINK_TARGET_BLOB, ERROR) \
44e07da8 69 /* warnings */ \
44e07da8
ÆAB
70 FUNC(EMPTY_NAME, WARN) \
71 FUNC(FULL_PATHNAME, WARN) \
72 FUNC(HAS_DOT, WARN) \
73 FUNC(HAS_DOTDOT, WARN) \
74 FUNC(HAS_DOTGIT, WARN) \
75 FUNC(NULL_SHA1, WARN) \
76 FUNC(ZERO_PADDED_FILEMODE, WARN) \
77 FUNC(NUL_IN_COMMIT, WARN) \
0fbcaef6 78 FUNC(LARGE_PATHNAME, WARN) \
a33fea08
JS
79 FUNC(SYMLINK_TARGET_LENGTH, WARN) \
80 FUNC(SYMLINK_POINTS_TO_GIT_DIR, WARN) \
44e07da8 81 /* infos (reported as warnings, but ignored by default) */ \
4dd3b045 82 FUNC(BAD_FILEMODE, INFO) \
44e07da8 83 FUNC(GITMODULES_PARSE, INFO) \
bb6832d5
JK
84 FUNC(GITIGNORE_SYMLINK, INFO) \
85 FUNC(GITATTRIBUTES_SYMLINK, INFO) \
86 FUNC(MAILMAP_SYMLINK, INFO) \
44e07da8
ÆAB
87 FUNC(BAD_TAG_NAME, INFO) \
88 FUNC(MISSING_TAGGER_ENTRY, INFO) \
89 /* ignored (elevated when requested) */ \
90 FUNC(EXTRA_HEADER_ENTRY, IGNORE)
91
92#define MSG_ID(id, msg_type) FSCK_MSG_##id,
93enum fsck_msg_id {
94 FOREACH_FSCK_MSG_ID(MSG_ID)
95 FSCK_MSG_MAX
96};
97#undef MSG_ID
98
22410549 99struct fsck_options;
ef3ca954 100struct object;
22410549 101
53692df2
ÆAB
102void fsck_set_msg_type_from_ids(struct fsck_options *options,
103 enum fsck_msg_id msg_id,
104 enum fsck_msg_type msg_type);
0282f4dc 105void fsck_set_msg_type(struct fsck_options *options,
f1abc2d0 106 const char *msg_id, const char *msg_type);
0282f4dc 107void fsck_set_msg_types(struct fsck_options *options, const char *values);
5d477a33 108int is_valid_msg_type(const char *msg_id, const char *msg_type);
0282f4dc 109
355885d5
MK
110/*
111 * callback function for fsck_walk
112 * type is the expected type of the object or OBJ_ANY
113 * the return value is:
114 * 0 everything OK
115 * <0 error signaled and abort
116 * >0 error signaled and do not abort
117 */
a1aad716
ÆAB
118typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type,
119 void *data, struct fsck_options *options);
355885d5 120
ba002f3b 121/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */
1cd772cc 122typedef int (*fsck_error)(struct fsck_options *o,
5afc4b1d 123 const struct object_id *oid, enum object_type object_type,
394d5d31
ÆAB
124 enum fsck_msg_type msg_type, enum fsck_msg_id msg_id,
125 const char *message);
ba002f3b 126
1cd772cc 127int fsck_error_function(struct fsck_options *o,
5afc4b1d 128 const struct object_id *oid, enum object_type object_type,
394d5d31
ÆAB
129 enum fsck_msg_type msg_type, enum fsck_msg_id msg_id,
130 const char *message);
3745e269
ÆAB
131int fsck_error_cb_print_missing_gitmodules(struct fsck_options *o,
132 const struct object_id *oid,
133 enum object_type object_type,
134 enum fsck_msg_type msg_type,
135 enum fsck_msg_id msg_id,
136 const char *message);
d6ffc8d7 137
22410549
JS
138struct fsck_options {
139 fsck_walk_func walk;
140 fsck_error error_func;
141 unsigned strict:1;
1b32b59f 142 enum fsck_msg_type *msg_type;
3b41fb0c 143 struct oidset skiplist;
c15087d1
ÆAB
144 struct oidset gitmodules_found;
145 struct oidset gitmodules_done;
27ab4784
PS
146 struct oidset gitattributes_found;
147 struct oidset gitattributes_done;
a33fea08
JS
148 struct oidset symlink_targets_found;
149 struct oidset symlink_targets_done;
73390290 150 kh_oid_map_t *object_names;
22410549
JS
151};
152
d385784f
ÆAB
153#define FSCK_OPTIONS_DEFAULT { \
154 .skiplist = OIDSET_INIT, \
c15087d1
ÆAB
155 .gitmodules_found = OIDSET_INIT, \
156 .gitmodules_done = OIDSET_INIT, \
27ab4784
PS
157 .gitattributes_found = OIDSET_INIT, \
158 .gitattributes_done = OIDSET_INIT, \
a33fea08
JS
159 .symlink_targets_found = OIDSET_INIT, \
160 .symlink_targets_done = OIDSET_INIT, \
d385784f
ÆAB
161 .error_func = fsck_error_function \
162}
163#define FSCK_OPTIONS_STRICT { \
164 .strict = 1, \
c15087d1
ÆAB
165 .gitmodules_found = OIDSET_INIT, \
166 .gitmodules_done = OIDSET_INIT, \
27ab4784
PS
167 .gitattributes_found = OIDSET_INIT, \
168 .gitattributes_done = OIDSET_INIT, \
a33fea08
JS
169 .symlink_targets_found = OIDSET_INIT, \
170 .symlink_targets_done = OIDSET_INIT, \
d385784f
ÆAB
171 .error_func = fsck_error_function, \
172}
3745e269
ÆAB
173#define FSCK_OPTIONS_MISSING_GITMODULES { \
174 .strict = 1, \
175 .gitmodules_found = OIDSET_INIT, \
176 .gitmodules_done = OIDSET_INIT, \
27ab4784
PS
177 .gitattributes_found = OIDSET_INIT, \
178 .gitattributes_done = OIDSET_INIT, \
a33fea08
JS
179 .symlink_targets_found = OIDSET_INIT, \
180 .symlink_targets_done = OIDSET_INIT, \
3745e269
ÆAB
181 .error_func = fsck_error_cb_print_missing_gitmodules, \
182}
22410549 183
355885d5
MK
184/* descend in all linked child objects
185 * the return value is:
186 * -1 error in processing the object
187 * <0 return value of the callback, which lead to an abort
3ea3c215 188 * >0 return value of the first signaled error >0 (in the case of no other errors)
355885d5
MK
189 * 0 everything OK
190 */
22410549 191int fsck_walk(struct object *obj, void *data, struct fsck_options *options);
23a173a7
JK
192
193/*
194 * Blob objects my pass a NULL data pointer, which indicates they are too large
195 * to fit in memory. All other types must pass a real buffer.
196 */
90a398bb 197int fsck_object(struct object *obj, void *data, unsigned long size,
22410549 198 struct fsck_options *options);
355885d5 199
35ff327e
JK
200/*
201 * Same as fsck_object(), but for when the caller doesn't have an object
202 * struct.
203 */
204int fsck_buffer(const struct object_id *oid, enum object_type,
205 void *data, unsigned long size,
206 struct fsck_options *options);
207
acf9de4c
ÆAB
208/*
209 * fsck a tag, and pass info about it back to the caller. This is
210 * exposed fsck_object() internals for git-mktag(1).
211 */
212int fsck_tag_standalone(const struct object_id *oid, const char *buffer,
213 unsigned long size, struct fsck_options *options,
214 struct object_id *tagged_oid,
215 int *tag_type);
216
159e7b08
JK
217/*
218 * Some fsck checks are context-dependent, and may end up queued; run this
219 * after completing all fsck_object() calls in order to resolve any remaining
220 * checks.
221 */
222int fsck_finish(struct fsck_options *options);
223
a59cfb32
JK
224/*
225 * Subsystem for storing human-readable names for each object.
226 *
227 * If fsck_enable_object_names() has not been called, all other functions are
228 * noops.
229 *
230 * Use fsck_put_object_name() to seed initial names (e.g. from refnames); the
231 * fsck code will extend that while walking trees, etc.
232 *
233 * Use fsck_get_object_name() to get a single name (or NULL if none). Or the
234 * more convenient describe_object(), which always produces an output string
235 * with the oid combined with the name (if any). Note that the return value
236 * points to a rotating array of static buffers, and may be invalidated by a
237 * subsequent call.
238 */
239void fsck_enable_object_names(struct fsck_options *options);
240const char *fsck_get_object_name(struct fsck_options *options,
73390290 241 const struct object_id *oid);
a59cfb32 242__attribute__((format (printf,3,4)))
73390290
JK
243void fsck_put_object_name(struct fsck_options *options,
244 const struct object_id *oid,
a59cfb32
JK
245 const char *fmt, ...);
246const char *fsck_describe_object(struct fsck_options *options,
73390290 247 const struct object_id *oid);
a59cfb32 248
a4e7e317 249struct key_value_info;
1f3299fd
ÆAB
250/*
251 * git_config() callback for use by fsck-y tools that want to support
252 * fsck.<msg> fsck.skipList etc.
253 */
a4e7e317
GC
254int git_fsck_config(const char *var, const char *value,
255 const struct config_context *ctx, void *cb);
1f3299fd 256
355885d5 257#endif