@@ -76,10 +76,12 @@ static int parse_ignorewhitespace_option(struct apply_state *state,
76
76
}
77
77
78
78
int init_apply_state (struct apply_state * state ,
79
+ struct repository * repo ,
79
80
const char * prefix )
80
81
{
81
82
memset (state , 0 , sizeof (* state ));
82
83
state -> prefix = prefix ;
84
+ state -> repo = repo ;
83
85
state -> apply = 1 ;
84
86
state -> line_termination = '\n' ;
85
87
state -> p_value = 1 ;
@@ -3374,14 +3376,17 @@ static struct patch *previous_patch(struct apply_state *state,
3374
3376
return previous ;
3375
3377
}
3376
3378
3377
- static int verify_index_match (const struct cache_entry * ce , struct stat * st )
3379
+ static int verify_index_match (struct apply_state * state ,
3380
+ const struct cache_entry * ce ,
3381
+ struct stat * st )
3378
3382
{
3379
3383
if (S_ISGITLINK (ce -> ce_mode )) {
3380
3384
if (!S_ISDIR (st -> st_mode ))
3381
3385
return -1 ;
3382
3386
return 0 ;
3383
3387
}
3384
- return ce_match_stat (ce , st , CE_MATCH_IGNORE_VALID |CE_MATCH_IGNORE_SKIP_WORKTREE );
3388
+ return ie_match_stat (state -> repo -> index , ce , st ,
3389
+ CE_MATCH_IGNORE_VALID | CE_MATCH_IGNORE_SKIP_WORKTREE );
3385
3390
}
3386
3391
3387
3392
#define SUBMODULE_PATCH_WITHOUT_INDEX 1
@@ -3514,17 +3519,17 @@ static int load_current(struct apply_state *state,
3514
3519
if (!patch -> is_new )
3515
3520
BUG ("patch to %s is not a creation" , patch -> old_name );
3516
3521
3517
- pos = cache_name_pos ( name , strlen (name ));
3522
+ pos = index_name_pos ( state -> repo -> index , name , strlen (name ));
3518
3523
if (pos < 0 )
3519
3524
return error (_ ("%s: does not exist in index" ), name );
3520
- ce = active_cache [pos ];
3525
+ ce = state -> repo -> index -> cache [pos ];
3521
3526
if (lstat (name , & st )) {
3522
3527
if (errno != ENOENT )
3523
3528
return error_errno ("%s" , name );
3524
- if (checkout_target (& the_index , ce , & st ))
3529
+ if (checkout_target (state -> repo -> index , ce , & st ))
3525
3530
return -1 ;
3526
3531
}
3527
- if (verify_index_match (ce , & st ))
3532
+ if (verify_index_match (state , ce , & st ))
3528
3533
return error (_ ("%s: does not match index" ), name );
3529
3534
3530
3535
status = load_patch_target (state , & buf , ce , & st , patch , name , mode );
@@ -3683,18 +3688,19 @@ static int check_preimage(struct apply_state *state,
3683
3688
}
3684
3689
3685
3690
if (state -> check_index && !previous ) {
3686
- int pos = cache_name_pos (old_name , strlen (old_name ));
3691
+ int pos = index_name_pos (state -> repo -> index , old_name ,
3692
+ strlen (old_name ));
3687
3693
if (pos < 0 ) {
3688
3694
if (patch -> is_new < 0 )
3689
3695
goto is_new ;
3690
3696
return error (_ ("%s: does not exist in index" ), old_name );
3691
3697
}
3692
- * ce = active_cache [pos ];
3698
+ * ce = state -> repo -> index -> cache [pos ];
3693
3699
if (stat_ret < 0 ) {
3694
- if (checkout_target (& the_index , * ce , st ))
3700
+ if (checkout_target (state -> repo -> index , * ce , st ))
3695
3701
return -1 ;
3696
3702
}
3697
- if (!state -> cached && verify_index_match (* ce , st ))
3703
+ if (!state -> cached && verify_index_match (state , * ce , st ))
3698
3704
return error (_ ("%s: does not match index" ), old_name );
3699
3705
if (state -> cached )
3700
3706
st_mode = (* ce )-> ce_mode ;
@@ -3738,7 +3744,7 @@ static int check_to_create(struct apply_state *state,
3738
3744
struct stat nst ;
3739
3745
3740
3746
if (state -> check_index &&
3741
- cache_name_pos ( new_name , strlen (new_name )) >= 0 &&
3747
+ index_name_pos ( state -> repo -> index , new_name , strlen (new_name )) >= 0 &&
3742
3748
!ok_if_exists )
3743
3749
return EXISTS_IN_INDEX ;
3744
3750
if (state -> cached )
@@ -3827,7 +3833,8 @@ static int path_is_beyond_symlink_1(struct apply_state *state, struct strbuf *na
3827
3833
if (state -> check_index ) {
3828
3834
struct cache_entry * ce ;
3829
3835
3830
- ce = cache_file_exists (name -> buf , name -> len , ignore_case );
3836
+ ce = index_file_exists (state -> repo -> index , name -> buf ,
3837
+ name -> len , ignore_case );
3831
3838
if (ce && S_ISLNK (ce -> ce_mode ))
3832
3839
return 1 ;
3833
3840
} else {
@@ -4002,9 +4009,10 @@ static int check_patch_list(struct apply_state *state, struct patch *patch)
4002
4009
static int read_apply_cache (struct apply_state * state )
4003
4010
{
4004
4011
if (state -> index_file )
4005
- return read_cache_from (state -> index_file );
4012
+ return read_index_from (state -> repo -> index , state -> index_file ,
4013
+ get_git_dir ());
4006
4014
else
4007
- return read_cache ( );
4015
+ return read_index ( state -> repo -> index );
4008
4016
}
4009
4017
4010
4018
/* This function tries to read the object name from the current index */
@@ -4015,10 +4023,10 @@ static int get_current_oid(struct apply_state *state, const char *path,
4015
4023
4016
4024
if (read_apply_cache (state ) < 0 )
4017
4025
return -1 ;
4018
- pos = cache_name_pos ( path , strlen (path ));
4026
+ pos = index_name_pos ( state -> repo -> index , path , strlen (path ));
4019
4027
if (pos < 0 )
4020
4028
return -1 ;
4021
- oidcpy (oid , & active_cache [pos ]-> oid );
4029
+ oidcpy (oid , & state -> repo -> index -> cache [pos ]-> oid );
4022
4030
return 0 ;
4023
4031
}
4024
4032
@@ -4246,7 +4254,7 @@ static void patch_stats(struct apply_state *state, struct patch *patch)
4246
4254
static int remove_file (struct apply_state * state , struct patch * patch , int rmdir_empty )
4247
4255
{
4248
4256
if (state -> update_index && !state -> ita_only ) {
4249
- if (remove_file_from_cache ( patch -> old_name ) < 0 )
4257
+ if (remove_file_from_index ( state -> repo -> index , patch -> old_name ) < 0 )
4250
4258
return error (_ ("unable to remove %s from index" ), patch -> old_name );
4251
4259
}
4252
4260
if (!state -> cached ) {
@@ -4267,7 +4275,7 @@ static int add_index_file(struct apply_state *state,
4267
4275
struct cache_entry * ce ;
4268
4276
int namelen = strlen (path );
4269
4277
4270
- ce = make_empty_cache_entry (& the_index , namelen );
4278
+ ce = make_empty_cache_entry (state -> repo -> index , namelen );
4271
4279
memcpy (ce -> name , path , namelen );
4272
4280
ce -> ce_mode = create_ce_mode (mode );
4273
4281
ce -> ce_flags = create_ce_flags (0 );
@@ -4299,7 +4307,7 @@ static int add_index_file(struct apply_state *state,
4299
4307
"for newly created file %s" ), path );
4300
4308
}
4301
4309
}
4302
- if (add_cache_entry ( ce , ADD_CACHE_OK_TO_ADD ) < 0 ) {
4310
+ if (add_index_entry ( state -> repo -> index , ce , ADD_CACHE_OK_TO_ADD ) < 0 ) {
4303
4311
discard_cache_entry (ce );
4304
4312
return error (_ ("unable to add cache entry for %s" ), path );
4305
4313
}
@@ -4313,7 +4321,9 @@ static int add_index_file(struct apply_state *state,
4313
4321
* 0 if everything went well
4314
4322
* 1 if a recoverable error happened
4315
4323
*/
4316
- static int try_create_file (const char * path , unsigned int mode , const char * buf , unsigned long size )
4324
+ static int try_create_file (struct apply_state * state , const char * path ,
4325
+ unsigned int mode , const char * buf ,
4326
+ unsigned long size )
4317
4327
{
4318
4328
int fd , res ;
4319
4329
struct strbuf nbuf = STRBUF_INIT ;
@@ -4335,7 +4345,7 @@ static int try_create_file(const char *path, unsigned int mode, const char *buf,
4335
4345
if (fd < 0 )
4336
4346
return 1 ;
4337
4347
4338
- if (convert_to_working_tree (path , buf , size , & nbuf )) {
4348
+ if (convert_to_working_tree (state -> repo -> index , path , buf , size , & nbuf )) {
4339
4349
size = nbuf .len ;
4340
4350
buf = nbuf .buf ;
4341
4351
}
@@ -4371,7 +4381,7 @@ static int create_one_file(struct apply_state *state,
4371
4381
if (state -> cached )
4372
4382
return 0 ;
4373
4383
4374
- res = try_create_file (path , mode , buf , size );
4384
+ res = try_create_file (state , path , mode , buf , size );
4375
4385
if (res < 0 )
4376
4386
return -1 ;
4377
4387
if (!res )
@@ -4380,7 +4390,7 @@ static int create_one_file(struct apply_state *state,
4380
4390
if (errno == ENOENT ) {
4381
4391
if (safe_create_leading_directories (path ))
4382
4392
return 0 ;
4383
- res = try_create_file (path , mode , buf , size );
4393
+ res = try_create_file (state , path , mode , buf , size );
4384
4394
if (res < 0 )
4385
4395
return -1 ;
4386
4396
if (!res )
@@ -4402,7 +4412,7 @@ static int create_one_file(struct apply_state *state,
4402
4412
for (;;) {
4403
4413
char newpath [PATH_MAX ];
4404
4414
mksnpath (newpath , sizeof (newpath ), "%s~%u" , path , nr );
4405
- res = try_create_file (newpath , mode , buf , size );
4415
+ res = try_create_file (state , newpath , mode , buf , size );
4406
4416
if (res < 0 )
4407
4417
return -1 ;
4408
4418
if (!res ) {
@@ -4432,17 +4442,17 @@ static int add_conflicted_stages_file(struct apply_state *state,
4432
4442
namelen = strlen (patch -> new_name );
4433
4443
mode = patch -> new_mode ? patch -> new_mode : (S_IFREG | 0644 );
4434
4444
4435
- remove_file_from_cache ( patch -> new_name );
4445
+ remove_file_from_index ( state -> repo -> index , patch -> new_name );
4436
4446
for (stage = 1 ; stage < 4 ; stage ++ ) {
4437
4447
if (is_null_oid (& patch -> threeway_stage [stage - 1 ]))
4438
4448
continue ;
4439
- ce = make_empty_cache_entry (& the_index , namelen );
4449
+ ce = make_empty_cache_entry (state -> repo -> index , namelen );
4440
4450
memcpy (ce -> name , patch -> new_name , namelen );
4441
4451
ce -> ce_mode = create_ce_mode (mode );
4442
4452
ce -> ce_flags = create_ce_flags (stage );
4443
4453
ce -> ce_namelen = namelen ;
4444
4454
oidcpy (& ce -> oid , & patch -> threeway_stage [stage - 1 ]);
4445
- if (add_cache_entry ( ce , ADD_CACHE_OK_TO_ADD ) < 0 ) {
4455
+ if (add_index_entry ( state -> repo -> index , ce , ADD_CACHE_OK_TO_ADD ) < 0 ) {
4446
4456
discard_cache_entry (ce );
4447
4457
return error (_ ("unable to add cache entry for %s" ),
4448
4458
patch -> new_name );
@@ -4891,7 +4901,7 @@ int apply_all_patches(struct apply_state *state,
4891
4901
}
4892
4902
4893
4903
if (state -> update_index ) {
4894
- res = write_locked_index (& the_index , & state -> lock_file , COMMIT_LOCK );
4904
+ res = write_locked_index (state -> repo -> index , & state -> lock_file , COMMIT_LOCK );
4895
4905
if (res ) {
4896
4906
error (_ ("Unable to write new index file" ));
4897
4907
res = -128 ;
0 commit comments