@@ -56,6 +56,7 @@ static size_t use_strategies_nr, use_strategies_alloc;
5656static const char * * xopts ;
5757static size_t xopts_nr , xopts_alloc ;
5858static const char * branch ;
59+ static char * branch_mergeoptions ;
5960static int option_renormalize ;
6061static int verbosity ;
6162static int allow_rerere_auto ;
@@ -503,26 +504,34 @@ static void merge_name(const char *remote, struct strbuf *msg)
503504 strbuf_release (& bname );
504505}
505506
507+ static void parse_branch_merge_options (char * bmo )
508+ {
509+ const char * * argv ;
510+ int argc ;
511+
512+ if (!bmo )
513+ return ;
514+ argc = split_cmdline (bmo , & argv );
515+ if (argc < 0 )
516+ die (_ ("Bad branch.%s.mergeoptions string: %s" ), branch ,
517+ split_cmdline_strerror (argc ));
518+ argv = xrealloc (argv , sizeof (* argv ) * (argc + 2 ));
519+ memmove (argv + 1 , argv , sizeof (* argv ) * (argc + 1 ));
520+ argc ++ ;
521+ argv [0 ] = "branch.*.mergeoptions" ;
522+ parse_options (argc , argv , NULL , builtin_merge_options ,
523+ builtin_merge_usage , 0 );
524+ free (argv );
525+ }
526+
506527static int git_merge_config (const char * k , const char * v , void * cb )
507528{
508529 if (branch && !prefixcmp (k , "branch." ) &&
509530 !prefixcmp (k + 7 , branch ) &&
510531 !strcmp (k + 7 + strlen (branch ), ".mergeoptions" )) {
511- const char * * argv ;
512- int argc ;
513- char * buf ;
514-
515- buf = xstrdup (v );
516- argc = split_cmdline (buf , & argv );
517- if (argc < 0 )
518- die (_ ("Bad branch.%s.mergeoptions string: %s" ), branch ,
519- split_cmdline_strerror (argc ));
520- argv = xrealloc (argv , sizeof (* argv ) * (argc + 2 ));
521- memmove (argv + 1 , argv , sizeof (* argv ) * (argc + 1 ));
522- argc ++ ;
523- parse_options (argc , argv , NULL , builtin_merge_options ,
524- builtin_merge_usage , 0 );
525- free (buf );
532+ free (branch_mergeoptions );
533+ branch_mergeoptions = xstrdup (v );
534+ return 0 ;
526535 }
527536
528537 if (!strcmp (k , "merge.diffstat" ) || !strcmp (k , "merge.stat" ))
@@ -1010,6 +1019,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
10101019 if (diff_use_color_default == -1 )
10111020 diff_use_color_default = git_use_color_default ;
10121021
1022+ if (branch_mergeoptions )
1023+ parse_branch_merge_options (branch_mergeoptions );
10131024 argc = parse_options (argc , argv , prefix , builtin_merge_options ,
10141025 builtin_merge_usage , 0 );
10151026
0 commit comments