apply.c: make init_apply_state() take a struct repository

We're moving away from the_index in this code. "struct index_state *" could be added to struct apply_state. But let's aim long term and put struct repository here instead so that we could even avoid more global states in the future. The index will be available via apply_state->repo->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 Aug 13, 2018 at 18:14 UTC 82ea77eca7af238f1ee65f5cbc945a01e16ee97a
4 files changed +8 -2
apply.c
+2
@@ -76,10 +76,12 @@ static int parse_ignorewhitespace_option(struct apply_state *state,
76 }
77
78 int init_apply_state(struct apply_state *state,
79 + struct repository *repo,
80 const char *prefix)
81 {
82 memset(state, 0, sizeof(*state));
83 state->prefix = prefix;
84 + state->repo = repo;
85 state->apply = 1;
86 state->line_termination = '\n';
87 state->p_value = 1;
apply.h
+4
@@ -1,6 +1,8 @@
1 #ifndef APPLY_H
2 #define APPLY_H
3
4 +struct repository;
5 +
6 enum apply_ws_error_action {
7 nowarn_ws_error,
8 warn_on_ws_error,
@@ -62,6 +64,7 @@ struct apply_state {
64 int unsafe_paths;
65
66 /* Other non boolean parameters */
67 + struct repository *repo;
68 const char *index_file;
69 enum apply_verbosity apply_verbosity;
70 const char *fake_ancestor;
@@ -116,6 +119,7 @@ int apply_parse_options(int argc, const char **argv,
119 int *force_apply, int *options,
120 const char * const *apply_usage);
121 int init_apply_state(struct apply_state *state,
122 + struct repository *repo,
123 const char *prefix);
124 void clear_apply_state(struct apply_state *state);
125 int check_apply_state(struct apply_state *state, int force_apply);
builtin/am.c
+1 -1
@@ -1464,7 +1464,7 @@ static int run_apply(const struct am_state *state, const char *index_file)
1464 int force_apply = 0;
1465 int options = 0;
1466
1467 - if (init_apply_state(&apply_state, NULL))
1467 + if (init_apply_state(&apply_state, the_repository, NULL))
1468 BUG("init_apply_state() failed");
1469
1470 argv_array_push(&apply_opts, "apply");
builtin/apply.c
+1 -1
@@ -16,7 +16,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
16 int ret;
17 struct apply_state state;
18
19 - if (init_apply_state(&state, prefix))
19 + if (init_apply_state(&state, the_repository, prefix))
20 exit(128);
21
22 argc = apply_parse_options(argc, argv,