summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarlos Martín Nieto <carlosmn@github.com>2016-03-29 03:26:43 -0700
committerCarlos Martín Nieto <carlosmn@github.com>2016-03-29 03:26:43 -0700
commit2f0450f4d635358f6da5d174c128b9ed1059bbf8 (patch)
tree752127195c68b2d000429d743f40fff994de26c7 /src
parentb085ecbe09019f885842c9b7244f9a9c8b639f86 (diff)
parent76e1a679eab9964c2857ead896e170cacb0cef1d (diff)
downloadlibgit2-2f0450f4d635358f6da5d174c128b9ed1059bbf8.tar.gz
Merge pull request #3712 from ethomson/config_duplicate_section
config: don't write duplicate section
Diffstat (limited to 'src')
-rw-r--r--src/config_file.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/config_file.c b/src/config_file.c
index 02bb2f75e..e33b83738 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -1483,7 +1483,7 @@ static int config_parse(
int (*on_section)(struct reader **reader, const char *current_section, const char *line, size_t line_len, void *data),
int (*on_variable)(struct reader **reader, const char *current_section, char *var_name, char *var_value, const char *line, size_t line_len, void *data),
int (*on_comment)(struct reader **reader, const char *line, size_t line_len, void *data),
- int (*on_eof)(struct reader **reader, void *data),
+ int (*on_eof)(struct reader **reader, const char *current_section, void *data),
void *data)
{
char *current_section = NULL, *var_name, *var_value, *line_start;
@@ -1534,7 +1534,7 @@ static int config_parse(
}
if (on_eof)
- result = on_eof(&reader, data);
+ result = on_eof(&reader, current_section, data);
git__free(current_section);
return result;
@@ -1850,7 +1850,8 @@ static int write_on_comment(struct reader **reader, const char *line, size_t lin
return write_line_to(&write_data->buffered_comment, line, line_len);
}
-static int write_on_eof(struct reader **reader, void *data)
+static int write_on_eof(
+ struct reader **reader, const char *current_section, void *data)
{
struct write_data *write_data = (struct write_data *)data;
int result = 0;
@@ -1869,7 +1870,11 @@ static int write_on_eof(struct reader **reader, void *data)
* value.
*/
if ((!write_data->preg || !write_data->preg_replaced) && write_data->value) {
- if ((result = write_section(write_data->buf, write_data->section)) == 0)
+ /* write the section header unless we're already in it */
+ if (!current_section || strcmp(current_section, write_data->section))
+ result = write_section(write_data->buf, write_data->section);
+
+ if (!result)
result = write_value(write_data);
}