]>
Commit | Line | Data |
---|---|---|
355885d5 MK |
1 | #ifndef GIT_FSCK_H |
2 | #define GIT_FSCK_H | |
3 | ||
3b41fb0c RS |
4 | #include "oidset.h" |
5 | ||
1b32b59f ÆAB |
6 | enum fsck_msg_type { |
7 | FSCK_INFO = -2, | |
8 | FSCK_FATAL = -1, | |
9 | FSCK_ERROR = 1, | |
10 | FSCK_WARN, | |
11 | FSCK_IGNORE | |
12 | }; | |
ba002f3b | 13 | |
22410549 | 14 | struct fsck_options; |
ef3ca954 | 15 | struct object; |
22410549 | 16 | |
0282f4dc | 17 | void fsck_set_msg_type(struct fsck_options *options, |
f1abc2d0 | 18 | const char *msg_id, const char *msg_type); |
0282f4dc | 19 | void fsck_set_msg_types(struct fsck_options *options, const char *values); |
5d477a33 | 20 | int is_valid_msg_type(const char *msg_id, const char *msg_type); |
0282f4dc | 21 | |
355885d5 MK |
22 | /* |
23 | * callback function for fsck_walk | |
24 | * type is the expected type of the object or OBJ_ANY | |
25 | * the return value is: | |
26 | * 0 everything OK | |
27 | * <0 error signaled and abort | |
28 | * >0 error signaled and do not abort | |
29 | */ | |
a1aad716 ÆAB |
30 | typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type, |
31 | void *data, struct fsck_options *options); | |
355885d5 | 32 | |
ba002f3b | 33 | /* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */ |
1cd772cc | 34 | typedef int (*fsck_error)(struct fsck_options *o, |
5afc4b1d | 35 | const struct object_id *oid, enum object_type object_type, |
1b32b59f | 36 | enum fsck_msg_type msg_type, const char *message); |
ba002f3b | 37 | |
1cd772cc | 38 | int fsck_error_function(struct fsck_options *o, |
5afc4b1d | 39 | const struct object_id *oid, enum object_type object_type, |
1b32b59f | 40 | enum fsck_msg_type msg_type, const char *message); |
d6ffc8d7 | 41 | |
22410549 JS |
42 | struct fsck_options { |
43 | fsck_walk_func walk; | |
44 | fsck_error error_func; | |
45 | unsigned strict:1; | |
1b32b59f | 46 | enum fsck_msg_type *msg_type; |
3b41fb0c | 47 | struct oidset skiplist; |
73390290 | 48 | kh_oid_map_t *object_names; |
22410549 JS |
49 | }; |
50 | ||
d385784f ÆAB |
51 | #define FSCK_OPTIONS_DEFAULT { \ |
52 | .skiplist = OIDSET_INIT, \ | |
53 | .error_func = fsck_error_function \ | |
54 | } | |
55 | #define FSCK_OPTIONS_STRICT { \ | |
56 | .strict = 1, \ | |
57 | .error_func = fsck_error_function, \ | |
58 | } | |
22410549 | 59 | |
355885d5 MK |
60 | /* descend in all linked child objects |
61 | * the return value is: | |
62 | * -1 error in processing the object | |
63 | * <0 return value of the callback, which lead to an abort | |
3ea3c215 | 64 | * >0 return value of the first signaled error >0 (in the case of no other errors) |
355885d5 MK |
65 | * 0 everything OK |
66 | */ | |
22410549 | 67 | int fsck_walk(struct object *obj, void *data, struct fsck_options *options); |
23a173a7 JK |
68 | |
69 | /* | |
70 | * Blob objects my pass a NULL data pointer, which indicates they are too large | |
71 | * to fit in memory. All other types must pass a real buffer. | |
72 | */ | |
90a398bb | 73 | int fsck_object(struct object *obj, void *data, unsigned long size, |
22410549 | 74 | struct fsck_options *options); |
355885d5 | 75 | |
5476e1ef JT |
76 | void register_found_gitmodules(const struct object_id *oid); |
77 | ||
acf9de4c ÆAB |
78 | /* |
79 | * fsck a tag, and pass info about it back to the caller. This is | |
80 | * exposed fsck_object() internals for git-mktag(1). | |
81 | */ | |
82 | int fsck_tag_standalone(const struct object_id *oid, const char *buffer, | |
83 | unsigned long size, struct fsck_options *options, | |
84 | struct object_id *tagged_oid, | |
85 | int *tag_type); | |
86 | ||
159e7b08 JK |
87 | /* |
88 | * Some fsck checks are context-dependent, and may end up queued; run this | |
89 | * after completing all fsck_object() calls in order to resolve any remaining | |
90 | * checks. | |
91 | */ | |
92 | int fsck_finish(struct fsck_options *options); | |
93 | ||
a59cfb32 JK |
94 | /* |
95 | * Subsystem for storing human-readable names for each object. | |
96 | * | |
97 | * If fsck_enable_object_names() has not been called, all other functions are | |
98 | * noops. | |
99 | * | |
100 | * Use fsck_put_object_name() to seed initial names (e.g. from refnames); the | |
101 | * fsck code will extend that while walking trees, etc. | |
102 | * | |
103 | * Use fsck_get_object_name() to get a single name (or NULL if none). Or the | |
104 | * more convenient describe_object(), which always produces an output string | |
105 | * with the oid combined with the name (if any). Note that the return value | |
106 | * points to a rotating array of static buffers, and may be invalidated by a | |
107 | * subsequent call. | |
108 | */ | |
109 | void fsck_enable_object_names(struct fsck_options *options); | |
110 | const char *fsck_get_object_name(struct fsck_options *options, | |
73390290 | 111 | const struct object_id *oid); |
a59cfb32 | 112 | __attribute__((format (printf,3,4))) |
73390290 JK |
113 | void fsck_put_object_name(struct fsck_options *options, |
114 | const struct object_id *oid, | |
a59cfb32 JK |
115 | const char *fmt, ...); |
116 | const char *fsck_describe_object(struct fsck_options *options, | |
73390290 | 117 | const struct object_id *oid); |
a59cfb32 | 118 | |
1f3299fd ÆAB |
119 | /* |
120 | * git_config() callback for use by fsck-y tools that want to support | |
121 | * fsck.<msg> fsck.skipList etc. | |
122 | */ | |
fb79f5bf | 123 | int git_fsck_config(const char *var, const char *value, void *cb); |
1f3299fd | 124 | |
355885d5 | 125 | #endif |