summaryrefslogtreecommitdiff
path: root/src/config_file.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/config_file.c')
-rw-r--r--src/config_file.c30
1 files changed, 12 insertions, 18 deletions
diff --git a/src/config_file.c b/src/config_file.c
index 90255c929..ea72648aa 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -876,10 +876,8 @@ static char *escape_value(const char *ptr)
ptr++;
}
- if (git_buf_oom(&buf)) {
- git_buf_dispose(&buf);
+ if (git_buf_oom(&buf))
return NULL;
- }
return git_buf_detach(&buf);
}
@@ -1022,8 +1020,8 @@ static int parse_conditional_include(git_config_parser *reader,
static int read_on_variable(
git_config_parser *reader,
const char *current_section,
- char *var_name,
- char *var_value,
+ const char *var_name,
+ const char *var_value,
const char *line,
size_t line_len,
void *data)
@@ -1031,24 +1029,24 @@ static int read_on_variable(
diskfile_parse_state *parse_data = (diskfile_parse_state *)data;
git_buf buf = GIT_BUF_INIT;
git_config_entry *entry;
+ const char *c;
int result = 0;
GIT_UNUSED(line);
GIT_UNUSED(line_len);
- git__strtolower(var_name);
- git_buf_printf(&buf, "%s.%s", current_section, var_name);
- git__free(var_name);
+ git_buf_puts(&buf, current_section);
+ git_buf_putc(&buf, '.');
+ for (c = var_name; *c; c++)
+ git_buf_putc(&buf, git__tolower(*c));
- if (git_buf_oom(&buf)) {
- git__free(var_value);
+ if (git_buf_oom(&buf))
return -1;
- }
entry = git__calloc(1, sizeof(git_config_entry));
GITERR_CHECK_ALLOC(entry);
entry->name = git_buf_detach(&buf);
- entry->value = var_value;
+ entry->value = var_value ? git__strdup(var_value) : NULL;
entry->level = parse_data->level;
entry->include_depth = parse_data->depth;
@@ -1065,7 +1063,6 @@ static int read_on_variable(
result = parse_conditional_include(reader, parse_data,
entry->name, entry->value);
-
return result;
}
@@ -1249,8 +1246,8 @@ static int write_on_section(
static int write_on_variable(
git_config_parser *reader,
const char *current_section,
- char *var_name,
- char *var_value,
+ const char *var_name,
+ const char *var_value,
const char *line,
size_t line_len,
void *data)
@@ -1279,9 +1276,6 @@ static int write_on_variable(
if (has_matched && write_data->preg != NULL)
has_matched = (regexec(write_data->preg, var_value, 0, NULL, 0) == 0);
- git__free(var_name);
- git__free(var_value);
-
/* If this isn't the name/value we're looking for, simply dump the
* existing data back out and continue on.
*/