[PATCH 11/21] merge.c: remove implicit dependency on the_index
flat view
STALE2920d
SUPERSEDED
From: Nguyễn Thái Ngọc Duy <hidden>
Date: 2018-08-26 10:03:48
Subsystem:
the rest · Maintainer:
Linus Torvalds
Revision v1 of 5 in this series.
Revisions (5)
Signed-off-by: Nguyễn Thái Ngọc Duy <redacted> --- builtin/merge.c | 8 +++++--- builtin/pull.c | 7 +++++-- cache.h | 6 ++++-- merge.c | 20 +++++++++++--------- sequencer.c | 6 +++--- 5 files changed, 28 insertions(+), 19 deletions(-)
diff --git a/builtin/merge.c b/builtin/merge.c
index 0a37d5ef2c..a56754db5c 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c@@ -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;
diff --git a/builtin/pull.c b/builtin/pull.c
index 53bc5facfd..9b2f76f9d9 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c@@ -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 31013ce8af..218edaa198 100644
--- a/cache.h
+++ b/cache.h@@ -1706,10 +1706,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 *repo, + 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 *repo, + const struct object_id *from, const struct object_id *to, int overwrite_ignore);
diff --git a/merge.c b/merge.c
index e30e03fb84..3c8c769e50 100644
--- 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 *repo, + 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(repo->index); + if (read_index(repo->index) < 0) die(_("failed to read the cache")); - resolve_undo_clear(); + resolve_undo_clear_index(repo->index); return ret; } -int checkout_fast_forward(const struct object_id *head, +int checkout_fast_forward(struct repository *repo, + 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(repo->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 = repo->index; + opts.dst_index = repo->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(repo->index, &lock_file, COMMIT_LOCK)) return error(_("unable to write new index file")); return 0; }
diff --git a/sequencer.c b/sequencer.c
index 65d371c746..83c1f0e42b 100644
--- a/sequencer.c
+++ b/sequencer.c@@ -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)));
@@ -1798,7 +1798,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);
--
2.19.0.rc0.337.ge906d732e7