Skip to content

Commit

Permalink
fsck: introduce fsck options
Browse files Browse the repository at this point in the history
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 <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Johannes Schindelin authored and Junio C Hamano committed Jun 22, 2015
1 parent 5b1d901 commit 2241054
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 93 deletions.
20 changes: 14 additions & 6 deletions builtin/fsck.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ static int include_reflogs = 1;
static int check_full = 1;
static int check_strict;
static int keep_cache_objects;
static struct fsck_options fsck_walk_options = FSCK_OPTIONS_DEFAULT;
static struct fsck_options fsck_obj_options = FSCK_OPTIONS_DEFAULT;
static struct object_id head_oid;
static const char *head_points_at;
static int errors_found;
Expand Down Expand Up @@ -76,7 +78,7 @@ static int fsck_error_func(struct object *obj, int type, const char *err, ...)

static struct object_array pending;

static int mark_object(struct object *obj, int type, void *data)
static int mark_object(struct object *obj, int type, void *data, struct fsck_options *options)
{
struct object *parent = data;

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

static void mark_object_reachable(struct object *obj)
{
mark_object(obj, OBJ_ANY, NULL);
mark_object(obj, OBJ_ANY, NULL, NULL);
}

static int traverse_one_object(struct object *obj)
Expand All @@ -132,7 +134,7 @@ static int traverse_one_object(struct object *obj)
if (parse_tree(tree) < 0)
return 1; /* error already displayed */
}
result = fsck_walk(obj, mark_object, obj);
result = fsck_walk(obj, obj, &fsck_walk_options);
if (tree)
free_tree_buffer(tree);
return result;
Expand All @@ -158,7 +160,7 @@ static int traverse_reachable(void)
return !!result;
}

static int mark_used(struct object *obj, int type, void *data)
static int mark_used(struct object *obj, int type, void *data, struct fsck_options *options)
{
if (!obj)
return 1;
Expand Down Expand Up @@ -296,9 +298,9 @@ static int fsck_obj(struct object *obj)
fprintf(stderr, "Checking %s %s\n",
typename(obj->type), sha1_to_hex(obj->sha1));

if (fsck_walk(obj, mark_used, NULL))
if (fsck_walk(obj, NULL, &fsck_obj_options))
objerror(obj, "broken links");
if (fsck_object(obj, NULL, 0, check_strict, fsck_error_func))
if (fsck_object(obj, NULL, 0, &fsck_obj_options))
return -1;

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

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

fsck_walk_options.walk = mark_object;
fsck_obj_options.walk = mark_used;
fsck_obj_options.error_func = fsck_error_func;
if (check_strict)
fsck_obj_options.strict = 1;

if (show_progress == -1)
show_progress = isatty(2);
if (verbose)
Expand Down
9 changes: 5 additions & 4 deletions builtin/index-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ static int nr_threads;
static int from_stdin;
static int strict;
static int do_fsck_object;
static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;
static int verbose;
static int show_stat;
static int check_self_contained_and_connected;
Expand Down Expand Up @@ -192,7 +193,7 @@ static void cleanup_thread(void)
#endif


static int mark_link(struct object *obj, int type, void *data)
static int mark_link(struct object *obj, int type, void *data, struct fsck_options *options)
{
if (!obj)
return -1;
Expand Down Expand Up @@ -838,10 +839,9 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
if (!obj)
die(_("invalid %s"), typename(type));
if (do_fsck_object &&
fsck_object(obj, buf, size, 1,
fsck_error_function))
fsck_object(obj, buf, size, &fsck_options))
die(_("Error in object"));
if (fsck_walk(obj, mark_link, NULL))
if (fsck_walk(obj, NULL, &fsck_options))
die(_("Not all child objects of %s are reachable"), sha1_to_hex(obj->sha1));

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

check_replace_refs = 0;
fsck_options.walk = mark_link;

reset_pack_idx_option(&opts);
git_config(git_index_pack_config, &opts);
Expand Down
11 changes: 6 additions & 5 deletions builtin/unpack-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ static unsigned char buffer[4096];
static unsigned int offset, len;
static off_t consumed_bytes;
static git_SHA_CTX ctx;
static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;

/*
* When running under --strict mode, objects whose reachability are
Expand Down Expand Up @@ -178,7 +179,7 @@ static void write_cached_object(struct object *obj, struct obj_buffer *obj_buf)
* that have reachability requirements and calls this function.
* Verify its reachability and validity recursively and write it out.
*/
static int check_object(struct object *obj, int type, void *data)
static int check_object(struct object *obj, int type, void *data, struct fsck_options *options)
{
struct obj_buffer *obj_buf;

Expand All @@ -203,10 +204,10 @@ static int check_object(struct object *obj, int type, void *data)
obj_buf = lookup_object_buffer(obj);
if (!obj_buf)
die("Whoops! Cannot find object '%s'", sha1_to_hex(obj->sha1));
if (fsck_object(obj, obj_buf->buffer, obj_buf->size, 1,
fsck_error_function))
if (fsck_object(obj, obj_buf->buffer, obj_buf->size, &fsck_options))
die("Error in object");
if (fsck_walk(obj, check_object, NULL))
fsck_options.walk = check_object;
if (fsck_walk(obj, NULL, &fsck_options))
die("Error on reachable objects of %s", sha1_to_hex(obj->sha1));
write_cached_object(obj, obj_buf);
return 0;
Expand All @@ -217,7 +218,7 @@ static void write_rest(void)
unsigned i;
for (i = 0; i < nr_objects; i++) {
if (obj_list[i].obj)
check_object(obj_list[i].obj, OBJ_ANY, NULL);
check_object(obj_list[i].obj, OBJ_ANY, NULL, NULL);
}
}

Expand Down
Loading

0 comments on commit 2241054

Please sign in to comment.