@@ -1472,7 +1472,7 @@ static int config_parse(
1472
1472
int (* on_section )(struct reader * * reader , const char * current_section , const char * line , size_t line_len , void * data ),
1473
1473
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 ),
1474
1474
int (* on_comment )(struct reader * * reader , const char * line , size_t line_len , void * data ),
1475
- int (* on_eof )(struct reader * * reader , void * data ),
1475
+ int (* on_eof )(struct reader * * reader , const char * current_section , void * data ),
1476
1476
void * data )
1477
1477
{
1478
1478
char * current_section = NULL , * var_name , * var_value , * line_start ;
@@ -1523,7 +1523,7 @@ static int config_parse(
1523
1523
}
1524
1524
1525
1525
if (on_eof )
1526
- result = on_eof (& reader , data );
1526
+ result = on_eof (& reader , current_section , data );
1527
1527
1528
1528
git__free (current_section );
1529
1529
return result ;
@@ -1839,7 +1839,8 @@ static int write_on_comment(struct reader **reader, const char *line, size_t lin
1839
1839
return write_line_to (& write_data -> buffered_comment , line , line_len );
1840
1840
}
1841
1841
1842
- static int write_on_eof (struct reader * * reader , void * data )
1842
+ static int write_on_eof (
1843
+ struct reader * * reader , const char * current_section , void * data )
1843
1844
{
1844
1845
struct write_data * write_data = (struct write_data * )data ;
1845
1846
int result = 0 ;
@@ -1858,7 +1859,11 @@ static int write_on_eof(struct reader **reader, void *data)
1858
1859
* value.
1859
1860
*/
1860
1861
if ((!write_data -> preg || !write_data -> preg_replaced ) && write_data -> value ) {
1861
- if ((result = write_section (write_data -> buf , write_data -> section )) == 0 )
1862
+ /* write the section header unless we're already in it */
1863
+ if (!current_section || strcmp (current_section , write_data -> section ))
1864
+ result = write_section (write_data -> buf , write_data -> section );
1865
+
1866
+ if (!result )
1862
1867
result = write_value (write_data );
1863
1868
}
1864
1869
0 commit comments