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