]>
Commit | Line | Data |
---|---|---|
355885d5 MK |
1 | #ifndef GIT_FSCK_H |
2 | #define GIT_FSCK_H | |
3 | ||
3b41fb0c RS |
4 | #include "oidset.h" |
5 | ||
1b32b59f | 6 | enum fsck_msg_type { |
30cf618e ÆAB |
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, | |
1b32b59f | 13 | FSCK_WARN, |
1b32b59f | 14 | }; |
ba002f3b | 15 | |
f6534dbd JC |
16 | /* |
17 | * Documentation/fsck-msgids.txt documents these; when | |
18 | * modifying this list in any way, make sure to keep the | |
19 | * two in sync. | |
20 | */ | |
21 | ||
44e07da8 ÆAB |
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) \ | |
44e07da8 ÆAB |
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) \ | |
44e07da8 ÆAB |
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 | /* warnings */ \ | |
44e07da8 ÆAB |
63 | FUNC(EMPTY_NAME, WARN) \ |
64 | FUNC(FULL_PATHNAME, WARN) \ | |
65 | FUNC(HAS_DOT, WARN) \ | |
66 | FUNC(HAS_DOTDOT, WARN) \ | |
67 | FUNC(HAS_DOTGIT, WARN) \ | |
68 | FUNC(NULL_SHA1, WARN) \ | |
69 | FUNC(ZERO_PADDED_FILEMODE, WARN) \ | |
70 | FUNC(NUL_IN_COMMIT, WARN) \ | |
71 | /* infos (reported as warnings, but ignored by default) */ \ | |
4dd3b045 | 72 | FUNC(BAD_FILEMODE, INFO) \ |
44e07da8 | 73 | FUNC(GITMODULES_PARSE, INFO) \ |
bb6832d5 JK |
74 | FUNC(GITIGNORE_SYMLINK, INFO) \ |
75 | FUNC(GITATTRIBUTES_SYMLINK, INFO) \ | |
76 | FUNC(MAILMAP_SYMLINK, INFO) \ | |
44e07da8 ÆAB |
77 | FUNC(BAD_TAG_NAME, INFO) \ |
78 | FUNC(MISSING_TAGGER_ENTRY, INFO) \ | |
79 | /* ignored (elevated when requested) */ \ | |
80 | FUNC(EXTRA_HEADER_ENTRY, IGNORE) | |
81 | ||
82 | #define MSG_ID(id, msg_type) FSCK_MSG_##id, | |
83 | enum fsck_msg_id { | |
84 | FOREACH_FSCK_MSG_ID(MSG_ID) | |
85 | FSCK_MSG_MAX | |
86 | }; | |
87 | #undef MSG_ID | |
88 | ||
22410549 | 89 | struct fsck_options; |
ef3ca954 | 90 | struct object; |
22410549 | 91 | |
53692df2 ÆAB |
92 | void fsck_set_msg_type_from_ids(struct fsck_options *options, |
93 | enum fsck_msg_id msg_id, | |
94 | enum fsck_msg_type msg_type); | |
0282f4dc | 95 | void fsck_set_msg_type(struct fsck_options *options, |
f1abc2d0 | 96 | const char *msg_id, const char *msg_type); |
0282f4dc | 97 | void fsck_set_msg_types(struct fsck_options *options, const char *values); |
5d477a33 | 98 | int is_valid_msg_type(const char *msg_id, const char *msg_type); |
0282f4dc | 99 | |
355885d5 MK |
100 | /* |
101 | * callback function for fsck_walk | |
102 | * type is the expected type of the object or OBJ_ANY | |
103 | * the return value is: | |
104 | * 0 everything OK | |
105 | * <0 error signaled and abort | |
106 | * >0 error signaled and do not abort | |
107 | */ | |
a1aad716 ÆAB |
108 | typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type, |
109 | void *data, struct fsck_options *options); | |
355885d5 | 110 | |
ba002f3b | 111 | /* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */ |
1cd772cc | 112 | typedef int (*fsck_error)(struct fsck_options *o, |
5afc4b1d | 113 | const struct object_id *oid, enum object_type object_type, |
394d5d31 ÆAB |
114 | enum fsck_msg_type msg_type, enum fsck_msg_id msg_id, |
115 | const char *message); | |
ba002f3b | 116 | |
1cd772cc | 117 | int fsck_error_function(struct fsck_options *o, |
5afc4b1d | 118 | const struct object_id *oid, enum object_type object_type, |
394d5d31 ÆAB |
119 | enum fsck_msg_type msg_type, enum fsck_msg_id msg_id, |
120 | const char *message); | |
3745e269 ÆAB |
121 | int fsck_error_cb_print_missing_gitmodules(struct fsck_options *o, |
122 | const struct object_id *oid, | |
123 | enum object_type object_type, | |
124 | enum fsck_msg_type msg_type, | |
125 | enum fsck_msg_id msg_id, | |
126 | const char *message); | |
d6ffc8d7 | 127 | |
22410549 JS |
128 | struct fsck_options { |
129 | fsck_walk_func walk; | |
130 | fsck_error error_func; | |
131 | unsigned strict:1; | |
1b32b59f | 132 | enum fsck_msg_type *msg_type; |
3b41fb0c | 133 | struct oidset skiplist; |
c15087d1 ÆAB |
134 | struct oidset gitmodules_found; |
135 | struct oidset gitmodules_done; | |
73390290 | 136 | kh_oid_map_t *object_names; |
22410549 JS |
137 | }; |
138 | ||
d385784f ÆAB |
139 | #define FSCK_OPTIONS_DEFAULT { \ |
140 | .skiplist = OIDSET_INIT, \ | |
c15087d1 ÆAB |
141 | .gitmodules_found = OIDSET_INIT, \ |
142 | .gitmodules_done = OIDSET_INIT, \ | |
d385784f ÆAB |
143 | .error_func = fsck_error_function \ |
144 | } | |
145 | #define FSCK_OPTIONS_STRICT { \ | |
146 | .strict = 1, \ | |
c15087d1 ÆAB |
147 | .gitmodules_found = OIDSET_INIT, \ |
148 | .gitmodules_done = OIDSET_INIT, \ | |
d385784f ÆAB |
149 | .error_func = fsck_error_function, \ |
150 | } | |
3745e269 ÆAB |
151 | #define FSCK_OPTIONS_MISSING_GITMODULES { \ |
152 | .strict = 1, \ | |
153 | .gitmodules_found = OIDSET_INIT, \ | |
154 | .gitmodules_done = OIDSET_INIT, \ | |
155 | .error_func = fsck_error_cb_print_missing_gitmodules, \ | |
156 | } | |
22410549 | 157 | |
355885d5 MK |
158 | /* descend in all linked child objects |
159 | * the return value is: | |
160 | * -1 error in processing the object | |
161 | * <0 return value of the callback, which lead to an abort | |
3ea3c215 | 162 | * >0 return value of the first signaled error >0 (in the case of no other errors) |
355885d5 MK |
163 | * 0 everything OK |
164 | */ | |
22410549 | 165 | int fsck_walk(struct object *obj, void *data, struct fsck_options *options); |
23a173a7 JK |
166 | |
167 | /* | |
168 | * Blob objects my pass a NULL data pointer, which indicates they are too large | |
169 | * to fit in memory. All other types must pass a real buffer. | |
170 | */ | |
90a398bb | 171 | int fsck_object(struct object *obj, void *data, unsigned long size, |
22410549 | 172 | struct fsck_options *options); |
355885d5 | 173 | |
acf9de4c ÆAB |
174 | /* |
175 | * fsck a tag, and pass info about it back to the caller. This is | |
176 | * exposed fsck_object() internals for git-mktag(1). | |
177 | */ | |
178 | int fsck_tag_standalone(const struct object_id *oid, const char *buffer, | |
179 | unsigned long size, struct fsck_options *options, | |
180 | struct object_id *tagged_oid, | |
181 | int *tag_type); | |
182 | ||
159e7b08 JK |
183 | /* |
184 | * Some fsck checks are context-dependent, and may end up queued; run this | |
185 | * after completing all fsck_object() calls in order to resolve any remaining | |
186 | * checks. | |
187 | */ | |
188 | int fsck_finish(struct fsck_options *options); | |
189 | ||
a59cfb32 JK |
190 | /* |
191 | * Subsystem for storing human-readable names for each object. | |
192 | * | |
193 | * If fsck_enable_object_names() has not been called, all other functions are | |
194 | * noops. | |
195 | * | |
196 | * Use fsck_put_object_name() to seed initial names (e.g. from refnames); the | |
197 | * fsck code will extend that while walking trees, etc. | |
198 | * | |
199 | * Use fsck_get_object_name() to get a single name (or NULL if none). Or the | |
200 | * more convenient describe_object(), which always produces an output string | |
201 | * with the oid combined with the name (if any). Note that the return value | |
202 | * points to a rotating array of static buffers, and may be invalidated by a | |
203 | * subsequent call. | |
204 | */ | |
205 | void fsck_enable_object_names(struct fsck_options *options); | |
206 | const char *fsck_get_object_name(struct fsck_options *options, | |
73390290 | 207 | const struct object_id *oid); |
a59cfb32 | 208 | __attribute__((format (printf,3,4))) |
73390290 JK |
209 | void fsck_put_object_name(struct fsck_options *options, |
210 | const struct object_id *oid, | |
a59cfb32 JK |
211 | const char *fmt, ...); |
212 | const char *fsck_describe_object(struct fsck_options *options, | |
73390290 | 213 | const struct object_id *oid); |
a59cfb32 | 214 | |
1f3299fd ÆAB |
215 | /* |
216 | * git_config() callback for use by fsck-y tools that want to support | |
217 | * fsck.<msg> fsck.skipList etc. | |
218 | */ | |
fb79f5bf | 219 | int git_fsck_config(const char *var, const char *value, void *cb); |
1f3299fd | 220 | |
355885d5 | 221 | #endif |