@@ -91,7 +91,7 @@ struct checkout_opts {
91
91
int new_branch_log ;
92
92
enum branch_track track ;
93
93
struct diff_options diff_options ;
94
- char * conflict_style ;
94
+ int conflict_style ;
95
95
96
96
int branch_exists ;
97
97
const char * prefix ;
@@ -100,6 +100,8 @@ struct checkout_opts {
100
100
struct tree * source_tree ;
101
101
};
102
102
103
+ #define CHECKOUT_OPTS_INIT { .conflict_style = -1 }
104
+
103
105
struct branch_info {
104
106
char * name ; /* The short name used */
105
107
char * path ; /* The full name of a real branch */
@@ -251,7 +253,8 @@ static int checkout_stage(int stage, const struct cache_entry *ce, int pos,
251
253
}
252
254
253
255
static int checkout_merged (int pos , const struct checkout * state ,
254
- int * nr_checkouts , struct mem_pool * ce_mem_pool )
256
+ int * nr_checkouts , struct mem_pool * ce_mem_pool ,
257
+ int conflict_style )
255
258
{
256
259
struct cache_entry * ce = the_index .cache [pos ];
257
260
const char * path = ce -> name ;
@@ -286,6 +289,7 @@ static int checkout_merged(int pos, const struct checkout *state,
286
289
287
290
git_config_get_bool ("merge.renormalize" , & renormalize );
288
291
ll_opts .renormalize = renormalize ;
292
+ ll_opts .conflict_style = conflict_style ;
289
293
merge_status = ll_merge (& result_buf , path , & ancestor , "base" ,
290
294
& ours , "ours" , & theirs , "theirs" ,
291
295
state -> istate , & ll_opts );
@@ -416,7 +420,8 @@ static int checkout_worktree(const struct checkout_opts *opts,
416
420
else if (opts -> merge )
417
421
errs |= checkout_merged (pos , & state ,
418
422
& nr_unmerged ,
419
- & ce_mem_pool );
423
+ & ce_mem_pool ,
424
+ opts -> conflict_style );
420
425
pos = skip_same_name (ce , pos ) - 1 ;
421
426
}
422
427
}
@@ -886,6 +891,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
886
891
}
887
892
o .branch1 = new_branch_info -> name ;
888
893
o .branch2 = "local" ;
894
+ o .conflict_style = opts -> conflict_style ;
889
895
ret = merge_trees (& o ,
890
896
new_tree ,
891
897
work ,
@@ -1616,6 +1622,21 @@ static int checkout_branch(struct checkout_opts *opts,
1616
1622
return switch_branches (opts , new_branch_info );
1617
1623
}
1618
1624
1625
+ static int parse_opt_conflict (const struct option * o , const char * arg , int unset )
1626
+ {
1627
+ struct checkout_opts * opts = o -> value ;
1628
+
1629
+ if (unset ) {
1630
+ opts -> conflict_style = -1 ;
1631
+ return 0 ;
1632
+ }
1633
+ opts -> conflict_style = parse_conflict_style_name (arg );
1634
+ if (opts -> conflict_style < 0 )
1635
+ return error (_ ("unknown conflict style '%s'" ), arg );
1636
+
1637
+ return 0 ;
1638
+ }
1639
+
1619
1640
static struct option * add_common_options (struct checkout_opts * opts ,
1620
1641
struct option * prevopts )
1621
1642
{
@@ -1626,8 +1647,9 @@ static struct option *add_common_options(struct checkout_opts *opts,
1626
1647
PARSE_OPT_OPTARG , option_parse_recurse_submodules_worktree_updater ),
1627
1648
OPT_BOOL (0 , "progress" , & opts -> show_progress , N_ ("force progress reporting" )),
1628
1649
OPT_BOOL ('m' , "merge" , & opts -> merge , N_ ("perform a 3-way merge with the new branch" )),
1629
- OPT_STRING (0 , "conflict" , & opts -> conflict_style , N_ ("style" ),
1630
- N_ ("conflict style (merge, diff3, or zdiff3)" )),
1650
+ OPT_CALLBACK (0 , "conflict" , opts , N_ ("style" ),
1651
+ N_ ("conflict style (merge, diff3, or zdiff3)" ),
1652
+ parse_opt_conflict ),
1631
1653
OPT_END ()
1632
1654
};
1633
1655
struct option * newopts = parse_options_concat (prevopts , options );
@@ -1718,15 +1740,9 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
1718
1740
opts -> show_progress = isatty (2 );
1719
1741
}
1720
1742
1721
- if (opts -> conflict_style ) {
1722
- struct key_value_info kvi = KVI_INIT ;
1723
- struct config_context ctx = {
1724
- .kvi = & kvi ,
1725
- };
1743
+ if (opts -> conflict_style >= 0 )
1726
1744
opts -> merge = 1 ; /* implied */
1727
- git_xmerge_config ("merge.conflictstyle" , opts -> conflict_style ,
1728
- & ctx , NULL );
1729
- }
1745
+
1730
1746
if (opts -> force ) {
1731
1747
opts -> discard_changes = 1 ;
1732
1748
opts -> ignore_unmerged_opt = "--force" ;
@@ -1891,7 +1907,7 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
1891
1907
1892
1908
int cmd_checkout (int argc , const char * * argv , const char * prefix )
1893
1909
{
1894
- struct checkout_opts opts ;
1910
+ struct checkout_opts opts = CHECKOUT_OPTS_INIT ;
1895
1911
struct option * options ;
1896
1912
struct option checkout_options [] = {
1897
1913
OPT_STRING ('b' , NULL , & opts .new_branch , N_ ("branch" ),
@@ -1907,7 +1923,6 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
1907
1923
int ret ;
1908
1924
struct branch_info new_branch_info = { 0 };
1909
1925
1910
- memset (& opts , 0 , sizeof (opts ));
1911
1926
opts .dwim_new_local_branch = 1 ;
1912
1927
opts .switch_branch_doing_nothing_is_ok = 1 ;
1913
1928
opts .only_merge_on_switching_branches = 0 ;
@@ -1946,7 +1961,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
1946
1961
1947
1962
int cmd_switch (int argc , const char * * argv , const char * prefix )
1948
1963
{
1949
- struct checkout_opts opts ;
1964
+ struct checkout_opts opts = CHECKOUT_OPTS_INIT ;
1950
1965
struct option * options = NULL ;
1951
1966
struct option switch_options [] = {
1952
1967
OPT_STRING ('c' , "create" , & opts .new_branch , N_ ("branch" ),
@@ -1962,7 +1977,6 @@ int cmd_switch(int argc, const char **argv, const char *prefix)
1962
1977
int ret ;
1963
1978
struct branch_info new_branch_info = { 0 };
1964
1979
1965
- memset (& opts , 0 , sizeof (opts ));
1966
1980
opts .dwim_new_local_branch = 1 ;
1967
1981
opts .accept_ref = 1 ;
1968
1982
opts .accept_pathspec = 0 ;
@@ -1988,7 +2002,7 @@ int cmd_switch(int argc, const char **argv, const char *prefix)
1988
2002
1989
2003
int cmd_restore (int argc , const char * * argv , const char * prefix )
1990
2004
{
1991
- struct checkout_opts opts ;
2005
+ struct checkout_opts opts = CHECKOUT_OPTS_INIT ;
1992
2006
struct option * options ;
1993
2007
struct option restore_options [] = {
1994
2008
OPT_STRING ('s' , "source" , & opts .from_treeish , "<tree-ish>" ,
@@ -2005,7 +2019,6 @@ int cmd_restore(int argc, const char **argv, const char *prefix)
2005
2019
int ret ;
2006
2020
struct branch_info new_branch_info = { 0 };
2007
2021
2008
- memset (& opts , 0 , sizeof (opts ));
2009
2022
opts .accept_ref = 0 ;
2010
2023
opts .accept_pathspec = 1 ;
2011
2024
opts .empty_pathspec_ok = 0 ;
0 commit comments