@@ -553,30 +553,15 @@ static int config_set_multivar(
553553 git_config_backend * cfg , const char * name , const char * regexp , const char * value )
554554{
555555 diskfile_backend * b = (diskfile_backend * )cfg ;
556- refcounted_strmap * map ;
557- git_strmap * values ;
558556 char * key ;
559557 regex_t preg ;
560558 int result ;
561- khiter_t pos ;
562559
563560 assert (regexp );
564561
565562 if ((result = git_config__normalize_name (name , & key )) < 0 )
566563 return result ;
567564
568- map = refcounted_strmap_take (& b -> header );
569- values = b -> header .values -> values ;
570-
571- pos = git_strmap_lookup_index (values , key );
572- if (!git_strmap_valid_index (values , pos )) {
573- /* If we don't have it, behave like a normal set */
574- result = config_set (cfg , name , value );
575- refcounted_strmap_free (map );
576- git__free (key );
577- return result ;
578- }
579-
580565 result = regcomp (& preg , regexp , REG_EXTENDED );
581566 if (result != 0 ) {
582567 giterr_set_regex (& preg , result );
@@ -591,7 +576,6 @@ static int config_set_multivar(
591576 result = config_refresh (cfg );
592577
593578out :
594- refcounted_strmap_free (map );
595579 git__free (key );
596580 regfree (& preg );
597581
@@ -1032,6 +1016,11 @@ static int parse_section_header_ext(struct reader *reader, const char *line, con
10321016 */
10331017
10341018 first_quote = strchr (line , '"' );
1019+ if (first_quote == NULL ) {
1020+ set_parse_error (reader , 0 , "Missing quotation marks in section header" );
1021+ return -1 ;
1022+ }
1023+
10351024 last_quote = strrchr (line , '"' );
10361025 quoted_len = last_quote - first_quote ;
10371026
@@ -1483,7 +1472,7 @@ static int config_parse(
14831472 int (* on_section )(struct reader * * reader , const char * current_section , const char * line , size_t line_len , void * data ),
14841473 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 ),
14851474 int (* on_comment )(struct reader * * reader , const char * line , size_t line_len , void * data ),
1486- int (* on_eof )(struct reader * * reader , void * data ),
1475+ int (* on_eof )(struct reader * * reader , const char * current_section , void * data ),
14871476 void * data )
14881477{
14891478 char * current_section = NULL , * var_name , * var_value , * line_start ;
@@ -1534,7 +1523,7 @@ static int config_parse(
15341523 }
15351524
15361525 if (on_eof )
1537- result = on_eof (& reader , data );
1526+ result = on_eof (& reader , current_section , data );
15381527
15391528 git__free (current_section );
15401529 return result ;
@@ -1850,7 +1839,8 @@ static int write_on_comment(struct reader **reader, const char *line, size_t lin
18501839 return write_line_to (& write_data -> buffered_comment , line , line_len );
18511840}
18521841
1853- 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 )
18541844{
18551845 struct write_data * write_data = (struct write_data * )data ;
18561846 int result = 0 ;
@@ -1869,7 +1859,11 @@ static int write_on_eof(struct reader **reader, void *data)
18691859 * value.
18701860 */
18711861 if ((!write_data -> preg || !write_data -> preg_replaced ) && write_data -> value ) {
1872- 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 )
18731867 result = write_value (write_data );
18741868 }
18751869
0 commit comments