@@ -52,7 +52,6 @@ static int fast_forward_only, option_edit = -1;
52
52
static int allow_trivial = 1 , have_message ;
53
53
static int overwrite_ignore = 1 ;
54
54
static struct strbuf merge_msg = STRBUF_INIT ;
55
- static struct commit_list * remoteheads ;
56
55
static struct strategy * * use_strategies ;
57
56
static size_t use_strategies_nr , use_strategies_alloc ;
58
57
static const char * * xopts ;
@@ -318,7 +317,7 @@ static void finish_up_to_date(const char *msg)
318
317
drop_save ();
319
318
}
320
319
321
- static void squash_message (struct commit * commit )
320
+ static void squash_message (struct commit * commit , struct commit_list * remoteheads )
322
321
{
323
322
struct rev_info rev ;
324
323
struct strbuf out = STRBUF_INIT ;
@@ -366,6 +365,7 @@ static void squash_message(struct commit *commit)
366
365
}
367
366
368
367
static void finish (struct commit * head_commit ,
368
+ struct commit_list * remoteheads ,
369
369
const unsigned char * new_head , const char * msg )
370
370
{
371
371
struct strbuf reflog_message = STRBUF_INIT ;
@@ -380,7 +380,7 @@ static void finish(struct commit *head_commit,
380
380
getenv ("GIT_REFLOG_ACTION" ), msg );
381
381
}
382
382
if (squash ) {
383
- squash_message (head_commit );
383
+ squash_message (head_commit , remoteheads );
384
384
} else {
385
385
if (verbosity >= 0 && !merge_msg .len )
386
386
printf (_ ("No merge message -- not updating HEAD\n" ));
@@ -681,6 +681,7 @@ int try_merge_command(const char *strategy, size_t xopts_nr,
681
681
}
682
682
683
683
static int try_merge_strategy (const char * strategy , struct commit_list * common ,
684
+ struct commit_list * remoteheads ,
684
685
struct commit * head , const char * head_arg )
685
686
{
686
687
int index_fd ;
@@ -874,14 +875,14 @@ static void read_merge_msg(struct strbuf *msg)
874
875
die_errno (_ ("Could not read from '%s'" ), filename );
875
876
}
876
877
877
- static void write_merge_state (void );
878
- static void abort_commit (const char * err_msg )
878
+ static void write_merge_state (struct commit_list * );
879
+ static void abort_commit (struct commit_list * remoteheads , const char * err_msg )
879
880
{
880
881
if (err_msg )
881
882
error ("%s" , err_msg );
882
883
fprintf (stderr ,
883
884
_ ("Not committing merge; use 'git commit' to complete the merge.\n" ));
884
- write_merge_state ();
885
+ write_merge_state (remoteheads );
885
886
exit (1 );
886
887
}
887
888
@@ -892,7 +893,7 @@ N_("Please enter a commit message to explain why this merge is necessary,\n"
892
893
"Lines starting with '#' will be ignored, and an empty message aborts\n"
893
894
"the commit.\n" );
894
895
895
- static void prepare_to_commit (void )
896
+ static void prepare_to_commit (struct commit_list * remoteheads )
896
897
{
897
898
struct strbuf msg = STRBUF_INIT ;
898
899
const char * comment = _ (merge_editor_comment );
@@ -905,18 +906,18 @@ static void prepare_to_commit(void)
905
906
git_path ("MERGE_MSG" ), "merge" , NULL , NULL );
906
907
if (option_edit ) {
907
908
if (launch_editor (git_path ("MERGE_MSG" ), NULL , NULL ))
908
- abort_commit (NULL );
909
+ abort_commit (remoteheads , NULL );
909
910
}
910
911
read_merge_msg (& msg );
911
912
stripspace (& msg , option_edit );
912
913
if (!msg .len )
913
- abort_commit (_ ("Empty commit message." ));
914
+ abort_commit (remoteheads , _ ("Empty commit message." ));
914
915
strbuf_release (& merge_msg );
915
916
strbuf_addbuf (& merge_msg , & msg );
916
917
strbuf_release (& msg );
917
918
}
918
919
919
- static int merge_trivial (struct commit * head )
920
+ static int merge_trivial (struct commit * head , struct commit_list * remoteheads )
920
921
{
921
922
unsigned char result_tree [20 ], result_commit [20 ];
922
923
struct commit_list * parent = xmalloc (sizeof (* parent ));
@@ -927,17 +928,18 @@ static int merge_trivial(struct commit *head)
927
928
parent -> next = xmalloc (sizeof (* parent -> next ));
928
929
parent -> next -> item = remoteheads -> item ;
929
930
parent -> next -> next = NULL ;
930
- prepare_to_commit ();
931
+ prepare_to_commit (remoteheads );
931
932
if (commit_tree (& merge_msg , result_tree , parent , result_commit , NULL ,
932
933
sign_commit ))
933
934
die (_ ("failed to write commit object" ));
934
- finish (head , result_commit , "In-index merge" );
935
+ finish (head , remoteheads , result_commit , "In-index merge" );
935
936
drop_save ();
936
937
return 0 ;
937
938
}
938
939
939
940
static int finish_automerge (struct commit * head ,
940
941
struct commit_list * common ,
942
+ struct commit_list * remoteheads ,
941
943
unsigned char * result_tree ,
942
944
const char * wt_strategy )
943
945
{
@@ -959,13 +961,13 @@ static int finish_automerge(struct commit *head,
959
961
pptr = & commit_list_insert (j -> item , pptr )-> next ;
960
962
}
961
963
strbuf_addch (& merge_msg , '\n' );
962
- prepare_to_commit ();
964
+ prepare_to_commit (remoteheads );
963
965
free_commit_list (remoteheads );
964
966
if (commit_tree (& merge_msg , result_tree , parents , result_commit ,
965
967
NULL , sign_commit ))
966
968
die (_ ("failed to write commit object" ));
967
969
strbuf_addf (& buf , "Merge made by the '%s' strategy." , wt_strategy );
968
- finish (head , result_commit , buf .buf );
970
+ finish (head , remoteheads , result_commit , buf .buf );
969
971
strbuf_release (& buf );
970
972
drop_save ();
971
973
return 0 ;
@@ -1070,7 +1072,7 @@ static int setup_with_upstream(const char ***argv)
1070
1072
return i ;
1071
1073
}
1072
1074
1073
- static void write_merge_state (void )
1075
+ static void write_merge_state (struct commit_list * remoteheads )
1074
1076
{
1075
1077
const char * filename ;
1076
1078
int fd ;
@@ -1148,6 +1150,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1148
1150
int best_cnt = -1 , merge_was_ok = 0 , automerge_was_ok = 0 ;
1149
1151
struct commit_list * common = NULL ;
1150
1152
const char * best_strategy = NULL , * wt_strategy = NULL ;
1153
+ struct commit_list * remoteheads = NULL ;
1151
1154
struct commit_list * * remotes = & remoteheads ;
1152
1155
void * branch_to_free ;
1153
1156
@@ -1400,7 +1403,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1400
1403
goto done ;
1401
1404
}
1402
1405
1403
- finish (head_commit , commit -> object .sha1 , msg .buf );
1406
+ finish (head_commit , remoteheads , commit -> object .sha1 , msg .buf );
1404
1407
drop_save ();
1405
1408
goto done ;
1406
1409
} else if (!remoteheads -> next && common -> next )
@@ -1422,7 +1425,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1422
1425
if (!read_tree_trivial (common -> item -> object .sha1 ,
1423
1426
head_commit -> object .sha1 ,
1424
1427
remoteheads -> item -> object .sha1 )) {
1425
- ret = merge_trivial (head_commit );
1428
+ ret = merge_trivial (head_commit , remoteheads );
1426
1429
goto done ;
1427
1430
}
1428
1431
printf (_ ("Nope.\n" ));
@@ -1493,7 +1496,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1493
1496
wt_strategy = use_strategies [i ]-> name ;
1494
1497
1495
1498
ret = try_merge_strategy (use_strategies [i ]-> name ,
1496
- common , head_commit , head_arg );
1499
+ common , remoteheads ,
1500
+ head_commit , head_arg );
1497
1501
if (!option_commit && !ret ) {
1498
1502
merge_was_ok = 1 ;
1499
1503
/*
@@ -1535,8 +1539,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1535
1539
* auto resolved the merge cleanly.
1536
1540
*/
1537
1541
if (automerge_was_ok ) {
1538
- ret = finish_automerge (head_commit , common , result_tree ,
1539
- wt_strategy );
1542
+ ret = finish_automerge (head_commit , common , remoteheads ,
1543
+ result_tree , wt_strategy );
1540
1544
goto done ;
1541
1545
}
1542
1546
@@ -1561,13 +1565,14 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1561
1565
restore_state (head_commit -> object .sha1 , stash );
1562
1566
printf (_ ("Using the %s to prepare resolving by hand.\n" ),
1563
1567
best_strategy );
1564
- try_merge_strategy (best_strategy , common , head_commit , head_arg );
1568
+ try_merge_strategy (best_strategy , common , remoteheads ,
1569
+ head_commit , head_arg );
1565
1570
}
1566
1571
1567
1572
if (squash )
1568
- finish (head_commit , NULL , NULL );
1573
+ finish (head_commit , remoteheads , NULL , NULL );
1569
1574
else
1570
- write_merge_state ();
1575
+ write_merge_state (remoteheads );
1571
1576
1572
1577
if (merge_was_ok )
1573
1578
fprintf (stderr , _ ("Automatic merge went well; "
0 commit comments