fetch: pass the full local reference name to `format_display`
[alt-git.git] / fsck.h
blob668330880ef65f72ba4e9d38487152cc28c205a1
1 #ifndef GIT_FSCK_H
2 #define GIT_FSCK_H
4 #include "oidset.h"
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,
17 * Documentation/fsck-msgids.txt documents these; when
18 * modifying this list in any way, make sure to keep the
19 * two in sync.
22 #define FOREACH_FSCK_MSG_ID(FUNC) \
23 /* fatal errors */ \
24 FUNC(NUL_IN_HEADER, FATAL) \
25 FUNC(UNTERMINATED_HEADER, FATAL) \
26 /* errors */ \
27 FUNC(BAD_DATE, ERROR) \
28 FUNC(BAD_DATE_OVERFLOW, ERROR) \
29 FUNC(BAD_EMAIL, ERROR) \
30 FUNC(BAD_NAME, ERROR) \
31 FUNC(BAD_OBJECT_SHA1, ERROR) \
32 FUNC(BAD_PARENT_SHA1, ERROR) \
33 FUNC(BAD_TIMEZONE, ERROR) \
34 FUNC(BAD_TREE, ERROR) \
35 FUNC(BAD_TREE_SHA1, ERROR) \
36 FUNC(BAD_TYPE, ERROR) \
37 FUNC(DUPLICATE_ENTRIES, ERROR) \
38 FUNC(MISSING_AUTHOR, ERROR) \
39 FUNC(MISSING_COMMITTER, ERROR) \
40 FUNC(MISSING_EMAIL, ERROR) \
41 FUNC(MISSING_NAME_BEFORE_EMAIL, ERROR) \
42 FUNC(MISSING_OBJECT, ERROR) \
43 FUNC(MISSING_SPACE_BEFORE_DATE, ERROR) \
44 FUNC(MISSING_SPACE_BEFORE_EMAIL, ERROR) \
45 FUNC(MISSING_TAG, ERROR) \
46 FUNC(MISSING_TAG_ENTRY, ERROR) \
47 FUNC(MISSING_TREE, ERROR) \
48 FUNC(MISSING_TYPE, ERROR) \
49 FUNC(MISSING_TYPE_ENTRY, ERROR) \
50 FUNC(MULTIPLE_AUTHORS, ERROR) \
51 FUNC(TREE_NOT_SORTED, ERROR) \
52 FUNC(UNKNOWN_TYPE, ERROR) \
53 FUNC(ZERO_PADDED_DATE, ERROR) \
54 FUNC(GITMODULES_MISSING, ERROR) \
55 FUNC(GITMODULES_BLOB, ERROR) \
56 FUNC(GITMODULES_LARGE, ERROR) \
57 FUNC(GITMODULES_NAME, ERROR) \
58 FUNC(GITMODULES_SYMLINK, ERROR) \
59 FUNC(GITMODULES_URL, ERROR) \
60 FUNC(GITMODULES_PATH, ERROR) \
61 FUNC(GITMODULES_UPDATE, ERROR) \
62 FUNC(GITATTRIBUTES_MISSING, ERROR) \
63 FUNC(GITATTRIBUTES_LARGE, ERROR) \
64 FUNC(GITATTRIBUTES_LINE_LENGTH, ERROR) \
65 FUNC(GITATTRIBUTES_BLOB, ERROR) \
66 /* warnings */ \
67 FUNC(EMPTY_NAME, WARN) \
68 FUNC(FULL_PATHNAME, WARN) \
69 FUNC(HAS_DOT, WARN) \
70 FUNC(HAS_DOTDOT, WARN) \
71 FUNC(HAS_DOTGIT, WARN) \
72 FUNC(NULL_SHA1, WARN) \
73 FUNC(ZERO_PADDED_FILEMODE, WARN) \
74 FUNC(NUL_IN_COMMIT, WARN) \
75 /* infos (reported as warnings, but ignored by default) */ \
76 FUNC(BAD_FILEMODE, INFO) \
77 FUNC(GITMODULES_PARSE, INFO) \
78 FUNC(GITIGNORE_SYMLINK, INFO) \
79 FUNC(GITATTRIBUTES_SYMLINK, INFO) \
80 FUNC(MAILMAP_SYMLINK, INFO) \
81 FUNC(BAD_TAG_NAME, INFO) \
82 FUNC(MISSING_TAGGER_ENTRY, INFO) \
83 /* ignored (elevated when requested) */ \
84 FUNC(EXTRA_HEADER_ENTRY, IGNORE)
86 #define MSG_ID(id, msg_type) FSCK_MSG_##id,
87 enum fsck_msg_id {
88 FOREACH_FSCK_MSG_ID(MSG_ID)
89 FSCK_MSG_MAX
91 #undef MSG_ID
93 struct fsck_options;
94 struct object;
96 void fsck_set_msg_type_from_ids(struct fsck_options *options,
97 enum fsck_msg_id msg_id,
98 enum fsck_msg_type msg_type);
99 void fsck_set_msg_type(struct fsck_options *options,
100 const char *msg_id, const char *msg_type);
101 void fsck_set_msg_types(struct fsck_options *options, const char *values);
102 int is_valid_msg_type(const char *msg_id, const char *msg_type);
105 * callback function for fsck_walk
106 * type is the expected type of the object or OBJ_ANY
107 * the return value is:
108 * 0 everything OK
109 * <0 error signaled and abort
110 * >0 error signaled and do not abort
112 typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type,
113 void *data, struct fsck_options *options);
115 /* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */
116 typedef int (*fsck_error)(struct fsck_options *o,
117 const struct object_id *oid, enum object_type object_type,
118 enum fsck_msg_type msg_type, enum fsck_msg_id msg_id,
119 const char *message);
121 int fsck_error_function(struct fsck_options *o,
122 const struct object_id *oid, enum object_type object_type,
123 enum fsck_msg_type msg_type, enum fsck_msg_id msg_id,
124 const char *message);
125 int fsck_error_cb_print_missing_gitmodules(struct fsck_options *o,
126 const struct object_id *oid,
127 enum object_type object_type,
128 enum fsck_msg_type msg_type,
129 enum fsck_msg_id msg_id,
130 const char *message);
132 struct fsck_options {
133 fsck_walk_func walk;
134 fsck_error error_func;
135 unsigned strict:1;
136 enum fsck_msg_type *msg_type;
137 struct oidset skiplist;
138 struct oidset gitmodules_found;
139 struct oidset gitmodules_done;
140 struct oidset gitattributes_found;
141 struct oidset gitattributes_done;
142 kh_oid_map_t *object_names;
145 #define FSCK_OPTIONS_DEFAULT { \
146 .skiplist = OIDSET_INIT, \
147 .gitmodules_found = OIDSET_INIT, \
148 .gitmodules_done = OIDSET_INIT, \
149 .gitattributes_found = OIDSET_INIT, \
150 .gitattributes_done = OIDSET_INIT, \
151 .error_func = fsck_error_function \
153 #define FSCK_OPTIONS_STRICT { \
154 .strict = 1, \
155 .gitmodules_found = OIDSET_INIT, \
156 .gitmodules_done = OIDSET_INIT, \
157 .gitattributes_found = OIDSET_INIT, \
158 .gitattributes_done = OIDSET_INIT, \
159 .error_func = fsck_error_function, \
161 #define FSCK_OPTIONS_MISSING_GITMODULES { \
162 .strict = 1, \
163 .gitmodules_found = OIDSET_INIT, \
164 .gitmodules_done = OIDSET_INIT, \
165 .gitattributes_found = OIDSET_INIT, \
166 .gitattributes_done = OIDSET_INIT, \
167 .error_func = fsck_error_cb_print_missing_gitmodules, \
170 /* descend in all linked child objects
171 * the return value is:
172 * -1 error in processing the object
173 * <0 return value of the callback, which lead to an abort
174 * >0 return value of the first signaled error >0 (in the case of no other errors)
175 * 0 everything OK
177 int fsck_walk(struct object *obj, void *data, struct fsck_options *options);
180 * Blob objects my pass a NULL data pointer, which indicates they are too large
181 * to fit in memory. All other types must pass a real buffer.
183 int fsck_object(struct object *obj, void *data, unsigned long size,
184 struct fsck_options *options);
187 * Same as fsck_object(), but for when the caller doesn't have an object
188 * struct.
190 int fsck_buffer(const struct object_id *oid, enum object_type,
191 void *data, unsigned long size,
192 struct fsck_options *options);
195 * fsck a tag, and pass info about it back to the caller. This is
196 * exposed fsck_object() internals for git-mktag(1).
198 int fsck_tag_standalone(const struct object_id *oid, const char *buffer,
199 unsigned long size, struct fsck_options *options,
200 struct object_id *tagged_oid,
201 int *tag_type);
204 * Some fsck checks are context-dependent, and may end up queued; run this
205 * after completing all fsck_object() calls in order to resolve any remaining
206 * checks.
208 int fsck_finish(struct fsck_options *options);
211 * Subsystem for storing human-readable names for each object.
213 * If fsck_enable_object_names() has not been called, all other functions are
214 * noops.
216 * Use fsck_put_object_name() to seed initial names (e.g. from refnames); the
217 * fsck code will extend that while walking trees, etc.
219 * Use fsck_get_object_name() to get a single name (or NULL if none). Or the
220 * more convenient describe_object(), which always produces an output string
221 * with the oid combined with the name (if any). Note that the return value
222 * points to a rotating array of static buffers, and may be invalidated by a
223 * subsequent call.
225 void fsck_enable_object_names(struct fsck_options *options);
226 const char *fsck_get_object_name(struct fsck_options *options,
227 const struct object_id *oid);
228 __attribute__((format (printf,3,4)))
229 void fsck_put_object_name(struct fsck_options *options,
230 const struct object_id *oid,
231 const char *fmt, ...);
232 const char *fsck_describe_object(struct fsck_options *options,
233 const struct object_id *oid);
236 * git_config() callback for use by fsck-y tools that want to support
237 * fsck.<msg> fsck.skipList etc.
239 int git_fsck_config(const char *var, const char *value, void *cb);
241 #endif