Skip to content

Commit ccb894f

Browse files
committed
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>
1 parent cfaee75 commit ccb894f

6 files changed

Lines changed: 25 additions & 12 deletions

File tree

builtin/blame.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,8 @@ static int git_blame_config(const char *var, const char *value,
739739
ret = git_config_pathname(&str, var, value);
740740
if (ret)
741741
return ret;
742-
string_list_insert(&ignore_revs_file_list, str);
742+
if (str)
743+
string_list_insert(&ignore_revs_file_list, str);
743744
free(str);
744745
return 0;
745746
}

builtin/receive-pack.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,9 @@ static int receive_pack_config(const char *var, const char *value,
177177

178178
if (git_config_pathname(&path, var, value))
179179
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);
182183
free(path);
183184
return 0;
184185
}

fetch-pack.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1872,8 +1872,9 @@ int fetch_pack_fsck_config(const char *var, const char *value,
18721872

18731873
if (git_config_pathname(&path, var, value))
18741874
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);
18771878
free(path);
18781879
return 0;
18791880
}

fsck.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,14 +1351,16 @@ int git_fsck_config(const char *var, const char *value,
13511351

13521352
if (strcmp(var, "fsck.skiplist") == 0) {
13531353
char *path;
1354-
struct strbuf sb = STRBUF_INIT;
13551354

13561355
if (git_config_pathname(&path, var, value))
13571356
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+
}
13621364
return 0;
13631365
}
13641366

gpg-interface.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,8 +794,16 @@ static int git_gpg_config(const char *var, const char *value,
794794
fmtname = "ssh";
795795

796796
if (fmtname) {
797+
char *program;
798+
int status;
799+
797800
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;
799807
}
800808

801809
return 0;

setup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1248,7 +1248,7 @@ static int safe_directory_cb(const char *key, const char *value,
12481248
} else {
12491249
char *allowed = NULL;
12501250

1251-
if (!git_config_pathname(&allowed, key, value)) {
1251+
if (!git_config_pathname(&allowed, key, value) && allowed) {
12521252
char *normalized = NULL;
12531253

12541254
/*

0 commit comments

Comments
 (0)