merge.c: remove implicit dependency on the_index

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Sep 21, 2018 at 17:57 UTC 7e196c3a28513225d48bd853846f5618419948c1
5 files changed +28 -19
builtin/merge.c
+5 -3
@@ -728,8 +728,9 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
728 die(_("unable to write %s"), get_index_file());
729 return clean ? 0 : 1;
730 } else {
731 - return try_merge_command(strategy, xopts_nr, xopts,
732 - common, head_arg, remoteheads);
731 + return try_merge_command(the_repository,
732 + strategy, xopts_nr, xopts,
733 + common, head_arg, remoteheads);
734 }
735 }
736
@@ -1470,7 +1471,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1471 goto done;
1472 }
1473
1473 - if (checkout_fast_forward(&head_commit->object.oid,
1474 + if (checkout_fast_forward(the_repository,
1475 + &head_commit->object.oid,
1476 &commit->object.oid,
1477 overwrite_ignore)) {
1478 ret = 1;
builtin/pull.c
+5 -2
@@ -562,7 +562,9 @@ static int pull_into_void(const struct object_id *merge_head,
562 * index/worktree changes that the user already made on the unborn
563 * branch.
564 */
565 - if (checkout_fast_forward(the_hash_algo->empty_tree, merge_head, 0))
565 + if (checkout_fast_forward(the_repository,
566 + the_hash_algo->empty_tree,
567 + merge_head, 0))
568 return 1;
569
570 if (update_ref("initial pull", "HEAD", merge_head, curr_head, 0, UPDATE_REFS_DIE_ON_ERR))
@@ -915,7 +917,8 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
917 "fast-forwarding your working tree from\n"
918 "commit %s."), oid_to_hex(&orig_head));
919
918 - if (checkout_fast_forward(&orig_head, &curr_head, 0))
920 + if (checkout_fast_forward(the_repository, &orig_head,
921 + &curr_head, 0))
922 die(_("Cannot fast-forward your working tree.\n"
923 "After making sure that you saved anything precious from\n"
924 "$ git diff %s\n"
cache.h
+4 -2
@@ -1716,10 +1716,12 @@ extern struct startup_info *startup_info;
1716
1717 /* merge.c */
1718 struct commit_list;
1719 -int try_merge_command(const char *strategy, size_t xopts_nr,
1719 +int try_merge_command(struct repository *r,
1720 + const char *strategy, size_t xopts_nr,
1721 const char **xopts, struct commit_list *common,
1722 const char *head_arg, struct commit_list *remotes);
1722 -int checkout_fast_forward(const struct object_id *from,
1723 +int checkout_fast_forward(struct repository *r,
1724 + const struct object_id *from,
1725 const struct object_id *to,
1726 int overwrite_ignore);
1727
merge.c
+11 -9
@@ -14,7 +14,8 @@ static const char *merge_argument(struct commit *commit)
14 return oid_to_hex(commit ? &commit->object.oid : the_hash_algo->empty_tree);
15 }
16
17 -int try_merge_command(const char *strategy, size_t xopts_nr,
17 +int try_merge_command(struct repository *r,
18 + const char *strategy, size_t xopts_nr,
19 const char **xopts, struct commit_list *common,
20 const char *head_arg, struct commit_list *remotes)
21 {
@@ -35,15 +36,16 @@ int try_merge_command(const char *strategy, size_t xopts_nr,
36 ret = run_command_v_opt(args.argv, RUN_GIT_CMD);
37 argv_array_clear(&args);
38
38 - discard_cache();
39 - if (read_cache() < 0)
39 + discard_index(r->index);
40 + if (read_index(r->index) < 0)
41 die(_("failed to read the cache"));
41 - resolve_undo_clear();
42 + resolve_undo_clear_index(r->index);
43
44 return ret;
45 }
46
46 -int checkout_fast_forward(const struct object_id *head,
47 +int checkout_fast_forward(struct repository *r,
48 + const struct object_id *head,
49 const struct object_id *remote,
50 int overwrite_ignore)
51 {
@@ -54,7 +56,7 @@ int checkout_fast_forward(const struct object_id *head,
56 struct dir_struct dir;
57 struct lock_file lock_file = LOCK_INIT;
58
57 - refresh_cache(REFRESH_QUIET);
59 + refresh_index(r->index, REFRESH_QUIET, NULL, NULL, NULL);
60
61 if (hold_locked_index(&lock_file, LOCK_REPORT_ON_ERROR) < 0)
62 return -1;
@@ -86,8 +88,8 @@ int checkout_fast_forward(const struct object_id *head,
88 }
89
90 opts.head_idx = 1;
89 - opts.src_index = &the_index;
90 - opts.dst_index = &the_index;
91 + opts.src_index = r->index;
92 + opts.dst_index = r->index;
93 opts.update = 1;
94 opts.verbose_update = 1;
95 opts.merge = 1;
@@ -101,7 +103,7 @@ int checkout_fast_forward(const struct object_id *head,
103 }
104 clear_unpack_trees_porcelain(&opts);
105
104 - if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
106 + if (write_locked_index(r->index, &lock_file, COMMIT_LOCK))
107 return error(_("unable to write new index file"));
108 return 0;
109 }
sequencer.c
+3 -3
@@ -470,8 +470,8 @@ static int fast_forward_to(const struct object_id *to, const struct object_id *f
470 struct strbuf sb = STRBUF_INIT;
471 struct strbuf err = STRBUF_INIT;
472
473 - read_cache();
474 - if (checkout_fast_forward(from, to, 1))
473 + read_index(&the_index);
474 + if (checkout_fast_forward(the_repository, from, to, 1))
475 return -1; /* the callee should have complained already */
476
477 strbuf_addf(&sb, _("%s: fast-forward"), _(action_name(opts)));
@@ -1827,7 +1827,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
1827
1828 commit_list_insert(base, &common);
1829 commit_list_insert(next, &remotes);
1830 - res |= try_merge_command(opts->strategy,
1830 + res |= try_merge_command(the_repository, opts->strategy,
1831 opts->xopts_nr, (const char **)opts->xopts,
1832 common, oid_to_hex(&head), remotes);
1833 free_commit_list(common);