]> git.ipfire.org Git - thirdparty/git.git/commitdiff
config: really treat missing optional path as not configured
authorJunio C Hamano <gitster@pobox.com>
Thu, 20 Nov 2025 19:45:35 +0000 (11:45 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 25 Nov 2025 01:00:47 +0000 (17:00 -0800)
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>
builtin/blame.c
builtin/receive-pack.c
fetch-pack.c
fsck.c
gpg-interface.c
setup.c

index 5b10e84b664228e88a1411a80b534b69a9148352..10928341442e0feea39fd4868fe58b57de80af4f 100644 (file)
@@ -739,7 +739,8 @@ static int git_blame_config(const char *var, const char *value,
                ret = git_config_pathname(&str, var, value);
                if (ret)
                        return ret;
-               string_list_insert(&ignore_revs_file_list, str);
+               if (str)
+                       string_list_insert(&ignore_revs_file_list, str);
                free(str);
                return 0;
        }
index 1113137a6f0b3f961fd02822154a41bcdedb6657..471857335429f865f6c599c5e60c24dc092cc6d7 100644 (file)
@@ -177,8 +177,9 @@ static int receive_pack_config(const char *var, const char *value,
 
                if (git_config_pathname(&path, var, value))
                        return -1;
-               strbuf_addf(&fsck_msg_types, "%cskiplist=%s",
-                       fsck_msg_types.len ? ',' : '=', path);
+               if (path)
+                       strbuf_addf(&fsck_msg_types, "%cskiplist=%s",
+                                   fsck_msg_types.len ? ',' : '=', path);
                free(path);
                return 0;
        }
index 46c39f85c4ca9e5adfb5b5882ef8ab98326abd07..33a3f20bfc4d27cc1809d3098b2adba80399d2af 100644 (file)
@@ -1872,8 +1872,9 @@ int fetch_pack_fsck_config(const char *var, const char *value,
 
                if (git_config_pathname(&path, var, value))
                        return -1;
-               strbuf_addf(msg_types, "%cskiplist=%s",
-                       msg_types->len ? ',' : '=', path);
+               if (path)
+                       strbuf_addf(msg_types, "%cskiplist=%s",
+                                   msg_types->len ? ',' : '=', path);
                free(path);
                return 0;
        }
diff --git a/fsck.c b/fsck.c
index 171b424dd57de12093a88d2b10d122639dbb0a43..0c287699d282678c16aac4e41ca6602ae6f22b68 100644 (file)
--- a/fsck.c
+++ b/fsck.c
@@ -1351,14 +1351,16 @@ int git_fsck_config(const char *var, const char *value,
 
        if (strcmp(var, "fsck.skiplist") == 0) {
                char *path;
-               struct strbuf sb = STRBUF_INIT;
 
                if (git_config_pathname(&path, var, value))
                        return -1;
-               strbuf_addf(&sb, "skiplist=%s", path);
-               free(path);
-               fsck_set_msg_types(options, sb.buf);
-               strbuf_release(&sb);
+               if (path) {
+                       struct strbuf sb = STRBUF_INIT;
+                       strbuf_addf(&sb, "skiplist=%s", path);
+                       free(path);
+                       fsck_set_msg_types(options, sb.buf);
+                       strbuf_release(&sb);
+               }
                return 0;
        }
 
index 06e7fb50603d22893e92c9c5f473e3c04d3396bf..8b91a11a430a355b74750ccedf2d0ad3d2e9d763 100644 (file)
@@ -794,8 +794,16 @@ static int git_gpg_config(const char *var, const char *value,
                fmtname = "ssh";
 
        if (fmtname) {
+               char *program;
+               int status;
+
                fmt = get_format_by_name(fmtname);
-               return git_config_pathname((char **) &fmt->program, var, value);
+               status = git_config_pathname(&program, var, value);
+               if (status)
+                       return status;
+               if (program)
+                       fmt->program = program;
+               return status;
        }
 
        return 0;
diff --git a/setup.c b/setup.c
index 98ddbf377f923b987d998ff2a9c3e33c3c8feeaf..18301b5907dc2092df2a79c468cd34cf9241acd0 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -1248,7 +1248,7 @@ static int safe_directory_cb(const char *key, const char *value,
        } else {
                char *allowed = NULL;
 
-               if (!git_config_pathname(&allowed, key, value)) {
+               if (!git_config_pathname(&allowed, key, value) && allowed) {
                        char *normalized = NULL;
 
                        /*