Martin Koegler | 355885d | 2008-02-25 22:46:04 +0100 | [diff] [blame] | 1 | #ifndef GIT_FSCK_H |
| 2 | #define GIT_FSCK_H |
| 3 | |
Elijah Newren | a64215b | 2023-02-24 00:09:30 +0000 | [diff] [blame] | 4 | #include "object.h" |
René Scharfe | 3b41fb0 | 2018-09-03 14:49:27 +0000 | [diff] [blame] | 5 | #include "oidset.h" |
| 6 | |
Ævar Arnfjörð Bjarmason | 1b32b59 | 2021-03-28 15:15:40 +0200 | [diff] [blame] | 7 | enum fsck_msg_type { |
Ævar Arnfjörð Bjarmason | 30cf618 | 2021-03-28 15:15:41 +0200 | [diff] [blame] | 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, |
Ævar Arnfjörð Bjarmason | 1b32b59 | 2021-03-28 15:15:40 +0200 | [diff] [blame] | 14 | FSCK_WARN, |
Ævar Arnfjörð Bjarmason | 1b32b59 | 2021-03-28 15:15:40 +0200 | [diff] [blame] | 15 | }; |
Martin Koegler | ba002f3 | 2008-02-25 22:46:08 +0100 | [diff] [blame] | 16 | |
John Cai | f6534db | 2022-10-25 15:42:23 -0700 | [diff] [blame] | 17 | /* |
| 18 | * Documentation/fsck-msgids.txt documents these; when |
| 19 | * modifying this list in any way, make sure to keep the |
| 20 | * two in sync. |
| 21 | */ |
| 22 | |
Ævar Arnfjörð Bjarmason | 44e07da | 2021-03-28 15:15:45 +0200 | [diff] [blame] | 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) \ |
Ævar Arnfjörð Bjarmason | 44e07da | 2021-03-28 15:15:45 +0200 | [diff] [blame] | 34 | FUNC(BAD_TIMEZONE, ERROR) \ |
| 35 | FUNC(BAD_TREE, ERROR) \ |
| 36 | FUNC(BAD_TREE_SHA1, ERROR) \ |
| 37 | FUNC(BAD_TYPE, ERROR) \ |
| 38 | FUNC(DUPLICATE_ENTRIES, ERROR) \ |
| 39 | FUNC(MISSING_AUTHOR, ERROR) \ |
| 40 | FUNC(MISSING_COMMITTER, ERROR) \ |
| 41 | FUNC(MISSING_EMAIL, ERROR) \ |
| 42 | FUNC(MISSING_NAME_BEFORE_EMAIL, ERROR) \ |
| 43 | FUNC(MISSING_OBJECT, ERROR) \ |
| 44 | FUNC(MISSING_SPACE_BEFORE_DATE, ERROR) \ |
| 45 | FUNC(MISSING_SPACE_BEFORE_EMAIL, ERROR) \ |
| 46 | FUNC(MISSING_TAG, ERROR) \ |
| 47 | FUNC(MISSING_TAG_ENTRY, ERROR) \ |
| 48 | FUNC(MISSING_TREE, ERROR) \ |
Ævar Arnfjörð Bjarmason | 44e07da | 2021-03-28 15:15:45 +0200 | [diff] [blame] | 49 | FUNC(MISSING_TYPE, ERROR) \ |
| 50 | FUNC(MISSING_TYPE_ENTRY, ERROR) \ |
| 51 | FUNC(MULTIPLE_AUTHORS, ERROR) \ |
| 52 | FUNC(TREE_NOT_SORTED, ERROR) \ |
| 53 | FUNC(UNKNOWN_TYPE, ERROR) \ |
| 54 | FUNC(ZERO_PADDED_DATE, ERROR) \ |
| 55 | FUNC(GITMODULES_MISSING, ERROR) \ |
| 56 | FUNC(GITMODULES_BLOB, ERROR) \ |
| 57 | FUNC(GITMODULES_LARGE, ERROR) \ |
| 58 | FUNC(GITMODULES_NAME, ERROR) \ |
| 59 | FUNC(GITMODULES_SYMLINK, ERROR) \ |
| 60 | FUNC(GITMODULES_URL, ERROR) \ |
| 61 | FUNC(GITMODULES_PATH, ERROR) \ |
| 62 | FUNC(GITMODULES_UPDATE, ERROR) \ |
Patrick Steinhardt | 27ab478 | 2022-12-01 15:46:09 +0100 | [diff] [blame] | 63 | FUNC(GITATTRIBUTES_MISSING, ERROR) \ |
| 64 | FUNC(GITATTRIBUTES_LARGE, ERROR) \ |
| 65 | FUNC(GITATTRIBUTES_LINE_LENGTH, ERROR) \ |
| 66 | FUNC(GITATTRIBUTES_BLOB, ERROR) \ |
Ævar Arnfjörð Bjarmason | 44e07da | 2021-03-28 15:15:45 +0200 | [diff] [blame] | 67 | /* warnings */ \ |
Ævar Arnfjörð Bjarmason | 44e07da | 2021-03-28 15:15:45 +0200 | [diff] [blame] | 68 | FUNC(EMPTY_NAME, WARN) \ |
| 69 | FUNC(FULL_PATHNAME, WARN) \ |
| 70 | FUNC(HAS_DOT, WARN) \ |
| 71 | FUNC(HAS_DOTDOT, WARN) \ |
| 72 | FUNC(HAS_DOTGIT, WARN) \ |
| 73 | FUNC(NULL_SHA1, WARN) \ |
| 74 | FUNC(ZERO_PADDED_FILEMODE, WARN) \ |
| 75 | FUNC(NUL_IN_COMMIT, WARN) \ |
Jeff King | 0fbcaef | 2023-08-31 02:20:01 -0400 | [diff] [blame] | 76 | FUNC(LARGE_PATHNAME, WARN) \ |
Ævar Arnfjörð Bjarmason | 44e07da | 2021-03-28 15:15:45 +0200 | [diff] [blame] | 77 | /* infos (reported as warnings, but ignored by default) */ \ |
Jeff King | 4dd3b04 | 2022-08-10 17:04:07 -0400 | [diff] [blame] | 78 | FUNC(BAD_FILEMODE, INFO) \ |
Ævar Arnfjörð Bjarmason | 44e07da | 2021-03-28 15:15:45 +0200 | [diff] [blame] | 79 | FUNC(GITMODULES_PARSE, INFO) \ |
Jeff King | bb6832d | 2021-05-03 16:43:25 -0400 | [diff] [blame] | 80 | FUNC(GITIGNORE_SYMLINK, INFO) \ |
| 81 | FUNC(GITATTRIBUTES_SYMLINK, INFO) \ |
| 82 | FUNC(MAILMAP_SYMLINK, INFO) \ |
Ævar Arnfjörð Bjarmason | 44e07da | 2021-03-28 15:15:45 +0200 | [diff] [blame] | 83 | FUNC(BAD_TAG_NAME, INFO) \ |
| 84 | FUNC(MISSING_TAGGER_ENTRY, INFO) \ |
| 85 | /* ignored (elevated when requested) */ \ |
| 86 | FUNC(EXTRA_HEADER_ENTRY, IGNORE) |
| 87 | |
| 88 | #define MSG_ID(id, msg_type) FSCK_MSG_##id, |
| 89 | enum fsck_msg_id { |
| 90 | FOREACH_FSCK_MSG_ID(MSG_ID) |
| 91 | FSCK_MSG_MAX |
| 92 | }; |
| 93 | #undef MSG_ID |
| 94 | |
Johannes Schindelin | 2241054 | 2015-06-22 17:25:00 +0200 | [diff] [blame] | 95 | struct fsck_options; |
Elijah Newren | ef3ca95 | 2018-08-15 10:54:05 -0700 | [diff] [blame] | 96 | struct object; |
Johannes Schindelin | 2241054 | 2015-06-22 17:25:00 +0200 | [diff] [blame] | 97 | |
Ævar Arnfjörð Bjarmason | 53692df | 2021-03-28 15:15:47 +0200 | [diff] [blame] | 98 | void fsck_set_msg_type_from_ids(struct fsck_options *options, |
| 99 | enum fsck_msg_id msg_id, |
| 100 | enum fsck_msg_type msg_type); |
Johannes Schindelin | 0282f4d | 2015-06-22 17:25:25 +0200 | [diff] [blame] | 101 | void fsck_set_msg_type(struct fsck_options *options, |
Ævar Arnfjörð Bjarmason | f1abc2d | 2021-03-28 15:15:36 +0200 | [diff] [blame] | 102 | const char *msg_id, const char *msg_type); |
Johannes Schindelin | 0282f4d | 2015-06-22 17:25:25 +0200 | [diff] [blame] | 103 | void fsck_set_msg_types(struct fsck_options *options, const char *values); |
Johannes Schindelin | 5d477a3 | 2015-06-22 17:25:31 +0200 | [diff] [blame] | 104 | int is_valid_msg_type(const char *msg_id, const char *msg_type); |
Johannes Schindelin | 0282f4d | 2015-06-22 17:25:25 +0200 | [diff] [blame] | 105 | |
Martin Koegler | 355885d | 2008-02-25 22:46:04 +0100 | [diff] [blame] | 106 | /* |
| 107 | * callback function for fsck_walk |
| 108 | * type is the expected type of the object or OBJ_ANY |
| 109 | * the return value is: |
| 110 | * 0 everything OK |
| 111 | * <0 error signaled and abort |
| 112 | * >0 error signaled and do not abort |
| 113 | */ |
Ævar Arnfjörð Bjarmason | a1aad71 | 2021-03-28 15:15:35 +0200 | [diff] [blame] | 114 | typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type, |
| 115 | void *data, struct fsck_options *options); |
Martin Koegler | 355885d | 2008-02-25 22:46:04 +0100 | [diff] [blame] | 116 | |
Martin Koegler | ba002f3 | 2008-02-25 22:46:08 +0100 | [diff] [blame] | 117 | /* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */ |
Johannes Schindelin | 1cd772c | 2016-07-17 12:59:57 +0200 | [diff] [blame] | 118 | typedef int (*fsck_error)(struct fsck_options *o, |
Jeff King | 5afc4b1 | 2019-10-18 00:58:40 -0400 | [diff] [blame] | 119 | const struct object_id *oid, enum object_type object_type, |
Ævar Arnfjörð Bjarmason | 394d5d3 | 2021-03-28 15:15:46 +0200 | [diff] [blame] | 120 | enum fsck_msg_type msg_type, enum fsck_msg_id msg_id, |
| 121 | const char *message); |
Martin Koegler | ba002f3 | 2008-02-25 22:46:08 +0100 | [diff] [blame] | 122 | |
Johannes Schindelin | 1cd772c | 2016-07-17 12:59:57 +0200 | [diff] [blame] | 123 | int fsck_error_function(struct fsck_options *o, |
Jeff King | 5afc4b1 | 2019-10-18 00:58:40 -0400 | [diff] [blame] | 124 | const struct object_id *oid, enum object_type object_type, |
Ævar Arnfjörð Bjarmason | 394d5d3 | 2021-03-28 15:15:46 +0200 | [diff] [blame] | 125 | enum fsck_msg_type msg_type, enum fsck_msg_id msg_id, |
| 126 | const char *message); |
Ævar Arnfjörð Bjarmason | 3745e26 | 2021-03-28 15:15:51 +0200 | [diff] [blame] | 127 | int fsck_error_cb_print_missing_gitmodules(struct fsck_options *o, |
| 128 | const struct object_id *oid, |
| 129 | enum object_type object_type, |
| 130 | enum fsck_msg_type msg_type, |
| 131 | enum fsck_msg_id msg_id, |
| 132 | const char *message); |
Martin Koegler | d6ffc8d | 2008-02-25 22:46:09 +0100 | [diff] [blame] | 133 | |
Johannes Schindelin | 2241054 | 2015-06-22 17:25:00 +0200 | [diff] [blame] | 134 | struct fsck_options { |
| 135 | fsck_walk_func walk; |
| 136 | fsck_error error_func; |
| 137 | unsigned strict:1; |
Ævar Arnfjörð Bjarmason | 1b32b59 | 2021-03-28 15:15:40 +0200 | [diff] [blame] | 138 | enum fsck_msg_type *msg_type; |
René Scharfe | 3b41fb0 | 2018-09-03 14:49:27 +0000 | [diff] [blame] | 139 | struct oidset skiplist; |
Ævar Arnfjörð Bjarmason | c15087d | 2021-03-28 15:15:48 +0200 | [diff] [blame] | 140 | struct oidset gitmodules_found; |
| 141 | struct oidset gitmodules_done; |
Patrick Steinhardt | 27ab478 | 2022-12-01 15:46:09 +0100 | [diff] [blame] | 142 | struct oidset gitattributes_found; |
| 143 | struct oidset gitattributes_done; |
Jeff King | 7339029 | 2019-10-18 00:57:37 -0400 | [diff] [blame] | 144 | kh_oid_map_t *object_names; |
Johannes Schindelin | 2241054 | 2015-06-22 17:25:00 +0200 | [diff] [blame] | 145 | }; |
| 146 | |
Ævar Arnfjörð Bjarmason | d385784 | 2021-03-28 15:15:34 +0200 | [diff] [blame] | 147 | #define FSCK_OPTIONS_DEFAULT { \ |
| 148 | .skiplist = OIDSET_INIT, \ |
Ævar Arnfjörð Bjarmason | c15087d | 2021-03-28 15:15:48 +0200 | [diff] [blame] | 149 | .gitmodules_found = OIDSET_INIT, \ |
| 150 | .gitmodules_done = OIDSET_INIT, \ |
Patrick Steinhardt | 27ab478 | 2022-12-01 15:46:09 +0100 | [diff] [blame] | 151 | .gitattributes_found = OIDSET_INIT, \ |
| 152 | .gitattributes_done = OIDSET_INIT, \ |
Ævar Arnfjörð Bjarmason | d385784 | 2021-03-28 15:15:34 +0200 | [diff] [blame] | 153 | .error_func = fsck_error_function \ |
| 154 | } |
| 155 | #define FSCK_OPTIONS_STRICT { \ |
| 156 | .strict = 1, \ |
Ævar Arnfjörð Bjarmason | c15087d | 2021-03-28 15:15:48 +0200 | [diff] [blame] | 157 | .gitmodules_found = OIDSET_INIT, \ |
| 158 | .gitmodules_done = OIDSET_INIT, \ |
Patrick Steinhardt | 27ab478 | 2022-12-01 15:46:09 +0100 | [diff] [blame] | 159 | .gitattributes_found = OIDSET_INIT, \ |
| 160 | .gitattributes_done = OIDSET_INIT, \ |
Ævar Arnfjörð Bjarmason | d385784 | 2021-03-28 15:15:34 +0200 | [diff] [blame] | 161 | .error_func = fsck_error_function, \ |
| 162 | } |
Ævar Arnfjörð Bjarmason | 3745e26 | 2021-03-28 15:15:51 +0200 | [diff] [blame] | 163 | #define FSCK_OPTIONS_MISSING_GITMODULES { \ |
| 164 | .strict = 1, \ |
| 165 | .gitmodules_found = OIDSET_INIT, \ |
| 166 | .gitmodules_done = OIDSET_INIT, \ |
Patrick Steinhardt | 27ab478 | 2022-12-01 15:46:09 +0100 | [diff] [blame] | 167 | .gitattributes_found = OIDSET_INIT, \ |
| 168 | .gitattributes_done = OIDSET_INIT, \ |
Ævar Arnfjörð Bjarmason | 3745e26 | 2021-03-28 15:15:51 +0200 | [diff] [blame] | 169 | .error_func = fsck_error_cb_print_missing_gitmodules, \ |
| 170 | } |
Johannes Schindelin | 2241054 | 2015-06-22 17:25:00 +0200 | [diff] [blame] | 171 | |
Martin Koegler | 355885d | 2008-02-25 22:46:04 +0100 | [diff] [blame] | 172 | /* descend in all linked child objects |
| 173 | * the return value is: |
| 174 | * -1 error in processing the object |
| 175 | * <0 return value of the callback, which lead to an abort |
Mike Ralphson | 3ea3c21 | 2009-04-17 19:13:30 +0100 | [diff] [blame] | 176 | * >0 return value of the first signaled error >0 (in the case of no other errors) |
Martin Koegler | 355885d | 2008-02-25 22:46:04 +0100 | [diff] [blame] | 177 | * 0 everything OK |
| 178 | */ |
Johannes Schindelin | 2241054 | 2015-06-22 17:25:00 +0200 | [diff] [blame] | 179 | int fsck_walk(struct object *obj, void *data, struct fsck_options *options); |
Jeff King | 23a173a | 2019-10-18 00:54:12 -0400 | [diff] [blame] | 180 | |
| 181 | /* |
| 182 | * Blob objects my pass a NULL data pointer, which indicates they are too large |
| 183 | * to fit in memory. All other types must pass a real buffer. |
| 184 | */ |
Johannes Schindelin | 90a398b | 2014-09-10 15:52:51 +0200 | [diff] [blame] | 185 | int fsck_object(struct object *obj, void *data, unsigned long size, |
Johannes Schindelin | 2241054 | 2015-06-22 17:25:00 +0200 | [diff] [blame] | 186 | struct fsck_options *options); |
Martin Koegler | 355885d | 2008-02-25 22:46:04 +0100 | [diff] [blame] | 187 | |
Jeff King | 159e7b0 | 2018-05-02 17:20:08 -0400 | [diff] [blame] | 188 | /* |
Jeff King | 35ff327 | 2023-01-18 15:43:53 -0500 | [diff] [blame] | 189 | * Same as fsck_object(), but for when the caller doesn't have an object |
| 190 | * struct. |
| 191 | */ |
| 192 | int fsck_buffer(const struct object_id *oid, enum object_type, |
| 193 | void *data, unsigned long size, |
| 194 | struct fsck_options *options); |
| 195 | |
| 196 | /* |
Ævar Arnfjörð Bjarmason | acf9de4 | 2021-01-05 20:42:46 +0100 | [diff] [blame] | 197 | * fsck a tag, and pass info about it back to the caller. This is |
| 198 | * exposed fsck_object() internals for git-mktag(1). |
| 199 | */ |
| 200 | int fsck_tag_standalone(const struct object_id *oid, const char *buffer, |
| 201 | unsigned long size, struct fsck_options *options, |
| 202 | struct object_id *tagged_oid, |
| 203 | int *tag_type); |
| 204 | |
| 205 | /* |
Jeff King | 159e7b0 | 2018-05-02 17:20:08 -0400 | [diff] [blame] | 206 | * Some fsck checks are context-dependent, and may end up queued; run this |
| 207 | * after completing all fsck_object() calls in order to resolve any remaining |
| 208 | * checks. |
| 209 | */ |
| 210 | int fsck_finish(struct fsck_options *options); |
| 211 | |
Jeff King | a59cfb3 | 2019-10-18 00:56:13 -0400 | [diff] [blame] | 212 | /* |
| 213 | * Subsystem for storing human-readable names for each object. |
| 214 | * |
| 215 | * If fsck_enable_object_names() has not been called, all other functions are |
| 216 | * noops. |
| 217 | * |
| 218 | * Use fsck_put_object_name() to seed initial names (e.g. from refnames); the |
| 219 | * fsck code will extend that while walking trees, etc. |
| 220 | * |
| 221 | * Use fsck_get_object_name() to get a single name (or NULL if none). Or the |
| 222 | * more convenient describe_object(), which always produces an output string |
| 223 | * with the oid combined with the name (if any). Note that the return value |
| 224 | * points to a rotating array of static buffers, and may be invalidated by a |
| 225 | * subsequent call. |
| 226 | */ |
| 227 | void fsck_enable_object_names(struct fsck_options *options); |
| 228 | const char *fsck_get_object_name(struct fsck_options *options, |
Jeff King | 7339029 | 2019-10-18 00:57:37 -0400 | [diff] [blame] | 229 | const struct object_id *oid); |
Jeff King | a59cfb3 | 2019-10-18 00:56:13 -0400 | [diff] [blame] | 230 | __attribute__((format (printf,3,4))) |
Jeff King | 7339029 | 2019-10-18 00:57:37 -0400 | [diff] [blame] | 231 | void fsck_put_object_name(struct fsck_options *options, |
| 232 | const struct object_id *oid, |
Jeff King | a59cfb3 | 2019-10-18 00:56:13 -0400 | [diff] [blame] | 233 | const char *fmt, ...); |
| 234 | const char *fsck_describe_object(struct fsck_options *options, |
Jeff King | 7339029 | 2019-10-18 00:57:37 -0400 | [diff] [blame] | 235 | const struct object_id *oid); |
Jeff King | a59cfb3 | 2019-10-18 00:56:13 -0400 | [diff] [blame] | 236 | |
Glen Choo | a4e7e31 | 2023-06-28 19:26:22 +0000 | [diff] [blame] | 237 | struct key_value_info; |
Ævar Arnfjörð Bjarmason | 1f3299f | 2021-01-05 20:42:47 +0100 | [diff] [blame] | 238 | /* |
| 239 | * git_config() callback for use by fsck-y tools that want to support |
| 240 | * fsck.<msg> fsck.skipList etc. |
| 241 | */ |
Glen Choo | a4e7e31 | 2023-06-28 19:26:22 +0000 | [diff] [blame] | 242 | int git_fsck_config(const char *var, const char *value, |
| 243 | const struct config_context *ctx, void *cb); |
Ævar Arnfjörð Bjarmason | 1f3299f | 2021-01-05 20:42:47 +0100 | [diff] [blame] | 244 | |
Martin Koegler | 355885d | 2008-02-25 22:46:04 +0100 | [diff] [blame] | 245 | #endif |