apply.c: pass struct apply_state to more functions

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@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 332a82a52222da253cd5023cd4c5cde2d51636b9
1 file changed +11 -7
apply.c
+11 -7
@@ -3374,7 +3374,9 @@ static struct patch *previous_patch(struct apply_state *state,
3374 return previous;
3375 }
3376
3377 -static int verify_index_match(const struct cache_entry *ce, struct stat *st)
3377 +static int verify_index_match(struct apply_state *state,
3378 + const struct cache_entry *ce,
3379 + struct stat *st)
3380 {
3381 if (S_ISGITLINK(ce->ce_mode)) {
3382 if (!S_ISDIR(st->st_mode))
@@ -3524,7 +3526,7 @@ static int load_current(struct apply_state *state,
3526 if (checkout_target(&the_index, ce, &st))
3527 return -1;
3528 }
3527 - if (verify_index_match(ce, &st))
3529 + if (verify_index_match(state, ce, &st))
3530 return error(_("%s: does not match index"), name);
3531
3532 status = load_patch_target(state, &buf, ce, &st, patch, name, mode);
@@ -3694,7 +3696,7 @@ static int check_preimage(struct apply_state *state,
3696 if (checkout_target(&the_index, *ce, st))
3697 return -1;
3698 }
3697 - if (!state->cached && verify_index_match(*ce, st))
3699 + if (!state->cached && verify_index_match(state, *ce, st))
3700 return error(_("%s: does not match index"), old_name);
3701 if (state->cached)
3702 st_mode = (*ce)->ce_mode;
@@ -4313,7 +4315,9 @@ static int add_index_file(struct apply_state *state,
4315 * 0 if everything went well
4316 * 1 if a recoverable error happened
4317 */
4316 -static int try_create_file(const char *path, unsigned int mode, const char *buf, unsigned long size)
4318 +static int try_create_file(struct apply_state *state, const char *path,
4319 + unsigned int mode, const char *buf,
4320 + unsigned long size)
4321 {
4322 int fd, res;
4323 struct strbuf nbuf = STRBUF_INIT;
@@ -4371,7 +4375,7 @@ static int create_one_file(struct apply_state *state,
4375 if (state->cached)
4376 return 0;
4377
4374 - res = try_create_file(path, mode, buf, size);
4378 + res = try_create_file(state, path, mode, buf, size);
4379 if (res < 0)
4380 return -1;
4381 if (!res)
@@ -4380,7 +4384,7 @@ static int create_one_file(struct apply_state *state,
4384 if (errno == ENOENT) {
4385 if (safe_create_leading_directories(path))
4386 return 0;
4383 - res = try_create_file(path, mode, buf, size);
4387 + res = try_create_file(state, path, mode, buf, size);
4388 if (res < 0)
4389 return -1;
4390 if (!res)
@@ -4402,7 +4406,7 @@ static int create_one_file(struct apply_state *state,
4406 for (;;) {
4407 char newpath[PATH_MAX];
4408 mksnpath(newpath, sizeof(newpath), "%s~%u", path, nr);
4405 - res = try_create_file(newpath, mode, buf, size);
4409 + res = try_create_file(state, newpath, mode, buf, size);
4410 if (res < 0)
4411 return -1;
4412 if (!res) {