@@ -1230,10 +1230,15 @@ static struct {
12301230
12311231static int matches (const char * key , const char * value )
12321232{
1233- return !strcmp (key , store .key ) &&
1234- (store .value_regex == NULL ||
1235- (store .do_not_match ^
1236- (value && !regexec (store .value_regex , value , 0 , NULL , 0 ))));
1233+ if (strcmp (key , store .key ))
1234+ return 0 ; /* not ours */
1235+ if (!store .value_regex )
1236+ return 1 ; /* always matches */
1237+ if (store .value_regex == CONFIG_REGEX_NONE )
1238+ return 0 ; /* never matches */
1239+
1240+ return store .do_not_match ^
1241+ (value && !regexec (store .value_regex , value , 0 , NULL , 0 ));
12371242}
12381243
12391244static int store_aux (const char * key , const char * value , void * cb )
@@ -1495,6 +1500,8 @@ int git_config_parse_key(const char *key, char **store_key, int *baselen_)
14951500/*
14961501 * If value==NULL, unset in (remove from) config,
14971502 * if value_regex!=NULL, disregard key/value pairs where value does not match.
1503+ * if value_regex==CONFIG_REGEX_NONE, do not match any existing values
1504+ * (only add a new one)
14981505 * if multi_replace==0, nothing, or only one matching key/value is replaced,
14991506 * else all matching key/values (regardless how many) are removed,
15001507 * before the new pair is written.
@@ -1578,6 +1585,8 @@ int git_config_set_multivar_in_file(const char *config_filename,
15781585
15791586 if (value_regex == NULL )
15801587 store .value_regex = NULL ;
1588+ else if (value_regex == CONFIG_REGEX_NONE )
1589+ store .value_regex = CONFIG_REGEX_NONE ;
15811590 else {
15821591 if (value_regex [0 ] == '!' ) {
15831592 store .do_not_match = 1 ;
@@ -1609,7 +1618,8 @@ int git_config_set_multivar_in_file(const char *config_filename,
16091618 if (git_config_from_file (store_aux , config_filename , NULL )) {
16101619 error ("invalid config file %s" , config_filename );
16111620 free (store .key );
1612- if (store .value_regex != NULL ) {
1621+ if (store .value_regex != NULL &&
1622+ store .value_regex != CONFIG_REGEX_NONE ) {
16131623 regfree (store .value_regex );
16141624 free (store .value_regex );
16151625 }
@@ -1618,7 +1628,8 @@ int git_config_set_multivar_in_file(const char *config_filename,
16181628 }
16191629
16201630 free (store .key );
1621- if (store .value_regex != NULL ) {
1631+ if (store .value_regex != NULL &&
1632+ store .value_regex != CONFIG_REGEX_NONE ) {
16221633 regfree (store .value_regex );
16231634 free (store .value_regex );
16241635 }
0 commit comments