Skip to content

Commit 2241054

Browse files
dschogitster
authored andcommitted
fsck: introduce fsck options
Just like the diff machinery, we are about to introduce more settings, therefore it makes sense to carry them around as a (pointer to a) struct containing all of them. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5b1d901 commit 2241054

File tree

5 files changed

+114
-93
lines changed

5 files changed

+114
-93
lines changed

builtin/fsck.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ static int include_reflogs = 1;
2525
static int check_full = 1;
2626
static int check_strict;
2727
static int keep_cache_objects;
28+
static struct fsck_options fsck_walk_options = FSCK_OPTIONS_DEFAULT;
29+
static struct fsck_options fsck_obj_options = FSCK_OPTIONS_DEFAULT;
2830
static struct object_id head_oid;
2931
static const char *head_points_at;
3032
static int errors_found;
@@ -76,7 +78,7 @@ static int fsck_error_func(struct object *obj, int type, const char *err, ...)
7678

7779
static struct object_array pending;
7880

79-
static int mark_object(struct object *obj, int type, void *data)
81+
static int mark_object(struct object *obj, int type, void *data, struct fsck_options *options)
8082
{
8183
struct object *parent = data;
8284

@@ -119,7 +121,7 @@ static int mark_object(struct object *obj, int type, void *data)
119121

120122
static void mark_object_reachable(struct object *obj)
121123
{
122-
mark_object(obj, OBJ_ANY, NULL);
124+
mark_object(obj, OBJ_ANY, NULL, NULL);
123125
}
124126

125127
static int traverse_one_object(struct object *obj)
@@ -132,7 +134,7 @@ static int traverse_one_object(struct object *obj)
132134
if (parse_tree(tree) < 0)
133135
return 1; /* error already displayed */
134136
}
135-
result = fsck_walk(obj, mark_object, obj);
137+
result = fsck_walk(obj, obj, &fsck_walk_options);
136138
if (tree)
137139
free_tree_buffer(tree);
138140
return result;
@@ -158,7 +160,7 @@ static int traverse_reachable(void)
158160
return !!result;
159161
}
160162

161-
static int mark_used(struct object *obj, int type, void *data)
163+
static int mark_used(struct object *obj, int type, void *data, struct fsck_options *options)
162164
{
163165
if (!obj)
164166
return 1;
@@ -296,9 +298,9 @@ static int fsck_obj(struct object *obj)
296298
fprintf(stderr, "Checking %s %s\n",
297299
typename(obj->type), sha1_to_hex(obj->sha1));
298300

299-
if (fsck_walk(obj, mark_used, NULL))
301+
if (fsck_walk(obj, NULL, &fsck_obj_options))
300302
objerror(obj, "broken links");
301-
if (fsck_object(obj, NULL, 0, check_strict, fsck_error_func))
303+
if (fsck_object(obj, NULL, 0, &fsck_obj_options))
302304
return -1;
303305

304306
if (obj->type == OBJ_TREE) {
@@ -632,6 +634,12 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
632634

633635
argc = parse_options(argc, argv, prefix, fsck_opts, fsck_usage, 0);
634636

637+
fsck_walk_options.walk = mark_object;
638+
fsck_obj_options.walk = mark_used;
639+
fsck_obj_options.error_func = fsck_error_func;
640+
if (check_strict)
641+
fsck_obj_options.strict = 1;
642+
635643
if (show_progress == -1)
636644
show_progress = isatty(2);
637645
if (verbose)

builtin/index-pack.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ static int nr_threads;
7575
static int from_stdin;
7676
static int strict;
7777
static int do_fsck_object;
78+
static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;
7879
static int verbose;
7980
static int show_stat;
8081
static int check_self_contained_and_connected;
@@ -192,7 +193,7 @@ static void cleanup_thread(void)
192193
#endif
193194

194195

195-
static int mark_link(struct object *obj, int type, void *data)
196+
static int mark_link(struct object *obj, int type, void *data, struct fsck_options *options)
196197
{
197198
if (!obj)
198199
return -1;
@@ -838,10 +839,9 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
838839
if (!obj)
839840
die(_("invalid %s"), typename(type));
840841
if (do_fsck_object &&
841-
fsck_object(obj, buf, size, 1,
842-
fsck_error_function))
842+
fsck_object(obj, buf, size, &fsck_options))
843843
die(_("Error in object"));
844-
if (fsck_walk(obj, mark_link, NULL))
844+
if (fsck_walk(obj, NULL, &fsck_options))
845845
die(_("Not all child objects of %s are reachable"), sha1_to_hex(obj->sha1));
846846

847847
if (obj->type == OBJ_TREE) {
@@ -1615,6 +1615,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
16151615
usage(index_pack_usage);
16161616

16171617
check_replace_refs = 0;
1618+
fsck_options.walk = mark_link;
16181619

16191620
reset_pack_idx_option(&opts);
16201621
git_config(git_index_pack_config, &opts);

builtin/unpack-objects.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ static unsigned char buffer[4096];
2020
static unsigned int offset, len;
2121
static off_t consumed_bytes;
2222
static git_SHA_CTX ctx;
23+
static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;
2324

2425
/*
2526
* When running under --strict mode, objects whose reachability are
@@ -178,7 +179,7 @@ static void write_cached_object(struct object *obj, struct obj_buffer *obj_buf)
178179
* that have reachability requirements and calls this function.
179180
* Verify its reachability and validity recursively and write it out.
180181
*/
181-
static int check_object(struct object *obj, int type, void *data)
182+
static int check_object(struct object *obj, int type, void *data, struct fsck_options *options)
182183
{
183184
struct obj_buffer *obj_buf;
184185

@@ -203,10 +204,10 @@ static int check_object(struct object *obj, int type, void *data)
203204
obj_buf = lookup_object_buffer(obj);
204205
if (!obj_buf)
205206
die("Whoops! Cannot find object '%s'", sha1_to_hex(obj->sha1));
206-
if (fsck_object(obj, obj_buf->buffer, obj_buf->size, 1,
207-
fsck_error_function))
207+
if (fsck_object(obj, obj_buf->buffer, obj_buf->size, &fsck_options))
208208
die("Error in object");
209-
if (fsck_walk(obj, check_object, NULL))
209+
fsck_options.walk = check_object;
210+
if (fsck_walk(obj, NULL, &fsck_options))
210211
die("Error on reachable objects of %s", sha1_to_hex(obj->sha1));
211212
write_cached_object(obj, obj_buf);
212213
return 0;
@@ -217,7 +218,7 @@ static void write_rest(void)
217218
unsigned i;
218219
for (i = 0; i < nr_objects; i++) {
219220
if (obj_list[i].obj)
220-
check_object(obj_list[i].obj, OBJ_ANY, NULL);
221+
check_object(obj_list[i].obj, OBJ_ANY, NULL, NULL);
221222
}
222223
}
223224

0 commit comments

Comments
 (0)