Git fork

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>

authored by

Justin Tobler and committed by
Junio C Hamano
05596e93 187574ce

+29 -8
+18 -8
fetch-pack.c
··· 1857 1857 return ref; 1858 1858 } 1859 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 1862 { 1863 1863 const char *msg_id; 1864 1864 ··· 1866 1866 char *path ; 1867 1867 1868 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 1872 free(path); 1873 1873 return 0; 1874 1874 } ··· 1877 1877 if (!value) 1878 1878 return config_error_nonbool(var); 1879 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 1882 else 1883 1883 warning("Skipping unknown msg id '%s'", msg_id); 1884 1884 return 0; 1885 1885 } 1886 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; 1888 1898 } 1889 1899 1890 1900 static void fetch_pack_config(void)
+11
fetch-pack.h
··· 106 106 */ 107 107 int fetch_pack_fsck_objects(void); 108 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 + 109 120 #endif