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