Skip to content

Commit 05596e9

Browse files
jltoblergitster
authored andcommitted
fetch-pack: split out fsck config parsing
When `fetch_pack_config()` is invoked, fetch-pack configuration is parsed from the config. As part of this operation, fsck message severity configuration is assigned to the `fsck_msg_types` global variable. This is optionally used to configure the downstream git-index-pack(1) when the `--strict` option is specified. The same parsed fsck message severity configuration is also needed outside of fetch-pack. Instead of exposing/relying on the existing global state, split out the fsck config parsing logic into `fetch_pack_fsck_config()` and expose it. In a subsequent commit, this is used to provide fsck configuration when invoking `unbundle()`. For `fetch_pack_fsck_config()` to discern between errors and unhandled config variables, the return code when `git_config_path()` errors is changed to a different value also indicating success. This frees up the previous return code to now indicate the provided config variable was unhandled. The behavior remains functionally the same. Signed-off-by: Justin Tobler <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 187574c commit 05596e9

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

fetch-pack.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1857,18 +1857,18 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
18571857
return ref;
18581858
}
18591859

1860-
static int fetch_pack_config_cb(const char *var, const char *value,
1861-
const struct config_context *ctx, void *cb)
1860+
int fetch_pack_fsck_config(const char *var, const char *value,
1861+
struct strbuf *msg_types)
18621862
{
18631863
const char *msg_id;
18641864

18651865
if (strcmp(var, "fetch.fsck.skiplist") == 0) {
18661866
char *path ;
18671867

18681868
if (git_config_pathname(&path, var, value))
1869-
return 1;
1870-
strbuf_addf(&fsck_msg_types, "%cskiplist=%s",
1871-
fsck_msg_types.len ? ',' : '=', path);
1869+
return 0;
1870+
strbuf_addf(msg_types, "%cskiplist=%s",
1871+
msg_types->len ? ',' : '=', path);
18721872
free(path);
18731873
return 0;
18741874
}
@@ -1877,14 +1877,24 @@ static int fetch_pack_config_cb(const char *var, const char *value,
18771877
if (!value)
18781878
return config_error_nonbool(var);
18791879
if (is_valid_msg_type(msg_id, value))
1880-
strbuf_addf(&fsck_msg_types, "%c%s=%s",
1881-
fsck_msg_types.len ? ',' : '=', msg_id, value);
1880+
strbuf_addf(msg_types, "%c%s=%s",
1881+
msg_types->len ? ',' : '=', msg_id, value);
18821882
else
18831883
warning("Skipping unknown msg id '%s'", msg_id);
18841884
return 0;
18851885
}
18861886

1887-
return git_default_config(var, value, ctx, cb);
1887+
return 1;
1888+
}
1889+
1890+
static int fetch_pack_config_cb(const char *var, const char *value,
1891+
const struct config_context *ctx, void *cb)
1892+
{
1893+
int ret = fetch_pack_fsck_config(var, value, &fsck_msg_types);
1894+
if (ret > 0)
1895+
return git_default_config(var, value, ctx, cb);
1896+
1897+
return ret;
18881898
}
18891899

18901900
static void fetch_pack_config(void)

fetch-pack.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,15 @@ int report_unmatched_refs(struct ref **sought, int nr_sought);
106106
*/
107107
int fetch_pack_fsck_objects(void);
108108

109+
/*
110+
* Check if the provided config variable pertains to fetch fsck and if so append
111+
* the configuration to the provided strbuf.
112+
*
113+
* When a fetch fsck config option is successfully processed the function
114+
* returns 0. If the provided config option is unrelated to fetch fsck, 1 is
115+
* returned. Errors return -1.
116+
*/
117+
int fetch_pack_fsck_config(const char *var, const char *value,
118+
struct strbuf *msg_types);
119+
109120
#endif

0 commit comments

Comments
 (0)