Git fork
at reftables-rust 299 lines 9.1 kB view raw
1#ifndef GIT_FSCK_H 2#define GIT_FSCK_H 3 4#include "object.h" 5#include "oidset.h" 6 7enum 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, 15}; 16 17/* 18 * Documentation/fsck-msgids.adoc documents these; when 19 * modifying this list in any way, make sure to keep the 20 * two in sync. 21 */ 22 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_HEADER_CONTINUATION, ERROR) \ 29 FUNC(BAD_DATE, ERROR) \ 30 FUNC(BAD_DATE_OVERFLOW, ERROR) \ 31 FUNC(BAD_EMAIL, ERROR) \ 32 FUNC(BAD_GPGSIG, ERROR) \ 33 FUNC(BAD_NAME, ERROR) \ 34 FUNC(BAD_OBJECT_SHA1, ERROR) \ 35 FUNC(BAD_PACKED_REF_ENTRY, ERROR) \ 36 FUNC(BAD_PACKED_REF_HEADER, ERROR) \ 37 FUNC(BAD_PARENT_SHA1, ERROR) \ 38 FUNC(BAD_REFERENT_NAME, ERROR) \ 39 FUNC(BAD_REF_CONTENT, ERROR) \ 40 FUNC(BAD_REF_FILETYPE, ERROR) \ 41 FUNC(BAD_REF_NAME, ERROR) \ 42 FUNC(BAD_TIMEZONE, ERROR) \ 43 FUNC(BAD_TREE, ERROR) \ 44 FUNC(BAD_TREE_SHA1, ERROR) \ 45 FUNC(BAD_TYPE, ERROR) \ 46 FUNC(DUPLICATE_ENTRIES, ERROR) \ 47 FUNC(GITATTRIBUTES_BLOB, ERROR) \ 48 FUNC(GITATTRIBUTES_LARGE, ERROR) \ 49 FUNC(GITATTRIBUTES_LINE_LENGTH, ERROR) \ 50 FUNC(GITATTRIBUTES_MISSING, ERROR) \ 51 FUNC(GITMODULES_BLOB, ERROR) \ 52 FUNC(GITMODULES_LARGE, ERROR) \ 53 FUNC(GITMODULES_MISSING, ERROR) \ 54 FUNC(GITMODULES_NAME, ERROR) \ 55 FUNC(GITMODULES_PATH, ERROR) \ 56 FUNC(GITMODULES_SYMLINK, ERROR) \ 57 FUNC(GITMODULES_UPDATE, ERROR) \ 58 FUNC(GITMODULES_URL, ERROR) \ 59 FUNC(MISSING_AUTHOR, ERROR) \ 60 FUNC(MISSING_COMMITTER, ERROR) \ 61 FUNC(MISSING_EMAIL, ERROR) \ 62 FUNC(MISSING_NAME_BEFORE_EMAIL, ERROR) \ 63 FUNC(MISSING_OBJECT, ERROR) \ 64 FUNC(MISSING_SPACE_BEFORE_DATE, ERROR) \ 65 FUNC(MISSING_SPACE_BEFORE_EMAIL, ERROR) \ 66 FUNC(MISSING_TAG, ERROR) \ 67 FUNC(MISSING_TAG_ENTRY, ERROR) \ 68 FUNC(MISSING_TREE, ERROR) \ 69 FUNC(MISSING_TYPE, ERROR) \ 70 FUNC(MISSING_TYPE_ENTRY, ERROR) \ 71 FUNC(MULTIPLE_AUTHORS, ERROR) \ 72 FUNC(PACKED_REF_ENTRY_NOT_TERMINATED, ERROR) \ 73 FUNC(PACKED_REF_UNSORTED, ERROR) \ 74 FUNC(TREE_NOT_SORTED, ERROR) \ 75 FUNC(UNKNOWN_TYPE, ERROR) \ 76 FUNC(ZERO_PADDED_DATE, ERROR) \ 77 /* warnings */ \ 78 FUNC(BAD_REFTABLE_TABLE_NAME, WARN) \ 79 FUNC(EMPTY_NAME, WARN) \ 80 FUNC(FULL_PATHNAME, WARN) \ 81 FUNC(HAS_DOT, WARN) \ 82 FUNC(HAS_DOTDOT, WARN) \ 83 FUNC(HAS_DOTGIT, WARN) \ 84 FUNC(LARGE_PATHNAME, WARN) \ 85 FUNC(NULL_SHA1, WARN) \ 86 FUNC(NUL_IN_COMMIT, WARN) \ 87 FUNC(ZERO_PADDED_FILEMODE, WARN) \ 88 /* infos (reported as warnings, but ignored by default) */ \ 89 FUNC(BAD_FILEMODE, INFO) \ 90 FUNC(BAD_TAG_NAME, INFO) \ 91 FUNC(EMPTY_PACKED_REFS_FILE, INFO) \ 92 FUNC(GITATTRIBUTES_SYMLINK, INFO) \ 93 FUNC(GITIGNORE_SYMLINK, INFO) \ 94 FUNC(GITMODULES_PARSE, INFO) \ 95 FUNC(MAILMAP_SYMLINK, INFO) \ 96 FUNC(MISSING_TAGGER_ENTRY, INFO) \ 97 FUNC(REF_MISSING_NEWLINE, INFO) \ 98 FUNC(SYMLINK_REF, INFO) \ 99 FUNC(SYMREF_TARGET_IS_NOT_A_REF, INFO) \ 100 FUNC(TRAILING_REF_CONTENT, INFO) \ 101 /* ignored (elevated when requested) */ \ 102 FUNC(EXTRA_HEADER_ENTRY, IGNORE) 103 104#define MSG_ID(id, msg_type) FSCK_MSG_##id, 105enum fsck_msg_id { 106 FOREACH_FSCK_MSG_ID(MSG_ID) 107 FSCK_MSG_MAX 108}; 109#undef MSG_ID 110 111struct fsck_options; 112struct object; 113 114void fsck_set_msg_type_from_ids(struct fsck_options *options, 115 enum fsck_msg_id msg_id, 116 enum fsck_msg_type msg_type); 117void fsck_set_msg_type(struct fsck_options *options, 118 const char *msg_id, const char *msg_type); 119void fsck_set_msg_types(struct fsck_options *options, const char *values); 120int is_valid_msg_type(const char *msg_id, const char *msg_type); 121 122/* 123 * callback function for fsck_walk 124 * type is the expected type of the object or OBJ_ANY 125 * the return value is: 126 * 0 everything OK 127 * <0 error signaled and abort 128 * >0 error signaled and do not abort 129 */ 130typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type, 131 void *data, struct fsck_options *options); 132 133/* 134 * Callback for reporting errors either for objects or refs. The "fsck_report" 135 * is a generic pointer that can be used to pass any information. 136 */ 137typedef int (*fsck_error)(struct fsck_options *o, 138 void *fsck_report, 139 enum fsck_msg_type msg_type, enum fsck_msg_id msg_id, 140 const char *message); 141 142int fsck_objects_error_function(struct fsck_options *o, 143 void *fsck_report, 144 enum fsck_msg_type msg_type, enum fsck_msg_id msg_id, 145 const char *message); 146int fsck_objects_error_cb_print_missing_gitmodules(struct fsck_options *o, 147 void *fsck_report, 148 enum fsck_msg_type msg_type, 149 enum fsck_msg_id msg_id, 150 const char *message); 151 152int fsck_refs_error_function(struct fsck_options *options, 153 void *fsck_report, 154 enum fsck_msg_type msg_type, 155 enum fsck_msg_id msg_id, 156 const char *message); 157 158struct fsck_object_report { 159 const struct object_id *oid; 160 enum object_type object_type; 161}; 162 163struct fsck_ref_report { 164 const char *path; 165 const struct object_id *oid; 166 const char *referent; 167}; 168 169struct fsck_options { 170 fsck_walk_func walk; 171 fsck_error error_func; 172 unsigned strict; 173 unsigned verbose; 174 enum fsck_msg_type *msg_type; 175 struct oidset skip_oids; 176 struct oidset gitmodules_found; 177 struct oidset gitmodules_done; 178 struct oidset gitattributes_found; 179 struct oidset gitattributes_done; 180 kh_oid_map_t *object_names; 181}; 182 183#define FSCK_OPTIONS_DEFAULT { \ 184 .skip_oids = OIDSET_INIT, \ 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 \ 190} 191#define FSCK_OPTIONS_STRICT { \ 192 .strict = 1, \ 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_function, \ 198} 199#define FSCK_OPTIONS_MISSING_GITMODULES { \ 200 .strict = 1, \ 201 .gitmodules_found = OIDSET_INIT, \ 202 .gitmodules_done = OIDSET_INIT, \ 203 .gitattributes_found = OIDSET_INIT, \ 204 .gitattributes_done = OIDSET_INIT, \ 205 .error_func = fsck_objects_error_cb_print_missing_gitmodules, \ 206} 207#define FSCK_REFS_OPTIONS_DEFAULT { \ 208 .error_func = fsck_refs_error_function, \ 209} 210 211/* descend in all linked child objects 212 * the return value is: 213 * -1 error in processing the object 214 * <0 return value of the callback, which lead to an abort 215 * >0 return value of the first signaled error >0 (in the case of no other errors) 216 * 0 everything OK 217 */ 218int fsck_walk(struct object *obj, void *data, struct fsck_options *options); 219 220/* 221 * Blob objects my pass a NULL data pointer, which indicates they are too large 222 * to fit in memory. All other types must pass a real buffer. 223 */ 224int fsck_object(struct object *obj, void *data, unsigned long size, 225 struct fsck_options *options); 226 227/* 228 * Same as fsck_object(), but for when the caller doesn't have an object 229 * struct. 230 */ 231int fsck_buffer(const struct object_id *oid, enum object_type, 232 const void *data, unsigned long size, 233 struct fsck_options *options); 234 235/* 236 * fsck a tag, and pass info about it back to the caller. This is 237 * exposed fsck_object() internals for git-mktag(1). 238 */ 239int fsck_tag_standalone(const struct object_id *oid, const char *buffer, 240 unsigned long size, struct fsck_options *options, 241 struct object_id *tagged_oid, 242 int *tag_type); 243 244/* 245 * Some fsck checks are context-dependent, and may end up queued; run this 246 * after completing all fsck_object() calls in order to resolve any remaining 247 * checks. 248 */ 249int fsck_finish(struct fsck_options *options); 250 251/* 252 * Clear the fsck_options struct, freeing any allocated memory. 253 */ 254void fsck_options_clear(struct fsck_options *options); 255 256/* 257 * Report an error or warning for refs. 258 */ 259__attribute__((format (printf, 4, 5))) 260int fsck_report_ref(struct fsck_options *options, 261 struct fsck_ref_report *report, 262 enum fsck_msg_id msg_id, 263 const char *fmt, ...); 264 265 266/* 267 * Subsystem for storing human-readable names for each object. 268 * 269 * If fsck_enable_object_names() has not been called, all other functions are 270 * noops. 271 * 272 * Use fsck_put_object_name() to seed initial names (e.g. from refnames); the 273 * fsck code will extend that while walking trees, etc. 274 * 275 * Use fsck_get_object_name() to get a single name (or NULL if none). Or the 276 * more convenient describe_object(), which always produces an output string 277 * with the oid combined with the name (if any). Note that the return value 278 * points to a rotating array of static buffers, and may be invalidated by a 279 * subsequent call. 280 */ 281void fsck_enable_object_names(struct fsck_options *options); 282const char *fsck_get_object_name(struct fsck_options *options, 283 const struct object_id *oid); 284__attribute__((format (printf,3,4))) 285void fsck_put_object_name(struct fsck_options *options, 286 const struct object_id *oid, 287 const char *fmt, ...); 288const char *fsck_describe_object(struct fsck_options *options, 289 const struct object_id *oid); 290 291struct key_value_info; 292/* 293 * repo_config() callback for use by fsck-y tools that want to support 294 * fsck.<msg> fsck.skipList etc. 295 */ 296int git_fsck_config(const char *var, const char *value, 297 const struct config_context *ctx, void *cb); 298 299#endif