config: really treat missing optional path as not configured

These callers expect that git_config_pathname() that returns 0 is a signal that the variable they passed has a string they need to act on. But with the introduction of ":(optional)path" earlier, that is no longer the case. If the path specified by the configuration variable is missing, their variable will get a NULL in it, and they need to act on it (often, just refraining from copying it elsewhere). Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Nov 20, 2025 at 11:45 UTC 0bd16856ffb3968de73699ad0555d1fae6c45406
6 files changed +25 -12
builtin/blame.c
+2 -1
@@ -739,7 +739,8 @@ static int git_blame_config(const char *var, const char *value,
739 ret = git_config_pathname(&str, var, value);
740 if (ret)
741 return ret;
742 - string_list_insert(&ignore_revs_file_list, str);
742 + if (str)
743 + string_list_insert(&ignore_revs_file_list, str);
744 free(str);
745 return 0;
746 }
builtin/receive-pack.c
+3 -2
@@ -177,8 +177,9 @@ static int receive_pack_config(const char *var, const char *value,
177
178 if (git_config_pathname(&path, var, value))
179 return -1;
180 - strbuf_addf(&fsck_msg_types, "%cskiplist=%s",
181 - fsck_msg_types.len ? ',' : '=', path);
180 + if (path)
181 + strbuf_addf(&fsck_msg_types, "%cskiplist=%s",
182 + fsck_msg_types.len ? ',' : '=', path);
183 free(path);
184 return 0;
185 }
fetch-pack.c
+3 -2
@@ -1872,8 +1872,9 @@ int fetch_pack_fsck_config(const char *var, const char *value,
1872
1873 if (git_config_pathname(&path, var, value))
1874 return -1;
1875 - strbuf_addf(msg_types, "%cskiplist=%s",
1876 - msg_types->len ? ',' : '=', path);
1875 + if (path)
1876 + strbuf_addf(msg_types, "%cskiplist=%s",
1877 + msg_types->len ? ',' : '=', path);
1878 free(path);
1879 return 0;
1880 }
fsck.c
+7 -5
@@ -1351,14 +1351,16 @@ int git_fsck_config(const char *var, const char *value,
1351
1352 if (strcmp(var, "fsck.skiplist") == 0) {
1353 char *path;
1354 - struct strbuf sb = STRBUF_INIT;
1354
1355 if (git_config_pathname(&path, var, value))
1356 return -1;
1358 - strbuf_addf(&sb, "skiplist=%s", path);
1359 - free(path);
1360 - fsck_set_msg_types(options, sb.buf);
1361 - strbuf_release(&sb);
1357 + if (path) {
1358 + struct strbuf sb = STRBUF_INIT;
1359 + strbuf_addf(&sb, "skiplist=%s", path);
1360 + free(path);
1361 + fsck_set_msg_types(options, sb.buf);
1362 + strbuf_release(&sb);
1363 + }
1364 return 0;
1365 }
1366
gpg-interface.c
+9 -1
@@ -794,8 +794,16 @@ static int git_gpg_config(const char *var, const char *value,
794 fmtname = "ssh";
795
796 if (fmtname) {
797 + char *program;
798 + int status;
799 +
800 fmt = get_format_by_name(fmtname);
798 - return git_config_pathname((char **) &fmt->program, var, value);
801 + status = git_config_pathname(&program, var, value);
802 + if (status)
803 + return status;
804 + if (program)
805 + fmt->program = program;
806 + return status;
807 }
808
809 return 0;
setup.c
+1 -1
@@ -1248,7 +1248,7 @@ static int safe_directory_cb(const char *key, const char *value,
1248 } else {
1249 char *allowed = NULL;
1250
1251 - if (!git_config_pathname(&allowed, key, value)) {
1251 + if (!git_config_pathname(&allowed, key, value) && allowed) {
1252 char *normalized = NULL;
1253
1254 /*