we're going to remove the dependency on the_index by moving 'struct index_state *' to somewhere inside struct apply_state. Let's make sure relevant functions have access to this struct now and reduce the diff noise when the actual conversion happens. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx> --- apply.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/apply.c b/apply.c index 2476f06ebd..572cd639a6 100644 --- a/apply.c +++ b/apply.c @@ -3374,7 +3374,9 @@ static struct patch *previous_patch(struct apply_state *state, return previous; } -static int verify_index_match(const struct cache_entry *ce, struct stat *st) +static int verify_index_match(struct apply_state *state, + const struct cache_entry *ce, + struct stat *st) { if (S_ISGITLINK(ce->ce_mode)) { if (!S_ISDIR(st->st_mode)) @@ -3524,7 +3526,7 @@ static int load_current(struct apply_state *state, if (checkout_target(&the_index, ce, &st)) return -1; } - if (verify_index_match(ce, &st)) + if (verify_index_match(state, ce, &st)) return error(_("%s: does not match index"), name); status = load_patch_target(state, &buf, ce, &st, patch, name, mode); @@ -3694,7 +3696,7 @@ static int check_preimage(struct apply_state *state, if (checkout_target(&the_index, *ce, st)) return -1; } - if (!state->cached && verify_index_match(*ce, st)) + if (!state->cached && verify_index_match(state, *ce, st)) return error(_("%s: does not match index"), old_name); if (state->cached) st_mode = (*ce)->ce_mode; @@ -4313,7 +4315,9 @@ static int add_index_file(struct apply_state *state, * 0 if everything went well * 1 if a recoverable error happened */ -static int try_create_file(const char *path, unsigned int mode, const char *buf, unsigned long size) +static int try_create_file(struct apply_state *state, const char *path, + unsigned int mode, const char *buf, + unsigned long size) { int fd, res; struct strbuf nbuf = STRBUF_INIT; @@ -4371,7 +4375,7 @@ static int create_one_file(struct apply_state *state, if (state->cached) return 0; - res = try_create_file(path, mode, buf, size); + res = try_create_file(state, path, mode, buf, size); if (res < 0) return -1; if (!res) @@ -4380,7 +4384,7 @@ static int create_one_file(struct apply_state *state, if (errno == ENOENT) { if (safe_create_leading_directories(path)) return 0; - res = try_create_file(path, mode, buf, size); + res = try_create_file(state, path, mode, buf, size); if (res < 0) return -1; if (!res) @@ -4402,7 +4406,7 @@ static int create_one_file(struct apply_state *state, for (;;) { char newpath[PATH_MAX]; mksnpath(newpath, sizeof(newpath), "%s~%u", path, nr); - res = try_create_file(newpath, mode, buf, size); + res = try_create_file(state, newpath, mode, buf, size); if (res < 0) return -1; if (!res) { -- 2.18.0.1004.g6639190530