blob: 69cf715e798ce29085b529b88374c5de75e69529 [file] [log] [blame]
Martin Koegler355885d2008-02-25 22:46:04 +01001#ifndef GIT_FSCK_H
2#define GIT_FSCK_H
3
René Scharfe3b41fb02018-09-03 14:49:27 +00004#include "oidset.h"
5
Martin Koeglerba002f32008-02-25 22:46:08 +01006#define FSCK_ERROR 1
7#define FSCK_WARN 2
Johannes Schindelinefaba7c2015-06-22 17:26:48 +02008#define FSCK_IGNORE 3
Martin Koeglerba002f32008-02-25 22:46:08 +01009
Johannes Schindelin22410542015-06-22 17:25:00 +020010struct fsck_options;
Elijah Newrenef3ca952018-08-15 10:54:05 -070011struct object;
Johannes Schindelin22410542015-06-22 17:25:00 +020012
Johannes Schindelin0282f4d2015-06-22 17:25:25 +020013void fsck_set_msg_type(struct fsck_options *options,
14 const char *msg_id, const char *msg_type);
15void fsck_set_msg_types(struct fsck_options *options, const char *values);
Johannes Schindelin5d477a32015-06-22 17:25:31 +020016int is_valid_msg_type(const char *msg_id, const char *msg_type);
Johannes Schindelin0282f4d2015-06-22 17:25:25 +020017
Martin Koegler355885d2008-02-25 22:46:04 +010018/*
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 Schindelin22410542015-06-22 17:25:00 +020026typedef int (*fsck_walk_func)(struct object *obj, int type, void *data, struct fsck_options *options);
Martin Koegler355885d2008-02-25 22:46:04 +010027
Martin Koeglerba002f32008-02-25 22:46:08 +010028/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */
Johannes Schindelin1cd772c2016-07-17 12:59:57 +020029typedef int (*fsck_error)(struct fsck_options *o,
Jeff King5afc4b12019-10-18 00:58:40 -040030 const struct object_id *oid, enum object_type object_type,
31 int msg_type, const char *message);
Martin Koeglerba002f32008-02-25 22:46:08 +010032
Johannes Schindelin1cd772c2016-07-17 12:59:57 +020033int fsck_error_function(struct fsck_options *o,
Jeff King5afc4b12019-10-18 00:58:40 -040034 const struct object_id *oid, enum object_type object_type,
35 int msg_type, const char *message);
Martin Koeglerd6ffc8d2008-02-25 22:46:09 +010036
Johannes Schindelin22410542015-06-22 17:25:00 +020037struct fsck_options {
38 fsck_walk_func walk;
39 fsck_error error_func;
40 unsigned strict:1;
Johannes Schindelin0282f4d2015-06-22 17:25:25 +020041 int *msg_type;
René Scharfe3b41fb02018-09-03 14:49:27 +000042 struct oidset skiplist;
Jeff King73390292019-10-18 00:57:37 -040043 kh_oid_map_t *object_names;
Johannes Schindelin22410542015-06-22 17:25:00 +020044};
45
René Scharfe3b41fb02018-09-03 14:49:27 +000046#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 Schindelin22410542015-06-22 17:25:00 +020048
Martin Koegler355885d2008-02-25 22:46:04 +010049/* 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 Ralphson3ea3c212009-04-17 19:13:30 +010053 * >0 return value of the first signaled error >0 (in the case of no other errors)
Martin Koegler355885d2008-02-25 22:46:04 +010054 * 0 everything OK
55 */
Johannes Schindelin22410542015-06-22 17:25:00 +020056int fsck_walk(struct object *obj, void *data, struct fsck_options *options);
Jeff King23a173a2019-10-18 00:54:12 -040057
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 Schindelin90a398b2014-09-10 15:52:51 +020062int fsck_object(struct object *obj, void *data, unsigned long size,
Johannes Schindelin22410542015-06-22 17:25:00 +020063 struct fsck_options *options);
Martin Koegler355885d2008-02-25 22:46:04 +010064
Jeff King159e7b02018-05-02 17:20:08 -040065/*
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 */
70int fsck_finish(struct fsck_options *options);
71
Jeff Kinga59cfb32019-10-18 00:56:13 -040072/*
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 */
87void fsck_enable_object_names(struct fsck_options *options);
88const char *fsck_get_object_name(struct fsck_options *options,
Jeff King73390292019-10-18 00:57:37 -040089 const struct object_id *oid);
Jeff Kinga59cfb32019-10-18 00:56:13 -040090__attribute__((format (printf,3,4)))
Jeff King73390292019-10-18 00:57:37 -040091void fsck_put_object_name(struct fsck_options *options,
92 const struct object_id *oid,
Jeff Kinga59cfb32019-10-18 00:56:13 -040093 const char *fmt, ...);
94const char *fsck_describe_object(struct fsck_options *options,
Jeff King73390292019-10-18 00:57:37 -040095 const struct object_id *oid);
Jeff Kinga59cfb32019-10-18 00:56:13 -040096
Martin Koegler355885d2008-02-25 22:46:04 +010097#endif