Merge branch 'ja/doc-synopsis-markup'
[git/gitster.git] / fsck.h
blob500b4c04d2cbf26fecc0b16ff9b4907fe56b4fc4
1 #ifndef GIT_FSCK_H
2 #define GIT_FSCK_H
4 #include "object.h"
5 #include "oidset.h"
7 enum fsck_msg_type {
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,
14 FSCK_WARN,
18 * Documentation/fsck-msgids.txt documents these; when
19 * modifying this list in any way, make sure to keep the
20 * two in sync.
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) \
34 FUNC(BAD_REF_FILETYPE, ERROR) \
35 FUNC(BAD_REF_NAME, ERROR) \
36 FUNC(BAD_TIMEZONE, ERROR) \
37 FUNC(BAD_TREE, ERROR) \
38 FUNC(BAD_TREE_SHA1, ERROR) \
39 FUNC(BAD_TYPE, ERROR) \
40 FUNC(DUPLICATE_ENTRIES, ERROR) \
41 FUNC(MISSING_AUTHOR, ERROR) \
42 FUNC(MISSING_COMMITTER, ERROR) \
43 FUNC(MISSING_EMAIL, ERROR) \
44 FUNC(MISSING_NAME_BEFORE_EMAIL, ERROR) \
45 FUNC(MISSING_OBJECT, ERROR) \
46 FUNC(MISSING_SPACE_BEFORE_DATE, ERROR) \
47 FUNC(MISSING_SPACE_BEFORE_EMAIL, ERROR) \
48 FUNC(MISSING_TAG, ERROR) \
49 FUNC(MISSING_TAG_ENTRY, ERROR) \
50 FUNC(MISSING_TREE, ERROR) \
51 FUNC(MISSING_TYPE, ERROR) \
52 FUNC(MISSING_TYPE_ENTRY, ERROR) \
53 FUNC(MULTIPLE_AUTHORS, ERROR) \
54 FUNC(TREE_NOT_SORTED, ERROR) \
55 FUNC(UNKNOWN_TYPE, ERROR) \
56 FUNC(ZERO_PADDED_DATE, ERROR) \
57 FUNC(GITMODULES_MISSING, ERROR) \
58 FUNC(GITMODULES_BLOB, ERROR) \
59 FUNC(GITMODULES_LARGE, ERROR) \
60 FUNC(GITMODULES_NAME, ERROR) \
61 FUNC(GITMODULES_SYMLINK, ERROR) \
62 FUNC(GITMODULES_URL, ERROR) \
63 FUNC(GITMODULES_PATH, ERROR) \
64 FUNC(GITMODULES_UPDATE, ERROR) \
65 FUNC(GITATTRIBUTES_MISSING, ERROR) \
66 FUNC(GITATTRIBUTES_LARGE, ERROR) \
67 FUNC(GITATTRIBUTES_LINE_LENGTH, ERROR) \
68 FUNC(GITATTRIBUTES_BLOB, ERROR) \
69 /* warnings */ \
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) \
78 FUNC(LARGE_PATHNAME, WARN) \
79 /* infos (reported as warnings, but ignored by default) */ \
80 FUNC(BAD_FILEMODE, INFO) \
81 FUNC(GITMODULES_PARSE, INFO) \
82 FUNC(GITIGNORE_SYMLINK, INFO) \
83 FUNC(GITATTRIBUTES_SYMLINK, INFO) \
84 FUNC(MAILMAP_SYMLINK, INFO) \
85 FUNC(BAD_TAG_NAME, INFO) \
86 FUNC(MISSING_TAGGER_ENTRY, INFO) \
87 /* ignored (elevated when requested) */ \
88 FUNC(EXTRA_HEADER_ENTRY, IGNORE)
90 #define MSG_ID(id, msg_type) FSCK_MSG_##id,
91 enum fsck_msg_id {
92 FOREACH_FSCK_MSG_ID(MSG_ID)
93 FSCK_MSG_MAX
95 #undef MSG_ID
97 struct fsck_options;
98 struct object;
100 void fsck_set_msg_type_from_ids(struct fsck_options *options,
101 enum fsck_msg_id msg_id,
102 enum fsck_msg_type msg_type);
103 void fsck_set_msg_type(struct fsck_options *options,
104 const char *msg_id, const char *msg_type);
105 void fsck_set_msg_types(struct fsck_options *options, const char *values);
106 int is_valid_msg_type(const char *msg_id, const char *msg_type);
109 * callback function for fsck_walk
110 * type is the expected type of the object or OBJ_ANY
111 * the return value is:
112 * 0 everything OK
113 * <0 error signaled and abort
114 * >0 error signaled and do not abort
116 typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type,
117 void *data, struct fsck_options *options);
120 * Callback for reporting errors either for objects or refs. The "fsck_report"
121 * is a generic pointer that can be used to pass any information.
123 typedef int (*fsck_error)(struct fsck_options *o,
124 void *fsck_report,
125 enum fsck_msg_type msg_type, enum fsck_msg_id msg_id,
126 const char *message);
128 int fsck_objects_error_function(struct fsck_options *o,
129 void *fsck_report,
130 enum fsck_msg_type msg_type, enum fsck_msg_id msg_id,
131 const char *message);
132 int fsck_objects_error_cb_print_missing_gitmodules(struct fsck_options *o,
133 void *fsck_report,
134 enum fsck_msg_type msg_type,
135 enum fsck_msg_id msg_id,
136 const char *message);
138 int fsck_refs_error_function(struct fsck_options *options,
139 void *fsck_report,
140 enum fsck_msg_type msg_type,
141 enum fsck_msg_id msg_id,
142 const char *message);
144 struct fsck_object_report {
145 const struct object_id *oid;
146 enum object_type object_type;
149 struct fsck_ref_report {
150 const char *path;
151 const struct object_id *oid;
152 const char *referent;
155 struct fsck_options {
156 fsck_walk_func walk;
157 fsck_error error_func;
158 unsigned strict;
159 unsigned verbose;
160 enum fsck_msg_type *msg_type;
161 struct oidset skip_oids;
162 struct oidset gitmodules_found;
163 struct oidset gitmodules_done;
164 struct oidset gitattributes_found;
165 struct oidset gitattributes_done;
166 kh_oid_map_t *object_names;
169 #define FSCK_OPTIONS_DEFAULT { \
170 .skip_oids = OIDSET_INIT, \
171 .gitmodules_found = OIDSET_INIT, \
172 .gitmodules_done = OIDSET_INIT, \
173 .gitattributes_found = OIDSET_INIT, \
174 .gitattributes_done = OIDSET_INIT, \
175 .error_func = fsck_objects_error_function \
177 #define FSCK_OPTIONS_STRICT { \
178 .strict = 1, \
179 .gitmodules_found = OIDSET_INIT, \
180 .gitmodules_done = OIDSET_INIT, \
181 .gitattributes_found = OIDSET_INIT, \
182 .gitattributes_done = OIDSET_INIT, \
183 .error_func = fsck_objects_error_function, \
185 #define FSCK_OPTIONS_MISSING_GITMODULES { \
186 .strict = 1, \
187 .gitmodules_found = OIDSET_INIT, \
188 .gitmodules_done = OIDSET_INIT, \
189 .gitattributes_found = OIDSET_INIT, \
190 .gitattributes_done = OIDSET_INIT, \
191 .error_func = fsck_objects_error_cb_print_missing_gitmodules, \
193 #define FSCK_REFS_OPTIONS_DEFAULT { \
194 .error_func = fsck_refs_error_function, \
197 /* descend in all linked child objects
198 * the return value is:
199 * -1 error in processing the object
200 * <0 return value of the callback, which lead to an abort
201 * >0 return value of the first signaled error >0 (in the case of no other errors)
202 * 0 everything OK
204 int fsck_walk(struct object *obj, void *data, struct fsck_options *options);
207 * Blob objects my pass a NULL data pointer, which indicates they are too large
208 * to fit in memory. All other types must pass a real buffer.
210 int fsck_object(struct object *obj, void *data, unsigned long size,
211 struct fsck_options *options);
214 * Same as fsck_object(), but for when the caller doesn't have an object
215 * struct.
217 int fsck_buffer(const struct object_id *oid, enum object_type,
218 const void *data, unsigned long size,
219 struct fsck_options *options);
222 * fsck a tag, and pass info about it back to the caller. This is
223 * exposed fsck_object() internals for git-mktag(1).
225 int fsck_tag_standalone(const struct object_id *oid, const char *buffer,
226 unsigned long size, struct fsck_options *options,
227 struct object_id *tagged_oid,
228 int *tag_type);
231 * Some fsck checks are context-dependent, and may end up queued; run this
232 * after completing all fsck_object() calls in order to resolve any remaining
233 * checks.
235 int fsck_finish(struct fsck_options *options);
238 * Clear the fsck_options struct, freeing any allocated memory.
240 void fsck_options_clear(struct fsck_options *options);
243 * Report an error or warning for refs.
245 __attribute__((format (printf, 4, 5)))
246 int fsck_report_ref(struct fsck_options *options,
247 struct fsck_ref_report *report,
248 enum fsck_msg_id msg_id,
249 const char *fmt, ...);
253 * Subsystem for storing human-readable names for each object.
255 * If fsck_enable_object_names() has not been called, all other functions are
256 * noops.
258 * Use fsck_put_object_name() to seed initial names (e.g. from refnames); the
259 * fsck code will extend that while walking trees, etc.
261 * Use fsck_get_object_name() to get a single name (or NULL if none). Or the
262 * more convenient describe_object(), which always produces an output string
263 * with the oid combined with the name (if any). Note that the return value
264 * points to a rotating array of static buffers, and may be invalidated by a
265 * subsequent call.
267 void fsck_enable_object_names(struct fsck_options *options);
268 const char *fsck_get_object_name(struct fsck_options *options,
269 const struct object_id *oid);
270 __attribute__((format (printf,3,4)))
271 void fsck_put_object_name(struct fsck_options *options,
272 const struct object_id *oid,
273 const char *fmt, ...);
274 const char *fsck_describe_object(struct fsck_options *options,
275 const struct object_id *oid);
277 struct key_value_info;
279 * git_config() callback for use by fsck-y tools that want to support
280 * fsck.<msg> fsck.skipList etc.
282 int git_fsck_config(const char *var, const char *value,
283 const struct config_context *ctx, void *cb);
285 #endif