@@ -393,13 +393,9 @@ static int tar_filter_config(const char *var, const char *value,
tar_filters[nr_tar_filters++] = ar;
}
- if (!strcmp(type, "command")) {
- if (!value)
- return config_error_nonbool(var);
- free(ar->filter_command);
- ar->filter_command = xstrdup(value);
- return 0;
- }
+ if (!strcmp(type, "command"))
+ return git_config_string_dup(&ar->filter_command, var, value);
+
if (!strcmp(type, "remote")) {
if (git_config_bool(var, value))
ar->flags |= ARCHIVER_REMOTE;
@@ -255,11 +255,8 @@ int mingw_core_config(const char *var, const char *value,
}
if (!strcmp(var, "core.unsetenvvars")) {
- if (!value)
- return config_error_nonbool(var);
- free(unset_environment_variables);
- unset_environment_variables = xstrdup(value);
- return 0;
+ return git_config_string_dup(&unset_environment_variables, var,
+ value);
}
if (!strcmp(var, "core.restrictinheritedhandles")) {
@@ -529,10 +529,7 @@ static int read_worktree_config(const char *var, const char *value,
if (strcmp(var, "core.bare") == 0) {
data->is_bare = git_config_bool(var, value);
} else if (strcmp(var, "core.worktree") == 0) {
- if (!value)
- return config_error_nonbool(var);
- free(data->work_tree);
- data->work_tree = xstrdup(value);
+ return git_config_string_dup(&data->work_tree, var, value);
}
return 0;
}
These are cases where the calling code does the exact same thing git_config_string_dup() would do. We can shorten the code a bit by using it. Note in the final case that we rely on leaving the if-else chain to return "0" for success, and now we'll return more directly. The two are equivalent. Signed-off-by: Jeff King <peff@peff.net> --- archive-tar.c | 10 +++------- compat/mingw.c | 7 ++----- setup.c | 5 +---- 3 files changed, 6 insertions(+), 16 deletions(-)