]> git.ipfire.org Git - thirdparty/git.git/blame - fsck.h
The sixth 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 17/*
c09c29b4 18 * Documentation/fsck-msgids.adoc documents these; when
f6534dbd
JC
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) \
e6ba4c07 33 FUNC(BAD_PACKED_REF_ENTRY, ERROR) \
c92e7e15 34 FUNC(BAD_PACKED_REF_HEADER, ERROR) \
44e07da8 35 FUNC(BAD_PARENT_SHA1, ERROR) \
824aa541 36 FUNC(BAD_REF_CONTENT, ERROR) \
a7600b84 37 FUNC(BAD_REF_FILETYPE, ERROR) \
1c31be45 38 FUNC(BAD_REF_NAME, ERROR) \
a6354e60 39 FUNC(BAD_REFERENT_NAME, ERROR) \
44e07da8
ÆAB
40 FUNC(BAD_TIMEZONE, ERROR) \
41 FUNC(BAD_TREE, ERROR) \
42 FUNC(BAD_TREE_SHA1, ERROR) \
43 FUNC(BAD_TYPE, ERROR) \
44 FUNC(DUPLICATE_ENTRIES, ERROR) \
45 FUNC(MISSING_AUTHOR, ERROR) \
46 FUNC(MISSING_COMMITTER, ERROR) \
47 FUNC(MISSING_EMAIL, ERROR) \
48 FUNC(MISSING_NAME_BEFORE_EMAIL, ERROR) \
49 FUNC(MISSING_OBJECT, ERROR) \
50 FUNC(MISSING_SPACE_BEFORE_DATE, ERROR) \
51 FUNC(MISSING_SPACE_BEFORE_EMAIL, ERROR) \
52 FUNC(MISSING_TAG, ERROR) \
53 FUNC(MISSING_TAG_ENTRY, ERROR) \
54 FUNC(MISSING_TREE, ERROR) \
44e07da8
ÆAB
55 FUNC(MISSING_TYPE, ERROR) \
56 FUNC(MISSING_TYPE_ENTRY, ERROR) \
57 FUNC(MULTIPLE_AUTHORS, ERROR) \
c92e7e15 58 FUNC(PACKED_REF_ENTRY_NOT_TERMINATED, ERROR) \
e1c9548e 59 FUNC(PACKED_REF_UNSORTED, ERROR) \
44e07da8
ÆAB
60 FUNC(TREE_NOT_SORTED, ERROR) \
61 FUNC(UNKNOWN_TYPE, ERROR) \
62 FUNC(ZERO_PADDED_DATE, ERROR) \
63 FUNC(GITMODULES_MISSING, ERROR) \
64 FUNC(GITMODULES_BLOB, ERROR) \
65 FUNC(GITMODULES_LARGE, ERROR) \
66 FUNC(GITMODULES_NAME, ERROR) \
67 FUNC(GITMODULES_SYMLINK, ERROR) \
68 FUNC(GITMODULES_URL, ERROR) \
69 FUNC(GITMODULES_PATH, ERROR) \
70 FUNC(GITMODULES_UPDATE, ERROR) \
27ab4784
PS
71 FUNC(GITATTRIBUTES_MISSING, ERROR) \
72 FUNC(GITATTRIBUTES_LARGE, ERROR) \
73 FUNC(GITATTRIBUTES_LINE_LENGTH, ERROR) \
74 FUNC(GITATTRIBUTES_BLOB, ERROR) \
44e07da8 75 /* warnings */ \
44e07da8
ÆAB
76 FUNC(EMPTY_NAME, WARN) \
77 FUNC(FULL_PATHNAME, WARN) \
78 FUNC(HAS_DOT, WARN) \
79 FUNC(HAS_DOTDOT, WARN) \
80 FUNC(HAS_DOTGIT, WARN) \
81 FUNC(NULL_SHA1, WARN) \
82 FUNC(ZERO_PADDED_FILEMODE, WARN) \
83 FUNC(NUL_IN_COMMIT, WARN) \
0fbcaef6 84 FUNC(LARGE_PATHNAME, WARN) \
44e07da8 85 /* infos (reported as warnings, but ignored by default) */ \
4dd3b045 86 FUNC(BAD_FILEMODE, INFO) \
784ceccb 87 FUNC(EMPTY_PACKED_REFS_FILE, INFO) \
44e07da8 88 FUNC(GITMODULES_PARSE, INFO) \
bb6832d5
JK
89 FUNC(GITIGNORE_SYMLINK, INFO) \
90 FUNC(GITATTRIBUTES_SYMLINK, INFO) \
91 FUNC(MAILMAP_SYMLINK, INFO) \
44e07da8
ÆAB
92 FUNC(BAD_TAG_NAME, INFO) \
93 FUNC(MISSING_TAGGER_ENTRY, INFO) \
c9f03f38 94 FUNC(SYMLINK_REF, INFO) \
1c0e2a00 95 FUNC(REF_MISSING_NEWLINE, INFO) \
d996b447 96 FUNC(SYMREF_TARGET_IS_NOT_A_REF, INFO) \
1c0e2a00 97 FUNC(TRAILING_REF_CONTENT, INFO) \
44e07da8
ÆAB
98 /* ignored (elevated when requested) */ \
99 FUNC(EXTRA_HEADER_ENTRY, IGNORE)
100
101#define MSG_ID(id, msg_type) FSCK_MSG_##id,
102enum fsck_msg_id {
103 FOREACH_FSCK_MSG_ID(MSG_ID)
104 FSCK_MSG_MAX
105};
106#undef MSG_ID
107
22410549 108struct fsck_options;
ef3ca954 109struct object;
22410549 110
53692df2
ÆAB
111void fsck_set_msg_type_from_ids(struct fsck_options *options,
112 enum fsck_msg_id msg_id,
113 enum fsck_msg_type msg_type);
0282f4dc 114void fsck_set_msg_type(struct fsck_options *options,
f1abc2d0 115 const char *msg_id, const char *msg_type);
0282f4dc 116void fsck_set_msg_types(struct fsck_options *options, const char *values);
5d477a33 117int is_valid_msg_type(const char *msg_id, const char *msg_type);
0282f4dc 118
355885d5
MK
119/*
120 * callback function for fsck_walk
121 * type is the expected type of the object or OBJ_ANY
122 * the return value is:
123 * 0 everything OK
124 * <0 error signaled and abort
125 * >0 error signaled and do not abort
126 */
a1aad716
ÆAB
127typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type,
128 void *data, struct fsck_options *options);
355885d5 129
0ec5dfe8 130/*
131 * Callback for reporting errors either for objects or refs. The "fsck_report"
132 * is a generic pointer that can be used to pass any information.
133 */
1cd772cc 134typedef int (*fsck_error)(struct fsck_options *o,
0ec5dfe8 135 void *fsck_report,
394d5d31
ÆAB
136 enum fsck_msg_type msg_type, enum fsck_msg_id msg_id,
137 const char *message);
ba002f3b 138
8cd4a447 139int fsck_objects_error_function(struct fsck_options *o,
0ec5dfe8 140 void *fsck_report,
8cd4a447 141 enum fsck_msg_type msg_type, enum fsck_msg_id msg_id,
142 const char *message);
143int fsck_objects_error_cb_print_missing_gitmodules(struct fsck_options *o,
0ec5dfe8 144 void *fsck_report,
8cd4a447 145 enum fsck_msg_type msg_type,
146 enum fsck_msg_id msg_id,
147 const char *message);
d6ffc8d7 148
2de307cd 149int fsck_refs_error_function(struct fsck_options *options,
150 void *fsck_report,
151 enum fsck_msg_type msg_type,
152 enum fsck_msg_id msg_id,
153 const char *message);
154
0ec5dfe8 155struct fsck_object_report {
156 const struct object_id *oid;
157 enum object_type object_type;
158};
159
2de307cd 160struct fsck_ref_report {
161 const char *path;
162 const struct object_id *oid;
163 const char *referent;
164};
165
22410549
JS
166struct fsck_options {
167 fsck_walk_func walk;
168 fsck_error error_func;
bf061d26 169 unsigned strict;
170 unsigned verbose;
1b32b59f 171 enum fsck_msg_type *msg_type;
2d79aa90 172 struct oidset skip_oids;
c15087d1
ÆAB
173 struct oidset gitmodules_found;
174 struct oidset gitmodules_done;
27ab4784
PS
175 struct oidset gitattributes_found;
176 struct oidset gitattributes_done;
73390290 177 kh_oid_map_t *object_names;
22410549
JS
178};
179
d385784f 180#define FSCK_OPTIONS_DEFAULT { \
2d79aa90 181 .skip_oids = OIDSET_INIT, \
c15087d1
ÆAB
182 .gitmodules_found = OIDSET_INIT, \
183 .gitmodules_done = OIDSET_INIT, \
27ab4784
PS
184 .gitattributes_found = OIDSET_INIT, \
185 .gitattributes_done = OIDSET_INIT, \
8cd4a447 186 .error_func = fsck_objects_error_function \
d385784f
ÆAB
187}
188#define FSCK_OPTIONS_STRICT { \
189 .strict = 1, \
c15087d1
ÆAB
190 .gitmodules_found = OIDSET_INIT, \
191 .gitmodules_done = OIDSET_INIT, \
27ab4784
PS
192 .gitattributes_found = OIDSET_INIT, \
193 .gitattributes_done = OIDSET_INIT, \
8cd4a447 194 .error_func = fsck_objects_error_function, \
d385784f 195}
3745e269
ÆAB
196#define FSCK_OPTIONS_MISSING_GITMODULES { \
197 .strict = 1, \
198 .gitmodules_found = OIDSET_INIT, \
199 .gitmodules_done = OIDSET_INIT, \
27ab4784
PS
200 .gitattributes_found = OIDSET_INIT, \
201 .gitattributes_done = OIDSET_INIT, \
8cd4a447 202 .error_func = fsck_objects_error_cb_print_missing_gitmodules, \
3745e269 203}
2de307cd 204#define FSCK_REFS_OPTIONS_DEFAULT { \
205 .error_func = fsck_refs_error_function, \
206}
22410549 207
355885d5
MK
208/* descend in all linked child objects
209 * the return value is:
210 * -1 error in processing the object
211 * <0 return value of the callback, which lead to an abort
3ea3c215 212 * >0 return value of the first signaled error >0 (in the case of no other errors)
355885d5
MK
213 * 0 everything OK
214 */
22410549 215int fsck_walk(struct object *obj, void *data, struct fsck_options *options);
23a173a7
JK
216
217/*
218 * Blob objects my pass a NULL data pointer, which indicates they are too large
219 * to fit in memory. All other types must pass a real buffer.
220 */
90a398bb 221int fsck_object(struct object *obj, void *data, unsigned long size,
22410549 222 struct fsck_options *options);
355885d5 223
35ff327e
JK
224/*
225 * Same as fsck_object(), but for when the caller doesn't have an object
226 * struct.
227 */
228int fsck_buffer(const struct object_id *oid, enum object_type,
b567004b 229 const void *data, unsigned long size,
35ff327e
JK
230 struct fsck_options *options);
231
acf9de4c
ÆAB
232/*
233 * fsck a tag, and pass info about it back to the caller. This is
234 * exposed fsck_object() internals for git-mktag(1).
235 */
236int fsck_tag_standalone(const struct object_id *oid, const char *buffer,
237 unsigned long size, struct fsck_options *options,
238 struct object_id *tagged_oid,
239 int *tag_type);
240
159e7b08
JK
241/*
242 * Some fsck checks are context-dependent, and may end up queued; run this
243 * after completing all fsck_object() calls in order to resolve any remaining
244 * checks.
245 */
246int fsck_finish(struct fsck_options *options);
247
bf061d26 248/*
249 * Clear the fsck_options struct, freeing any allocated memory.
250 */
251void fsck_options_clear(struct fsck_options *options);
252
2de307cd 253/*
254 * Report an error or warning for refs.
255 */
256__attribute__((format (printf, 4, 5)))
257int fsck_report_ref(struct fsck_options *options,
258 struct fsck_ref_report *report,
259 enum fsck_msg_id msg_id,
260 const char *fmt, ...);
261
262
a59cfb32
JK
263/*
264 * Subsystem for storing human-readable names for each object.
265 *
266 * If fsck_enable_object_names() has not been called, all other functions are
267 * noops.
268 *
269 * Use fsck_put_object_name() to seed initial names (e.g. from refnames); the
270 * fsck code will extend that while walking trees, etc.
271 *
272 * Use fsck_get_object_name() to get a single name (or NULL if none). Or the
273 * more convenient describe_object(), which always produces an output string
274 * with the oid combined with the name (if any). Note that the return value
275 * points to a rotating array of static buffers, and may be invalidated by a
276 * subsequent call.
277 */
278void fsck_enable_object_names(struct fsck_options *options);
279const char *fsck_get_object_name(struct fsck_options *options,
73390290 280 const struct object_id *oid);
a59cfb32 281__attribute__((format (printf,3,4)))
73390290
JK
282void fsck_put_object_name(struct fsck_options *options,
283 const struct object_id *oid,
a59cfb32
JK
284 const char *fmt, ...);
285const char *fsck_describe_object(struct fsck_options *options,
73390290 286 const struct object_id *oid);
a59cfb32 287
a4e7e317 288struct key_value_info;
1f3299fd
ÆAB
289/*
290 * git_config() callback for use by fsck-y tools that want to support
291 * fsck.<msg> fsck.skipList etc.
292 */
a4e7e317
GC
293int git_fsck_config(const char *var, const char *value,
294 const struct config_context *ctx, void *cb);
1f3299fd 295
355885d5 296#endif