Martin Koegler | 355885d | 2008-02-25 22:46:04 +0100 | [diff] [blame] | 1 | #ifndef GIT_FSCK_H |
| 2 | #define GIT_FSCK_H |
| 3 | |
René Scharfe | 3b41fb0 | 2018-09-03 14:49:27 +0000 | [diff] [blame] | 4 | #include "oidset.h" |
| 5 | |
Martin Koegler | ba002f3 | 2008-02-25 22:46:08 +0100 | [diff] [blame] | 6 | #define FSCK_ERROR 1 |
| 7 | #define FSCK_WARN 2 |
Johannes Schindelin | efaba7c | 2015-06-22 17:26:48 +0200 | [diff] [blame] | 8 | #define FSCK_IGNORE 3 |
Martin Koegler | ba002f3 | 2008-02-25 22:46:08 +0100 | [diff] [blame] | 9 | |
Johannes Schindelin | 2241054 | 2015-06-22 17:25:00 +0200 | [diff] [blame] | 10 | struct fsck_options; |
Elijah Newren | ef3ca95 | 2018-08-15 10:54:05 -0700 | [diff] [blame] | 11 | struct object; |
Johannes Schindelin | 2241054 | 2015-06-22 17:25:00 +0200 | [diff] [blame] | 12 | |
Johannes Schindelin | 0282f4d | 2015-06-22 17:25:25 +0200 | [diff] [blame] | 13 | void fsck_set_msg_type(struct fsck_options *options, |
| 14 | const char *msg_id, const char *msg_type); |
| 15 | void fsck_set_msg_types(struct fsck_options *options, const char *values); |
Johannes Schindelin | 5d477a3 | 2015-06-22 17:25:31 +0200 | [diff] [blame] | 16 | 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] | 17 | |
Martin Koegler | 355885d | 2008-02-25 22:46:04 +0100 | [diff] [blame] | 18 | /* |
| 19 | * callback function for fsck_walk |
| 20 | * type is the expected type of the object or OBJ_ANY |
| 21 | * the return value is: |
| 22 | * 0 everything OK |
| 23 | * <0 error signaled and abort |
| 24 | * >0 error signaled and do not abort |
| 25 | */ |
Johannes Schindelin | 2241054 | 2015-06-22 17:25:00 +0200 | [diff] [blame] | 26 | typedef int (*fsck_walk_func)(struct object *obj, int type, void *data, struct fsck_options *options); |
Martin Koegler | 355885d | 2008-02-25 22:46:04 +0100 | [diff] [blame] | 27 | |
Martin Koegler | ba002f3 | 2008-02-25 22:46:08 +0100 | [diff] [blame] | 28 | /* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */ |
Johannes Schindelin | 1cd772c | 2016-07-17 12:59:57 +0200 | [diff] [blame] | 29 | typedef int (*fsck_error)(struct fsck_options *o, |
Jeff King | 5afc4b1 | 2019-10-18 00:58:40 -0400 | [diff] [blame] | 30 | const struct object_id *oid, enum object_type object_type, |
| 31 | int msg_type, const char *message); |
Martin Koegler | ba002f3 | 2008-02-25 22:46:08 +0100 | [diff] [blame] | 32 | |
Johannes Schindelin | 1cd772c | 2016-07-17 12:59:57 +0200 | [diff] [blame] | 33 | int fsck_error_function(struct fsck_options *o, |
Jeff King | 5afc4b1 | 2019-10-18 00:58:40 -0400 | [diff] [blame] | 34 | const struct object_id *oid, enum object_type object_type, |
| 35 | int msg_type, const char *message); |
Martin Koegler | d6ffc8d | 2008-02-25 22:46:09 +0100 | [diff] [blame] | 36 | |
Johannes Schindelin | 2241054 | 2015-06-22 17:25:00 +0200 | [diff] [blame] | 37 | struct fsck_options { |
| 38 | fsck_walk_func walk; |
| 39 | fsck_error error_func; |
| 40 | unsigned strict:1; |
Johannes Schindelin | 0282f4d | 2015-06-22 17:25:25 +0200 | [diff] [blame] | 41 | int *msg_type; |
René Scharfe | 3b41fb0 | 2018-09-03 14:49:27 +0000 | [diff] [blame] | 42 | struct oidset skiplist; |
Jeff King | 7339029 | 2019-10-18 00:57:37 -0400 | [diff] [blame] | 43 | kh_oid_map_t *object_names; |
Johannes Schindelin | 2241054 | 2015-06-22 17:25:00 +0200 | [diff] [blame] | 44 | }; |
| 45 | |
René Scharfe | 3b41fb0 | 2018-09-03 14:49:27 +0000 | [diff] [blame] | 46 | #define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT } |
| 47 | #define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT } |
Johannes Schindelin | 2241054 | 2015-06-22 17:25:00 +0200 | [diff] [blame] | 48 | |
Martin Koegler | 355885d | 2008-02-25 22:46:04 +0100 | [diff] [blame] | 49 | /* descend in all linked child objects |
| 50 | * the return value is: |
| 51 | * -1 error in processing the object |
| 52 | * <0 return value of the callback, which lead to an abort |
Mike Ralphson | 3ea3c21 | 2009-04-17 19:13:30 +0100 | [diff] [blame] | 53 | * >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] | 54 | * 0 everything OK |
| 55 | */ |
Johannes Schindelin | 2241054 | 2015-06-22 17:25:00 +0200 | [diff] [blame] | 56 | int fsck_walk(struct object *obj, void *data, struct fsck_options *options); |
Jeff King | 23a173a | 2019-10-18 00:54:12 -0400 | [diff] [blame] | 57 | |
| 58 | /* |
| 59 | * Blob objects my pass a NULL data pointer, which indicates they are too large |
| 60 | * to fit in memory. All other types must pass a real buffer. |
| 61 | */ |
Johannes Schindelin | 90a398b | 2014-09-10 15:52:51 +0200 | [diff] [blame] | 62 | int fsck_object(struct object *obj, void *data, unsigned long size, |
Johannes Schindelin | 2241054 | 2015-06-22 17:25:00 +0200 | [diff] [blame] | 63 | struct fsck_options *options); |
Martin Koegler | 355885d | 2008-02-25 22:46:04 +0100 | [diff] [blame] | 64 | |
Jeff King | 159e7b0 | 2018-05-02 17:20:08 -0400 | [diff] [blame] | 65 | /* |
| 66 | * Some fsck checks are context-dependent, and may end up queued; run this |
| 67 | * after completing all fsck_object() calls in order to resolve any remaining |
| 68 | * checks. |
| 69 | */ |
| 70 | int fsck_finish(struct fsck_options *options); |
| 71 | |
Jeff King | a59cfb3 | 2019-10-18 00:56:13 -0400 | [diff] [blame] | 72 | /* |
| 73 | * Subsystem for storing human-readable names for each object. |
| 74 | * |
| 75 | * If fsck_enable_object_names() has not been called, all other functions are |
| 76 | * noops. |
| 77 | * |
| 78 | * Use fsck_put_object_name() to seed initial names (e.g. from refnames); the |
| 79 | * fsck code will extend that while walking trees, etc. |
| 80 | * |
| 81 | * Use fsck_get_object_name() to get a single name (or NULL if none). Or the |
| 82 | * more convenient describe_object(), which always produces an output string |
| 83 | * with the oid combined with the name (if any). Note that the return value |
| 84 | * points to a rotating array of static buffers, and may be invalidated by a |
| 85 | * subsequent call. |
| 86 | */ |
| 87 | void fsck_enable_object_names(struct fsck_options *options); |
| 88 | const char *fsck_get_object_name(struct fsck_options *options, |
Jeff King | 7339029 | 2019-10-18 00:57:37 -0400 | [diff] [blame] | 89 | const struct object_id *oid); |
Jeff King | a59cfb3 | 2019-10-18 00:56:13 -0400 | [diff] [blame] | 90 | __attribute__((format (printf,3,4))) |
Jeff King | 7339029 | 2019-10-18 00:57:37 -0400 | [diff] [blame] | 91 | void fsck_put_object_name(struct fsck_options *options, |
| 92 | const struct object_id *oid, |
Jeff King | a59cfb3 | 2019-10-18 00:56:13 -0400 | [diff] [blame] | 93 | const char *fmt, ...); |
| 94 | const char *fsck_describe_object(struct fsck_options *options, |
Jeff King | 7339029 | 2019-10-18 00:57:37 -0400 | [diff] [blame] | 95 | const struct object_id *oid); |
Jeff King | a59cfb3 | 2019-10-18 00:56:13 -0400 | [diff] [blame] | 96 | |
Martin Koegler | 355885d | 2008-02-25 22:46:04 +0100 | [diff] [blame] | 97 | #endif |