diff options
| author | Carlos Martín Nieto <cmn@elego.de> | 2011-06-07 23:32:14 +0200 |
|---|---|---|
| committer | Carlos Martín Nieto <cmn@elego.de> | 2011-06-08 00:23:12 +0200 |
| commit | 3b3577c764ad06cd24bb9047107022abdf6fea90 (patch) | |
| tree | 9ad037a7eeaa0379c664868c22f956f45ad570df | |
| parent | 5ab50417b7d51fff1c88158f0f334f42bfb5a9b7 (diff) | |
| download | libgit2-3b3577c764ad06cd24bb9047107022abdf6fea90.tar.gz | |
config: store new variables with the internal representation of the section
The section name should be stored in its case-sensitive variant when
we are adding a new variable. Use the internalize_section function to
do just that.
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
| -rw-r--r-- | src/config_file.c | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/src/config_file.c b/src/config_file.c index 74162d74f..5e3dabdf7 100644 --- a/src/config_file.c +++ b/src/config_file.c @@ -237,6 +237,39 @@ static int cvar_normalize_name(cvar_t *var, char **output) return GIT_SUCCESS; } +static char *interiorize_section(const char *orig) +{ + char *dot, *last_dot, *section, *ret; + int len; + + dot = strchr(orig, '.'); + last_dot = strrchr(orig, '.'); + len = last_dot - orig; + + /* No subsection, this is easy */ + if (last_dot == dot) + return git__strndup(orig, dot - orig); + + section = git__malloc(len + 4); + if (section == NULL) + return NULL; + + memset(section, 0x0, len + 4); + ret = section; + len = dot - orig; + memcpy(section, orig, len); + section += len; + len = STRLEN(" \""); + memcpy(section, " \"", len); + section += len; + len = last_dot - dot - 1; + memcpy(section, dot + 1, len); + section += len; + *section = '"'; + + return ret; +} + static int config_open(git_config_file *cfg) { int error; @@ -334,7 +367,7 @@ static int config_set(git_config_file *cfg, const char *name, const char *value) memset(var, 0x0, sizeof(cvar_t)); - var->section = git__strndup(name, last_dot - name); + var->section = interiorize_section(name); if (var->section == NULL) { error = GIT_ENOMEM; goto out; |
