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