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