Skip to content

Commit 1f3299f

Browse files
avargitster
authored andcommitted
fsck: make fsck_config() re-usable
Move the fsck_config() function from builtin/fsck.c to fsck.[ch]. This allows for re-using it in other tools that expose fsck logic and want to support its configuration variables. A logical continuation of this change would be to use a common function for all of {fetch,receive}.fsck.* and fsck.*. See 5d477a3 (fsck (receive-pack): allow demoting errors to warnings, 2015-06-22) and my own 1362df0 (fetch: implement fetch.fsck.*, 2018-07-27) for the relevant code. However, those routines want to not parse the fsck.skipList into OIDs, but rather pass them along with the --strict option to another process. It would be possible to refactor that whole thing so we support e.g. a "fetch." prefix, then just keep track of the skiplist as a filename instead of parsing it, and learn to spew that all out from our internal structures into something we can append to the --strict option. But instead I'm planning to re-use this in "mktag", which'll just re-use these "fsck.*" variables as-is. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent acf9de4 commit 1f3299f

File tree

3 files changed

+32
-19
lines changed

3 files changed

+32
-19
lines changed

builtin/fsck.c

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -73,25 +73,7 @@ static const char *printable_type(const struct object_id *oid,
7373

7474
static int fsck_config(const char *var, const char *value, void *cb)
7575
{
76-
if (strcmp(var, "fsck.skiplist") == 0) {
77-
const char *path;
78-
struct strbuf sb = STRBUF_INIT;
79-
80-
if (git_config_pathname(&path, var, value))
81-
return 1;
82-
strbuf_addf(&sb, "skiplist=%s", path);
83-
free((char *)path);
84-
fsck_set_msg_types(&fsck_obj_options, sb.buf);
85-
strbuf_release(&sb);
86-
return 0;
87-
}
88-
89-
if (skip_prefix(var, "fsck.", &var)) {
90-
fsck_set_msg_type(&fsck_obj_options, var, value);
91-
return 0;
92-
}
93-
94-
return git_default_config(var, value, cb);
76+
return fsck_config_internal(var, value, cb, &fsck_obj_options);
9577
}
9678

9779
static int objerror(struct object *obj, const char *err)

fsck.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,3 +1310,27 @@ int fsck_finish(struct fsck_options *options)
13101310
oidset_clear(&gitmodules_done);
13111311
return ret;
13121312
}
1313+
1314+
int fsck_config_internal(const char *var, const char *value, void *cb,
1315+
struct fsck_options *options)
1316+
{
1317+
if (strcmp(var, "fsck.skiplist") == 0) {
1318+
const char *path;
1319+
struct strbuf sb = STRBUF_INIT;
1320+
1321+
if (git_config_pathname(&path, var, value))
1322+
return 1;
1323+
strbuf_addf(&sb, "skiplist=%s", path);
1324+
free((char *)path);
1325+
fsck_set_msg_types(options, sb.buf);
1326+
strbuf_release(&sb);
1327+
return 0;
1328+
}
1329+
1330+
if (skip_prefix(var, "fsck.", &var)) {
1331+
fsck_set_msg_type(options, var, value);
1332+
return 0;
1333+
}
1334+
1335+
return git_default_config(var, value, cb);
1336+
}

fsck.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,11 @@ void fsck_put_object_name(struct fsck_options *options,
103103
const char *fsck_describe_object(struct fsck_options *options,
104104
const struct object_id *oid);
105105

106+
/*
107+
* git_config() callback for use by fsck-y tools that want to support
108+
* fsck.<msg> fsck.skipList etc.
109+
*/
110+
int fsck_config_internal(const char *var, const char *value, void *cb,
111+
struct fsck_options *options);
112+
106113
#endif

0 commit comments

Comments
 (0)