Skip to content

Commit 4c57bd2

Browse files
committed
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 <[email protected]>
1 parent 833abdc commit 4c57bd2

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

builtin/merge.c

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ static int fast_forward_only, option_edit = -1;
5252
static int allow_trivial = 1, have_message;
5353
static int overwrite_ignore = 1;
5454
static struct strbuf merge_msg = STRBUF_INIT;
55-
static struct commit_list *remoteheads;
5655
static struct strategy **use_strategies;
5756
static size_t use_strategies_nr, use_strategies_alloc;
5857
static const char **xopts;
@@ -318,7 +317,7 @@ static void finish_up_to_date(const char *msg)
318317
drop_save();
319318
}
320319

321-
static void squash_message(struct commit *commit)
320+
static void squash_message(struct commit *commit, struct commit_list *remoteheads)
322321
{
323322
struct rev_info rev;
324323
struct strbuf out = STRBUF_INIT;
@@ -366,6 +365,7 @@ static void squash_message(struct commit *commit)
366365
}
367366

368367
static void finish(struct commit *head_commit,
368+
struct commit_list *remoteheads,
369369
const unsigned char *new_head, const char *msg)
370370
{
371371
struct strbuf reflog_message = STRBUF_INIT;
@@ -380,7 +380,7 @@ static void finish(struct commit *head_commit,
380380
getenv("GIT_REFLOG_ACTION"), msg);
381381
}
382382
if (squash) {
383-
squash_message(head_commit);
383+
squash_message(head_commit, remoteheads);
384384
} else {
385385
if (verbosity >= 0 && !merge_msg.len)
386386
printf(_("No merge message -- not updating HEAD\n"));
@@ -681,6 +681,7 @@ int try_merge_command(const char *strategy, size_t xopts_nr,
681681
}
682682

683683
static int try_merge_strategy(const char *strategy, struct commit_list *common,
684+
struct commit_list *remoteheads,
684685
struct commit *head, const char *head_arg)
685686
{
686687
int index_fd;
@@ -874,14 +875,14 @@ static void read_merge_msg(struct strbuf *msg)
874875
die_errno(_("Could not read from '%s'"), filename);
875876
}
876877

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)
879880
{
880881
if (err_msg)
881882
error("%s", err_msg);
882883
fprintf(stderr,
883884
_("Not committing merge; use 'git commit' to complete the merge.\n"));
884-
write_merge_state();
885+
write_merge_state(remoteheads);
885886
exit(1);
886887
}
887888

@@ -892,7 +893,7 @@ N_("Please enter a commit message to explain why this merge is necessary,\n"
892893
"Lines starting with '#' will be ignored, and an empty message aborts\n"
893894
"the commit.\n");
894895

895-
static void prepare_to_commit(void)
896+
static void prepare_to_commit(struct commit_list *remoteheads)
896897
{
897898
struct strbuf msg = STRBUF_INIT;
898899
const char *comment = _(merge_editor_comment);
@@ -905,18 +906,18 @@ static void prepare_to_commit(void)
905906
git_path("MERGE_MSG"), "merge", NULL, NULL);
906907
if (option_edit) {
907908
if (launch_editor(git_path("MERGE_MSG"), NULL, NULL))
908-
abort_commit(NULL);
909+
abort_commit(remoteheads, NULL);
909910
}
910911
read_merge_msg(&msg);
911912
stripspace(&msg, option_edit);
912913
if (!msg.len)
913-
abort_commit(_("Empty commit message."));
914+
abort_commit(remoteheads, _("Empty commit message."));
914915
strbuf_release(&merge_msg);
915916
strbuf_addbuf(&merge_msg, &msg);
916917
strbuf_release(&msg);
917918
}
918919

919-
static int merge_trivial(struct commit *head)
920+
static int merge_trivial(struct commit *head, struct commit_list *remoteheads)
920921
{
921922
unsigned char result_tree[20], result_commit[20];
922923
struct commit_list *parent = xmalloc(sizeof(*parent));
@@ -927,17 +928,18 @@ static int merge_trivial(struct commit *head)
927928
parent->next = xmalloc(sizeof(*parent->next));
928929
parent->next->item = remoteheads->item;
929930
parent->next->next = NULL;
930-
prepare_to_commit();
931+
prepare_to_commit(remoteheads);
931932
if (commit_tree(&merge_msg, result_tree, parent, result_commit, NULL,
932933
sign_commit))
933934
die(_("failed to write commit object"));
934-
finish(head, result_commit, "In-index merge");
935+
finish(head, remoteheads, result_commit, "In-index merge");
935936
drop_save();
936937
return 0;
937938
}
938939

939940
static int finish_automerge(struct commit *head,
940941
struct commit_list *common,
942+
struct commit_list *remoteheads,
941943
unsigned char *result_tree,
942944
const char *wt_strategy)
943945
{
@@ -959,13 +961,13 @@ static int finish_automerge(struct commit *head,
959961
pptr = &commit_list_insert(j->item, pptr)->next;
960962
}
961963
strbuf_addch(&merge_msg, '\n');
962-
prepare_to_commit();
964+
prepare_to_commit(remoteheads);
963965
free_commit_list(remoteheads);
964966
if (commit_tree(&merge_msg, result_tree, parents, result_commit,
965967
NULL, sign_commit))
966968
die(_("failed to write commit object"));
967969
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);
969971
strbuf_release(&buf);
970972
drop_save();
971973
return 0;
@@ -1070,7 +1072,7 @@ static int setup_with_upstream(const char ***argv)
10701072
return i;
10711073
}
10721074

1073-
static void write_merge_state(void)
1075+
static void write_merge_state(struct commit_list *remoteheads)
10741076
{
10751077
const char *filename;
10761078
int fd;
@@ -1148,6 +1150,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
11481150
int best_cnt = -1, merge_was_ok = 0, automerge_was_ok = 0;
11491151
struct commit_list *common = NULL;
11501152
const char *best_strategy = NULL, *wt_strategy = NULL;
1153+
struct commit_list *remoteheads = NULL;
11511154
struct commit_list **remotes = &remoteheads;
11521155
void *branch_to_free;
11531156

@@ -1400,7 +1403,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
14001403
goto done;
14011404
}
14021405

1403-
finish(head_commit, commit->object.sha1, msg.buf);
1406+
finish(head_commit, remoteheads, commit->object.sha1, msg.buf);
14041407
drop_save();
14051408
goto done;
14061409
} else if (!remoteheads->next && common->next)
@@ -1422,7 +1425,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
14221425
if (!read_tree_trivial(common->item->object.sha1,
14231426
head_commit->object.sha1,
14241427
remoteheads->item->object.sha1)) {
1425-
ret = merge_trivial(head_commit);
1428+
ret = merge_trivial(head_commit, remoteheads);
14261429
goto done;
14271430
}
14281431
printf(_("Nope.\n"));
@@ -1493,7 +1496,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
14931496
wt_strategy = use_strategies[i]->name;
14941497

14951498
ret = try_merge_strategy(use_strategies[i]->name,
1496-
common, head_commit, head_arg);
1499+
common, remoteheads,
1500+
head_commit, head_arg);
14971501
if (!option_commit && !ret) {
14981502
merge_was_ok = 1;
14991503
/*
@@ -1535,8 +1539,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
15351539
* auto resolved the merge cleanly.
15361540
*/
15371541
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);
15401544
goto done;
15411545
}
15421546

@@ -1561,13 +1565,14 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
15611565
restore_state(head_commit->object.sha1, stash);
15621566
printf(_("Using the %s to prepare resolving by hand.\n"),
15631567
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);
15651570
}
15661571

15671572
if (squash)
1568-
finish(head_commit, NULL, NULL);
1573+
finish(head_commit, remoteheads, NULL, NULL);
15691574
else
1570-
write_merge_state();
1575+
write_merge_state(remoteheads);
15711576

15721577
if (merge_was_ok)
15731578
fprintf(stderr, _("Automatic merge went well; "

0 commit comments

Comments
 (0)