Skip to content

Commit 332a82a

Browse files
pcloudsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ff82d12 commit 332a82a

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

apply.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3374,7 +3374,9 @@ static struct patch *previous_patch(struct apply_state *state,
33743374
return previous;
33753375
}
33763376

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)
33783380
{
33793381
if (S_ISGITLINK(ce->ce_mode)) {
33803382
if (!S_ISDIR(st->st_mode))
@@ -3524,7 +3526,7 @@ static int load_current(struct apply_state *state,
35243526
if (checkout_target(&the_index, ce, &st))
35253527
return -1;
35263528
}
3527-
if (verify_index_match(ce, &st))
3529+
if (verify_index_match(state, ce, &st))
35283530
return error(_("%s: does not match index"), name);
35293531

35303532
status = load_patch_target(state, &buf, ce, &st, patch, name, mode);
@@ -3694,7 +3696,7 @@ static int check_preimage(struct apply_state *state,
36943696
if (checkout_target(&the_index, *ce, st))
36953697
return -1;
36963698
}
3697-
if (!state->cached && verify_index_match(*ce, st))
3699+
if (!state->cached && verify_index_match(state, *ce, st))
36983700
return error(_("%s: does not match index"), old_name);
36993701
if (state->cached)
37003702
st_mode = (*ce)->ce_mode;
@@ -4313,7 +4315,9 @@ static int add_index_file(struct apply_state *state,
43134315
* 0 if everything went well
43144316
* 1 if a recoverable error happened
43154317
*/
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)
43174321
{
43184322
int fd, res;
43194323
struct strbuf nbuf = STRBUF_INIT;
@@ -4371,7 +4375,7 @@ static int create_one_file(struct apply_state *state,
43714375
if (state->cached)
43724376
return 0;
43734377

4374-
res = try_create_file(path, mode, buf, size);
4378+
res = try_create_file(state, path, mode, buf, size);
43754379
if (res < 0)
43764380
return -1;
43774381
if (!res)
@@ -4380,7 +4384,7 @@ static int create_one_file(struct apply_state *state,
43804384
if (errno == ENOENT) {
43814385
if (safe_create_leading_directories(path))
43824386
return 0;
4383-
res = try_create_file(path, mode, buf, size);
4387+
res = try_create_file(state, path, mode, buf, size);
43844388
if (res < 0)
43854389
return -1;
43864390
if (!res)
@@ -4402,7 +4406,7 @@ static int create_one_file(struct apply_state *state,
44024406
for (;;) {
44034407
char newpath[PATH_MAX];
44044408
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);
44064410
if (res < 0)
44074411
return -1;
44084412
if (!res) {

0 commit comments

Comments
 (0)