merge.c: remove implicit dependency on the_index
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Fri, 21 Sep 2018 15:57:29 +0000 (17:57 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 21 Sep 2018 16:48:10 +0000 (09:48 -0700)
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/merge.c
builtin/pull.c
cache.h
merge.c
sequencer.c
index 592cb19caf6ae8056c99b23e0ba12c0571af47de..5f79fc5fd7a80103debbc812482f8cf0d7e8f9da 100644 (file)
@@ -728,8 +728,9 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
                        die(_("unable to write %s"), get_index_file());
                return clean ? 0 : 1;
        } else {
-               return try_merge_command(strategy, xopts_nr, xopts,
-                                               common, head_arg, remoteheads);
+               return try_merge_command(the_repository,
+                                        strategy, xopts_nr, xopts,
+                                        common, head_arg, remoteheads);
        }
 }
 
@@ -1470,7 +1471,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
                        goto done;
                }
 
-               if (checkout_fast_forward(&head_commit->object.oid,
+               if (checkout_fast_forward(the_repository,
+                                         &head_commit->object.oid,
                                          &commit->object.oid,
                                          overwrite_ignore)) {
                        ret = 1;
index 681c127a07071c98641972227a28dbe7f77eaf70..33b7100837d6b49f13d5f2d80336cd36d8cb126a 100644 (file)
@@ -562,7 +562,9 @@ static int pull_into_void(const struct object_id *merge_head,
         * index/worktree changes that the user already made on the unborn
         * branch.
         */
-       if (checkout_fast_forward(the_hash_algo->empty_tree, merge_head, 0))
+       if (checkout_fast_forward(the_repository,
+                                 the_hash_algo->empty_tree,
+                                 merge_head, 0))
                return 1;
 
        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)
                        "fast-forwarding your working tree from\n"
                        "commit %s."), oid_to_hex(&orig_head));
 
-               if (checkout_fast_forward(&orig_head, &curr_head, 0))
+               if (checkout_fast_forward(the_repository, &orig_head,
+                                         &curr_head, 0))
                        die(_("Cannot fast-forward your working tree.\n"
                                "After making sure that you saved anything precious from\n"
                                "$ git diff %s\n"
diff --git a/cache.h b/cache.h
index 260e4ee44ad1c80ee0b5490a661c2998426f32e4..49fe83331c876f8c3a2ce5a77e196bf8c00fa842 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -1716,10 +1716,12 @@ extern struct startup_info *startup_info;
 
 /* merge.c */
 struct commit_list;
-int try_merge_command(const char *strategy, size_t xopts_nr,
+int try_merge_command(struct repository *r,
+               const char *strategy, size_t xopts_nr,
                const char **xopts, struct commit_list *common,
                const char *head_arg, struct commit_list *remotes);
-int checkout_fast_forward(const struct object_id *from,
+int checkout_fast_forward(struct repository *r,
+                         const struct object_id *from,
                          const struct object_id *to,
                          int overwrite_ignore);
 
diff --git a/merge.c b/merge.c
index e30e03fb84a7677520d208a5688bb7170c22bf8e..91008f760223e4f6c65a5d344bb6403dd5885d28 100644 (file)
--- a/merge.c
+++ b/merge.c
@@ -14,7 +14,8 @@ static const char *merge_argument(struct commit *commit)
        return oid_to_hex(commit ? &commit->object.oid : the_hash_algo->empty_tree);
 }
 
-int try_merge_command(const char *strategy, size_t xopts_nr,
+int try_merge_command(struct repository *r,
+                     const char *strategy, size_t xopts_nr,
                      const char **xopts, struct commit_list *common,
                      const char *head_arg, struct commit_list *remotes)
 {
@@ -35,15 +36,16 @@ int try_merge_command(const char *strategy, size_t xopts_nr,
        ret = run_command_v_opt(args.argv, RUN_GIT_CMD);
        argv_array_clear(&args);
 
-       discard_cache();
-       if (read_cache() < 0)
+       discard_index(r->index);
+       if (read_index(r->index) < 0)
                die(_("failed to read the cache"));
-       resolve_undo_clear();
+       resolve_undo_clear_index(r->index);
 
        return ret;
 }
 
-int checkout_fast_forward(const struct object_id *head,
+int checkout_fast_forward(struct repository *r,
+                         const struct object_id *head,
                          const struct object_id *remote,
                          int overwrite_ignore)
 {
@@ -54,7 +56,7 @@ int checkout_fast_forward(const struct object_id *head,
        struct dir_struct dir;
        struct lock_file lock_file = LOCK_INIT;
 
-       refresh_cache(REFRESH_QUIET);
+       refresh_index(r->index, REFRESH_QUIET, NULL, NULL, NULL);
 
        if (hold_locked_index(&lock_file, LOCK_REPORT_ON_ERROR) < 0)
                return -1;
@@ -86,8 +88,8 @@ int checkout_fast_forward(const struct object_id *head,
        }
 
        opts.head_idx = 1;
-       opts.src_index = &the_index;
-       opts.dst_index = &the_index;
+       opts.src_index = r->index;
+       opts.dst_index = r->index;
        opts.update = 1;
        opts.verbose_update = 1;
        opts.merge = 1;
@@ -101,7 +103,7 @@ int checkout_fast_forward(const struct object_id *head,
        }
        clear_unpack_trees_porcelain(&opts);
 
-       if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
+       if (write_locked_index(r->index, &lock_file, COMMIT_LOCK))
                return error(_("unable to write new index file"));
        return 0;
 }
index dc2c58d464c14be033f4bcba2ab4332886ead327..2adc66f45ea8f6aa5038e6d6c1ec627ecc0aba0d 100644 (file)
@@ -470,8 +470,8 @@ static int fast_forward_to(const struct object_id *to, const struct object_id *f
        struct strbuf sb = STRBUF_INIT;
        struct strbuf err = STRBUF_INIT;
 
-       read_cache();
-       if (checkout_fast_forward(from, to, 1))
+       read_index(&the_index);
+       if (checkout_fast_forward(the_repository, from, to, 1))
                return -1; /* the callee should have complained already */
 
        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,
 
                commit_list_insert(base, &common);
                commit_list_insert(next, &remotes);
-               res |= try_merge_command(opts->strategy,
+               res |= try_merge_command(the_repository, opts->strategy,
                                         opts->xopts_nr, (const char **)opts->xopts,
                                        common, oid_to_hex(&head), remotes);
                free_commit_list(common);