8 /* for internal use only */
12 /* "public", fed to e.g. error_func callbacks */
18 * Documentation/fsck-msgids.txt documents these; when
19 * modifying this list in any way, make sure to keep the
23 #define FOREACH_FSCK_MSG_ID(FUNC) \
25 FUNC(NUL_IN_HEADER, FATAL) \
26 FUNC(UNTERMINATED_HEADER, FATAL) \
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_CONTENT, ERROR) \
35 FUNC(BAD_REF_FILETYPE, ERROR) \
36 FUNC(BAD_REF_NAME, ERROR) \
37 FUNC(BAD_REFERENT_NAME, ERROR) \
38 FUNC(BAD_TIMEZONE, ERROR) \
39 FUNC(BAD_TREE, ERROR) \
40 FUNC(BAD_TREE_SHA1, ERROR) \
41 FUNC(BAD_TYPE, ERROR) \
42 FUNC(DUPLICATE_ENTRIES, ERROR) \
43 FUNC(MISSING_AUTHOR, ERROR) \
44 FUNC(MISSING_COMMITTER, ERROR) \
45 FUNC(MISSING_EMAIL, ERROR) \
46 FUNC(MISSING_NAME_BEFORE_EMAIL, ERROR) \
47 FUNC(MISSING_OBJECT, ERROR) \
48 FUNC(MISSING_SPACE_BEFORE_DATE, ERROR) \
49 FUNC(MISSING_SPACE_BEFORE_EMAIL, ERROR) \
50 FUNC(MISSING_TAG, ERROR) \
51 FUNC(MISSING_TAG_ENTRY, ERROR) \
52 FUNC(MISSING_TREE, ERROR) \
53 FUNC(MISSING_TYPE, ERROR) \
54 FUNC(MISSING_TYPE_ENTRY, ERROR) \
55 FUNC(MULTIPLE_AUTHORS, ERROR) \
56 FUNC(TREE_NOT_SORTED, ERROR) \
57 FUNC(UNKNOWN_TYPE, ERROR) \
58 FUNC(ZERO_PADDED_DATE, ERROR) \
59 FUNC(GITMODULES_MISSING, ERROR) \
60 FUNC(GITMODULES_BLOB, ERROR) \
61 FUNC(GITMODULES_LARGE, ERROR) \
62 FUNC(GITMODULES_NAME, ERROR) \
63 FUNC(GITMODULES_SYMLINK, ERROR) \
64 FUNC(GITMODULES_URL, ERROR) \
65 FUNC(GITMODULES_PATH, ERROR) \
66 FUNC(GITMODULES_UPDATE, ERROR) \
67 FUNC(GITATTRIBUTES_MISSING, ERROR) \
68 FUNC(GITATTRIBUTES_LARGE, ERROR) \
69 FUNC(GITATTRIBUTES_LINE_LENGTH, ERROR) \
70 FUNC(GITATTRIBUTES_BLOB, ERROR) \
72 FUNC(EMPTY_NAME, WARN) \
73 FUNC(FULL_PATHNAME, WARN) \
75 FUNC(HAS_DOTDOT, WARN) \
76 FUNC(HAS_DOTGIT, WARN) \
77 FUNC(NULL_SHA1, WARN) \
78 FUNC(ZERO_PADDED_FILEMODE, WARN) \
79 FUNC(NUL_IN_COMMIT, WARN) \
80 FUNC(LARGE_PATHNAME, WARN) \
81 /* infos (reported as warnings, but ignored by default) */ \
82 FUNC(BAD_FILEMODE, INFO) \
83 FUNC(GITMODULES_PARSE, INFO) \
84 FUNC(GITIGNORE_SYMLINK, INFO) \
85 FUNC(GITATTRIBUTES_SYMLINK, INFO) \
86 FUNC(MAILMAP_SYMLINK, INFO) \
87 FUNC(BAD_TAG_NAME, INFO) \
88 FUNC(MISSING_TAGGER_ENTRY, INFO) \
89 FUNC(SYMLINK_REF, INFO) \
90 FUNC(REF_MISSING_NEWLINE, INFO) \
91 FUNC(SYMREF_TARGET_IS_NOT_A_REF, INFO) \
92 FUNC(TRAILING_REF_CONTENT, INFO) \
93 /* ignored (elevated when requested) */ \
94 FUNC(EXTRA_HEADER_ENTRY, IGNORE)
96 #define MSG_ID(id, msg_type) FSCK_MSG_##id,
98 FOREACH_FSCK_MSG_ID(MSG_ID
)
106 void fsck_set_msg_type_from_ids(struct fsck_options
*options
,
107 enum fsck_msg_id msg_id
,
108 enum fsck_msg_type msg_type
);
109 void fsck_set_msg_type(struct fsck_options
*options
,
110 const char *msg_id
, const char *msg_type
);
111 void fsck_set_msg_types(struct fsck_options
*options
, const char *values
);
112 int is_valid_msg_type(const char *msg_id
, const char *msg_type
);
115 * callback function for fsck_walk
116 * type is the expected type of the object or OBJ_ANY
117 * the return value is:
119 * <0 error signaled and abort
120 * >0 error signaled and do not abort
122 typedef int (*fsck_walk_func
)(struct object
*obj
, enum object_type object_type
,
123 void *data
, struct fsck_options
*options
);
126 * Callback for reporting errors either for objects or refs. The "fsck_report"
127 * is a generic pointer that can be used to pass any information.
129 typedef int (*fsck_error
)(struct fsck_options
*o
,
131 enum fsck_msg_type msg_type
, enum fsck_msg_id msg_id
,
132 const char *message
);
134 int fsck_objects_error_function(struct fsck_options
*o
,
136 enum fsck_msg_type msg_type
, enum fsck_msg_id msg_id
,
137 const char *message
);
138 int fsck_objects_error_cb_print_missing_gitmodules(struct fsck_options
*o
,
140 enum fsck_msg_type msg_type
,
141 enum fsck_msg_id msg_id
,
142 const char *message
);
144 int fsck_refs_error_function(struct fsck_options
*options
,
146 enum fsck_msg_type msg_type
,
147 enum fsck_msg_id msg_id
,
148 const char *message
);
150 struct fsck_object_report
{
151 const struct object_id
*oid
;
152 enum object_type object_type
;
155 struct fsck_ref_report
{
157 const struct object_id
*oid
;
158 const char *referent
;
161 struct fsck_options
{
163 fsck_error error_func
;
166 enum fsck_msg_type
*msg_type
;
167 struct oidset skip_oids
;
168 struct oidset gitmodules_found
;
169 struct oidset gitmodules_done
;
170 struct oidset gitattributes_found
;
171 struct oidset gitattributes_done
;
172 kh_oid_map_t
*object_names
;
175 #define FSCK_OPTIONS_DEFAULT { \
176 .skip_oids = OIDSET_INIT, \
177 .gitmodules_found = OIDSET_INIT, \
178 .gitmodules_done = OIDSET_INIT, \
179 .gitattributes_found = OIDSET_INIT, \
180 .gitattributes_done = OIDSET_INIT, \
181 .error_func = fsck_objects_error_function \
183 #define FSCK_OPTIONS_STRICT { \
185 .gitmodules_found = OIDSET_INIT, \
186 .gitmodules_done = OIDSET_INIT, \
187 .gitattributes_found = OIDSET_INIT, \
188 .gitattributes_done = OIDSET_INIT, \
189 .error_func = fsck_objects_error_function, \
191 #define FSCK_OPTIONS_MISSING_GITMODULES { \
193 .gitmodules_found = OIDSET_INIT, \
194 .gitmodules_done = OIDSET_INIT, \
195 .gitattributes_found = OIDSET_INIT, \
196 .gitattributes_done = OIDSET_INIT, \
197 .error_func = fsck_objects_error_cb_print_missing_gitmodules, \
199 #define FSCK_REFS_OPTIONS_DEFAULT { \
200 .error_func = fsck_refs_error_function, \
203 /* descend in all linked child objects
204 * the return value is:
205 * -1 error in processing the object
206 * <0 return value of the callback, which lead to an abort
207 * >0 return value of the first signaled error >0 (in the case of no other errors)
210 int fsck_walk(struct object
*obj
, void *data
, struct fsck_options
*options
);
213 * Blob objects my pass a NULL data pointer, which indicates they are too large
214 * to fit in memory. All other types must pass a real buffer.
216 int fsck_object(struct object
*obj
, void *data
, unsigned long size
,
217 struct fsck_options
*options
);
220 * Same as fsck_object(), but for when the caller doesn't have an object
223 int fsck_buffer(const struct object_id
*oid
, enum object_type
,
224 const void *data
, unsigned long size
,
225 struct fsck_options
*options
);
228 * fsck a tag, and pass info about it back to the caller. This is
229 * exposed fsck_object() internals for git-mktag(1).
231 int fsck_tag_standalone(const struct object_id
*oid
, const char *buffer
,
232 unsigned long size
, struct fsck_options
*options
,
233 struct object_id
*tagged_oid
,
237 * Some fsck checks are context-dependent, and may end up queued; run this
238 * after completing all fsck_object() calls in order to resolve any remaining
241 int fsck_finish(struct fsck_options
*options
);
244 * Clear the fsck_options struct, freeing any allocated memory.
246 void fsck_options_clear(struct fsck_options
*options
);
249 * Report an error or warning for refs.
251 __attribute__((format (printf
, 4, 5)))
252 int fsck_report_ref(struct fsck_options
*options
,
253 struct fsck_ref_report
*report
,
254 enum fsck_msg_id msg_id
,
255 const char *fmt
, ...);
259 * Subsystem for storing human-readable names for each object.
261 * If fsck_enable_object_names() has not been called, all other functions are
264 * Use fsck_put_object_name() to seed initial names (e.g. from refnames); the
265 * fsck code will extend that while walking trees, etc.
267 * Use fsck_get_object_name() to get a single name (or NULL if none). Or the
268 * more convenient describe_object(), which always produces an output string
269 * with the oid combined with the name (if any). Note that the return value
270 * points to a rotating array of static buffers, and may be invalidated by a
273 void fsck_enable_object_names(struct fsck_options
*options
);
274 const char *fsck_get_object_name(struct fsck_options
*options
,
275 const struct object_id
*oid
);
276 __attribute__((format (printf
,3,4)))
277 void fsck_put_object_name(struct fsck_options
*options
,
278 const struct object_id
*oid
,
279 const char *fmt
, ...);
280 const char *fsck_describe_object(struct fsck_options
*options
,
281 const struct object_id
*oid
);
283 struct key_value_info
;
285 * git_config() callback for use by fsck-y tools that want to support
286 * fsck.<msg> fsck.skipList etc.
288 int git_fsck_config(const char *var
, const char *value
,
289 const struct config_context
*ctx
, void *cb
);