Skip to content

Commit 7e196c3

Browse files
pcloudsgitster
authored andcommitted
merge.c: remove implicit dependency on the_index
Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f4a55b2 commit 7e196c3

File tree

5 files changed

+28
-19
lines changed

5 files changed

+28
-19
lines changed

builtin/merge.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -728,8 +728,9 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
728728
die(_("unable to write %s"), get_index_file());
729729
return clean ? 0 : 1;
730730
} 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);
733734
}
734735
}
735736

@@ -1470,7 +1471,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
14701471
goto done;
14711472
}
14721473

1473-
if (checkout_fast_forward(&head_commit->object.oid,
1474+
if (checkout_fast_forward(the_repository,
1475+
&head_commit->object.oid,
14741476
&commit->object.oid,
14751477
overwrite_ignore)) {
14761478
ret = 1;

builtin/pull.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,9 @@ static int pull_into_void(const struct object_id *merge_head,
562562
* index/worktree changes that the user already made on the unborn
563563
* branch.
564564
*/
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))
566568
return 1;
567569

568570
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)
915917
"fast-forwarding your working tree from\n"
916918
"commit %s."), oid_to_hex(&orig_head));
917919

918-
if (checkout_fast_forward(&orig_head, &curr_head, 0))
920+
if (checkout_fast_forward(the_repository, &orig_head,
921+
&curr_head, 0))
919922
die(_("Cannot fast-forward your working tree.\n"
920923
"After making sure that you saved anything precious from\n"
921924
"$ git diff %s\n"

cache.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,10 +1716,12 @@ extern struct startup_info *startup_info;
17161716

17171717
/* merge.c */
17181718
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,
17201721
const char **xopts, struct commit_list *common,
17211722
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,
17231725
const struct object_id *to,
17241726
int overwrite_ignore);
17251727

merge.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ static const char *merge_argument(struct commit *commit)
1414
return oid_to_hex(commit ? &commit->object.oid : the_hash_algo->empty_tree);
1515
}
1616

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,
1819
const char **xopts, struct commit_list *common,
1920
const char *head_arg, struct commit_list *remotes)
2021
{
@@ -35,15 +36,16 @@ int try_merge_command(const char *strategy, size_t xopts_nr,
3536
ret = run_command_v_opt(args.argv, RUN_GIT_CMD);
3637
argv_array_clear(&args);
3738

38-
discard_cache();
39-
if (read_cache() < 0)
39+
discard_index(r->index);
40+
if (read_index(r->index) < 0)
4041
die(_("failed to read the cache"));
41-
resolve_undo_clear();
42+
resolve_undo_clear_index(r->index);
4243

4344
return ret;
4445
}
4546

46-
int checkout_fast_forward(const struct object_id *head,
47+
int checkout_fast_forward(struct repository *r,
48+
const struct object_id *head,
4749
const struct object_id *remote,
4850
int overwrite_ignore)
4951
{
@@ -54,7 +56,7 @@ int checkout_fast_forward(const struct object_id *head,
5456
struct dir_struct dir;
5557
struct lock_file lock_file = LOCK_INIT;
5658

57-
refresh_cache(REFRESH_QUIET);
59+
refresh_index(r->index, REFRESH_QUIET, NULL, NULL, NULL);
5860

5961
if (hold_locked_index(&lock_file, LOCK_REPORT_ON_ERROR) < 0)
6062
return -1;
@@ -86,8 +88,8 @@ int checkout_fast_forward(const struct object_id *head,
8688
}
8789

8890
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;
9193
opts.update = 1;
9294
opts.verbose_update = 1;
9395
opts.merge = 1;
@@ -101,7 +103,7 @@ int checkout_fast_forward(const struct object_id *head,
101103
}
102104
clear_unpack_trees_porcelain(&opts);
103105

104-
if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
106+
if (write_locked_index(r->index, &lock_file, COMMIT_LOCK))
105107
return error(_("unable to write new index file"));
106108
return 0;
107109
}

sequencer.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,8 @@ static int fast_forward_to(const struct object_id *to, const struct object_id *f
470470
struct strbuf sb = STRBUF_INIT;
471471
struct strbuf err = STRBUF_INIT;
472472

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))
475475
return -1; /* the callee should have complained already */
476476

477477
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,
18271827

18281828
commit_list_insert(base, &common);
18291829
commit_list_insert(next, &remotes);
1830-
res |= try_merge_command(opts->strategy,
1830+
res |= try_merge_command(the_repository, opts->strategy,
18311831
opts->xopts_nr, (const char **)opts->xopts,
18321832
common, oid_to_hex(&head), remotes);
18331833
free_commit_list(common);

0 commit comments

Comments
 (0)