blob: 6f801e53b1d70ea9e522babbb119b913a7b32b62 [file] [log] [blame]
Martin Koegler355885d2008-02-25 22:46:04 +01001#ifndef GIT_FSCK_H
2#define GIT_FSCK_H
3
René Scharfe3b41fb02018-09-03 14:49:27 +00004#include "oidset.h"
5
Ævar Arnfjörð Bjarmason1b32b592021-03-28 15:15:40 +02006enum fsck_msg_type {
Ævar Arnfjörð Bjarmason30cf6182021-03-28 15:15:41 +02007 /* 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,
Ævar Arnfjörð Bjarmason1b32b592021-03-28 15:15:40 +020013 FSCK_WARN,
Ævar Arnfjörð Bjarmason1b32b592021-03-28 15:15:40 +020014};
Martin Koeglerba002f32008-02-25 22:46:08 +010015
Ævar Arnfjörð Bjarmason44e07da2021-03-28 15:15:45 +020016#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 */ \
Ævar Arnfjörð Bjarmason44e07da2021-03-28 15:15:45 +020059 FUNC(EMPTY_NAME, WARN) \
60 FUNC(FULL_PATHNAME, WARN) \
61 FUNC(HAS_DOT, WARN) \
62 FUNC(HAS_DOTDOT, WARN) \
63 FUNC(HAS_DOTGIT, WARN) \
64 FUNC(NULL_SHA1, WARN) \
65 FUNC(ZERO_PADDED_FILEMODE, WARN) \
66 FUNC(NUL_IN_COMMIT, WARN) \
67 /* infos (reported as warnings, but ignored by default) */ \
Jeff King4dd3b042022-08-10 17:04:07 -040068 FUNC(BAD_FILEMODE, INFO) \
Ævar Arnfjörð Bjarmason44e07da2021-03-28 15:15:45 +020069 FUNC(GITMODULES_PARSE, INFO) \
Jeff Kingbb6832d2021-05-03 16:43:25 -040070 FUNC(GITIGNORE_SYMLINK, INFO) \
71 FUNC(GITATTRIBUTES_SYMLINK, INFO) \
72 FUNC(MAILMAP_SYMLINK, INFO) \
Ævar Arnfjörð Bjarmason44e07da2021-03-28 15:15:45 +020073 FUNC(BAD_TAG_NAME, INFO) \
74 FUNC(MISSING_TAGGER_ENTRY, INFO) \
75 /* ignored (elevated when requested) */ \
76 FUNC(EXTRA_HEADER_ENTRY, IGNORE)
77
78#define MSG_ID(id, msg_type) FSCK_MSG_##id,
79enum fsck_msg_id {
80 FOREACH_FSCK_MSG_ID(MSG_ID)
81 FSCK_MSG_MAX
82};
83#undef MSG_ID
84
Johannes Schindelin22410542015-06-22 17:25:00 +020085struct fsck_options;
Elijah Newrenef3ca952018-08-15 10:54:05 -070086struct object;
Johannes Schindelin22410542015-06-22 17:25:00 +020087
Ævar Arnfjörð Bjarmason53692df2021-03-28 15:15:47 +020088void fsck_set_msg_type_from_ids(struct fsck_options *options,
89 enum fsck_msg_id msg_id,
90 enum fsck_msg_type msg_type);
Johannes Schindelin0282f4d2015-06-22 17:25:25 +020091void fsck_set_msg_type(struct fsck_options *options,
Ævar Arnfjörð Bjarmasonf1abc2d2021-03-28 15:15:36 +020092 const char *msg_id, const char *msg_type);
Johannes Schindelin0282f4d2015-06-22 17:25:25 +020093void fsck_set_msg_types(struct fsck_options *options, const char *values);
Johannes Schindelin5d477a32015-06-22 17:25:31 +020094int is_valid_msg_type(const char *msg_id, const char *msg_type);
Johannes Schindelin0282f4d2015-06-22 17:25:25 +020095
Martin Koegler355885d2008-02-25 22:46:04 +010096/*
97 * callback function for fsck_walk
98 * type is the expected type of the object or OBJ_ANY
99 * the return value is:
100 * 0 everything OK
101 * <0 error signaled and abort
102 * >0 error signaled and do not abort
103 */
Ævar Arnfjörð Bjarmasona1aad712021-03-28 15:15:35 +0200104typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type,
105 void *data, struct fsck_options *options);
Martin Koegler355885d2008-02-25 22:46:04 +0100106
Martin Koeglerba002f32008-02-25 22:46:08 +0100107/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */
Johannes Schindelin1cd772c2016-07-17 12:59:57 +0200108typedef int (*fsck_error)(struct fsck_options *o,
Jeff King5afc4b12019-10-18 00:58:40 -0400109 const struct object_id *oid, enum object_type object_type,
Ævar Arnfjörð Bjarmason394d5d32021-03-28 15:15:46 +0200110 enum fsck_msg_type msg_type, enum fsck_msg_id msg_id,
111 const char *message);
Martin Koeglerba002f32008-02-25 22:46:08 +0100112
Johannes Schindelin1cd772c2016-07-17 12:59:57 +0200113int fsck_error_function(struct fsck_options *o,
Jeff King5afc4b12019-10-18 00:58:40 -0400114 const struct object_id *oid, enum object_type object_type,
Ævar Arnfjörð Bjarmason394d5d32021-03-28 15:15:46 +0200115 enum fsck_msg_type msg_type, enum fsck_msg_id msg_id,
116 const char *message);
Ævar Arnfjörð Bjarmason3745e262021-03-28 15:15:51 +0200117int fsck_error_cb_print_missing_gitmodules(struct fsck_options *o,
118 const struct object_id *oid,
119 enum object_type object_type,
120 enum fsck_msg_type msg_type,
121 enum fsck_msg_id msg_id,
122 const char *message);
Martin Koeglerd6ffc8d2008-02-25 22:46:09 +0100123
Johannes Schindelin22410542015-06-22 17:25:00 +0200124struct fsck_options {
125 fsck_walk_func walk;
126 fsck_error error_func;
127 unsigned strict:1;
Ævar Arnfjörð Bjarmason1b32b592021-03-28 15:15:40 +0200128 enum fsck_msg_type *msg_type;
René Scharfe3b41fb02018-09-03 14:49:27 +0000129 struct oidset skiplist;
Ævar Arnfjörð Bjarmasonc15087d2021-03-28 15:15:48 +0200130 struct oidset gitmodules_found;
131 struct oidset gitmodules_done;
Jeff King73390292019-10-18 00:57:37 -0400132 kh_oid_map_t *object_names;
Johannes Schindelin22410542015-06-22 17:25:00 +0200133};
134
Ævar Arnfjörð Bjarmasond3857842021-03-28 15:15:34 +0200135#define FSCK_OPTIONS_DEFAULT { \
136 .skiplist = OIDSET_INIT, \
Ævar Arnfjörð Bjarmasonc15087d2021-03-28 15:15:48 +0200137 .gitmodules_found = OIDSET_INIT, \
138 .gitmodules_done = OIDSET_INIT, \
Ævar Arnfjörð Bjarmasond3857842021-03-28 15:15:34 +0200139 .error_func = fsck_error_function \
140}
141#define FSCK_OPTIONS_STRICT { \
142 .strict = 1, \
Ævar Arnfjörð Bjarmasonc15087d2021-03-28 15:15:48 +0200143 .gitmodules_found = OIDSET_INIT, \
144 .gitmodules_done = OIDSET_INIT, \
Ævar Arnfjörð Bjarmasond3857842021-03-28 15:15:34 +0200145 .error_func = fsck_error_function, \
146}
Ævar Arnfjörð Bjarmason3745e262021-03-28 15:15:51 +0200147#define FSCK_OPTIONS_MISSING_GITMODULES { \
148 .strict = 1, \
149 .gitmodules_found = OIDSET_INIT, \
150 .gitmodules_done = OIDSET_INIT, \
151 .error_func = fsck_error_cb_print_missing_gitmodules, \
152}
Johannes Schindelin22410542015-06-22 17:25:00 +0200153
Martin Koegler355885d2008-02-25 22:46:04 +0100154/* descend in all linked child objects
155 * the return value is:
156 * -1 error in processing the object
157 * <0 return value of the callback, which lead to an abort
Mike Ralphson3ea3c212009-04-17 19:13:30 +0100158 * >0 return value of the first signaled error >0 (in the case of no other errors)
Martin Koegler355885d2008-02-25 22:46:04 +0100159 * 0 everything OK
160 */
Johannes Schindelin22410542015-06-22 17:25:00 +0200161int fsck_walk(struct object *obj, void *data, struct fsck_options *options);
Jeff King23a173a2019-10-18 00:54:12 -0400162
163/*
164 * Blob objects my pass a NULL data pointer, which indicates they are too large
165 * to fit in memory. All other types must pass a real buffer.
166 */
Johannes Schindelin90a398b2014-09-10 15:52:51 +0200167int fsck_object(struct object *obj, void *data, unsigned long size,
Johannes Schindelin22410542015-06-22 17:25:00 +0200168 struct fsck_options *options);
Martin Koegler355885d2008-02-25 22:46:04 +0100169
Jeff King159e7b02018-05-02 17:20:08 -0400170/*
Ævar Arnfjörð Bjarmasonacf9de42021-01-05 20:42:46 +0100171 * fsck a tag, and pass info about it back to the caller. This is
172 * exposed fsck_object() internals for git-mktag(1).
173 */
174int fsck_tag_standalone(const struct object_id *oid, const char *buffer,
175 unsigned long size, struct fsck_options *options,
176 struct object_id *tagged_oid,
177 int *tag_type);
178
179/*
Jeff King159e7b02018-05-02 17:20:08 -0400180 * Some fsck checks are context-dependent, and may end up queued; run this
181 * after completing all fsck_object() calls in order to resolve any remaining
182 * checks.
183 */
184int fsck_finish(struct fsck_options *options);
185
Jeff Kinga59cfb32019-10-18 00:56:13 -0400186/*
187 * Subsystem for storing human-readable names for each object.
188 *
189 * If fsck_enable_object_names() has not been called, all other functions are
190 * noops.
191 *
192 * Use fsck_put_object_name() to seed initial names (e.g. from refnames); the
193 * fsck code will extend that while walking trees, etc.
194 *
195 * Use fsck_get_object_name() to get a single name (or NULL if none). Or the
196 * more convenient describe_object(), which always produces an output string
197 * with the oid combined with the name (if any). Note that the return value
198 * points to a rotating array of static buffers, and may be invalidated by a
199 * subsequent call.
200 */
201void fsck_enable_object_names(struct fsck_options *options);
202const char *fsck_get_object_name(struct fsck_options *options,
Jeff King73390292019-10-18 00:57:37 -0400203 const struct object_id *oid);
Jeff Kinga59cfb32019-10-18 00:56:13 -0400204__attribute__((format (printf,3,4)))
Jeff King73390292019-10-18 00:57:37 -0400205void fsck_put_object_name(struct fsck_options *options,
206 const struct object_id *oid,
Jeff Kinga59cfb32019-10-18 00:56:13 -0400207 const char *fmt, ...);
208const char *fsck_describe_object(struct fsck_options *options,
Jeff King73390292019-10-18 00:57:37 -0400209 const struct object_id *oid);
Jeff Kinga59cfb32019-10-18 00:56:13 -0400210
Ævar Arnfjörð Bjarmason1f3299f2021-01-05 20:42:47 +0100211/*
212 * git_config() callback for use by fsck-y tools that want to support
213 * fsck.<msg> fsck.skipList etc.
214 */
Ævar Arnfjörð Bjarmasonfb79f5b2021-03-17 19:20:36 +0100215int git_fsck_config(const char *var, const char *value, void *cb);
Ævar Arnfjörð Bjarmason1f3299f2021-01-05 20:42:47 +0100216
Martin Koegler355885d2008-02-25 22:46:04 +0100217#endif