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 <jltobler@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Justin Tobler committed Nov 27, 2024 at 17:33 UTC 05596e93c50b286fa445af8ae572759be079092d
2 files changed +29 -8
fetch-pack.c
+18 -8
@@ -1857,8 +1857,8 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
1857 return ref;
1858 }
1859
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)
1862 {
1863 const char *msg_id;
1864
@@ -1866,9 +1866,9 @@ static int fetch_pack_config_cb(const char *var, const char *value,
1866 char *path ;
1867
1868 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);
1872 free(path);
1873 return 0;
1874 }
@@ -1877,14 +1877,24 @@ static int fetch_pack_config_cb(const char *var, const char *value,
1877 if (!value)
1878 return config_error_nonbool(var);
1879 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);
1882 else
1883 warning("Skipping unknown msg id '%s'", msg_id);
1884 return 0;
1885 }
1886
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;
1898 }
1899
1900 static void fetch_pack_config(void)
fetch-pack.h
+11
@@ -106,4 +106,15 @@ int report_unmatched_refs(struct ref **sought, int nr_sought);
106 */
107 int fetch_pack_fsck_objects(void);
108
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 +
120 #endif