@@ -119,9 +119,10 @@ static void status_printf_more(struct wt_status *s, const char *color,
119
119
va_end (ap );
120
120
}
121
121
122
- void wt_status_prepare (struct wt_status * s )
122
+ void wt_status_prepare (struct repository * r , struct wt_status * s )
123
123
{
124
124
memset (s , 0 , sizeof (* s ));
125
+ s -> repo = r ;
125
126
memcpy (s -> color_palette , default_wt_status_colors ,
126
127
sizeof (default_wt_status_colors ));
127
128
s -> show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES ;
@@ -494,19 +495,19 @@ static void wt_status_collect_changed_cb(struct diff_queue_struct *q,
494
495
}
495
496
}
496
497
497
- static int unmerged_mask (const char * path )
498
+ static int unmerged_mask (struct index_state * istate , const char * path )
498
499
{
499
500
int pos , mask ;
500
501
const struct cache_entry * ce ;
501
502
502
- pos = cache_name_pos ( path , strlen (path ));
503
+ pos = index_name_pos ( istate , path , strlen (path ));
503
504
if (0 <= pos )
504
505
return 0 ;
505
506
506
507
mask = 0 ;
507
508
pos = - pos - 1 ;
508
- while (pos < active_nr ) {
509
- ce = active_cache [pos ++ ];
509
+ while (pos < istate -> cache_nr ) {
510
+ ce = istate -> cache [pos ++ ];
510
511
if (strcmp (ce -> name , path ) || !ce_stage (ce ))
511
512
break ;
512
513
mask |= (1 << (ce_stage (ce ) - 1 ));
@@ -566,7 +567,8 @@ static void wt_status_collect_updated_cb(struct diff_queue_struct *q,
566
567
s -> committable = 1 ;
567
568
break ;
568
569
case DIFF_STATUS_UNMERGED :
569
- d -> stagemask = unmerged_mask (p -> two -> path );
570
+ d -> stagemask = unmerged_mask (s -> repo -> index ,
571
+ p -> two -> path );
570
572
/*
571
573
* Don't bother setting {mode,oid}_{head,index} since the print
572
574
* code will output the stage values directly and not use the
@@ -585,7 +587,7 @@ static void wt_status_collect_changes_worktree(struct wt_status *s)
585
587
{
586
588
struct rev_info rev ;
587
589
588
- repo_init_revisions (the_repository , & rev , NULL );
590
+ repo_init_revisions (s -> repo , & rev , NULL );
589
591
setup_revisions (0 , NULL , & rev , NULL );
590
592
rev .diffopt .output_format |= DIFF_FORMAT_CALLBACK ;
591
593
rev .diffopt .flags .dirty_submodules = 1 ;
@@ -610,7 +612,7 @@ static void wt_status_collect_changes_index(struct wt_status *s)
610
612
struct rev_info rev ;
611
613
struct setup_revision_opt opt ;
612
614
613
- repo_init_revisions (the_repository , & rev , NULL );
615
+ repo_init_revisions (s -> repo , & rev , NULL );
614
616
memset (& opt , 0 , sizeof (opt ));
615
617
opt .def = s -> is_initial ? empty_tree_oid_hex () : s -> reference ;
616
618
setup_revisions (0 , NULL , & rev , & opt );
@@ -643,14 +645,15 @@ static void wt_status_collect_changes_index(struct wt_status *s)
643
645
644
646
static void wt_status_collect_changes_initial (struct wt_status * s )
645
647
{
648
+ struct index_state * istate = s -> repo -> index ;
646
649
int i ;
647
650
648
- for (i = 0 ; i < active_nr ; i ++ ) {
651
+ for (i = 0 ; i < istate -> cache_nr ; i ++ ) {
649
652
struct string_list_item * it ;
650
653
struct wt_status_change_data * d ;
651
- const struct cache_entry * ce = active_cache [i ];
654
+ const struct cache_entry * ce = istate -> cache [i ];
652
655
653
- if (!ce_path_match (& the_index , ce , & s -> pathspec , NULL ))
656
+ if (!ce_path_match (istate , ce , & s -> pathspec , NULL ))
654
657
continue ;
655
658
if (ce_intent_to_add (ce ))
656
659
continue ;
@@ -684,6 +687,7 @@ static void wt_status_collect_untracked(struct wt_status *s)
684
687
int i ;
685
688
struct dir_struct dir ;
686
689
uint64_t t_begin = getnanotime ();
690
+ struct index_state * istate = s -> repo -> index ;
687
691
688
692
if (!s -> show_untracked_files )
689
693
return ;
@@ -698,25 +702,25 @@ static void wt_status_collect_untracked(struct wt_status *s)
698
702
if (s -> show_ignored_mode == SHOW_MATCHING_IGNORED )
699
703
dir .flags |= DIR_SHOW_IGNORED_TOO_MODE_MATCHING ;
700
704
} else {
701
- dir .untracked = the_index . untracked ;
705
+ dir .untracked = istate -> untracked ;
702
706
}
703
707
704
708
setup_standard_excludes (& dir );
705
709
706
- fill_directory (& dir , & the_index , & s -> pathspec );
710
+ fill_directory (& dir , istate , & s -> pathspec );
707
711
708
712
for (i = 0 ; i < dir .nr ; i ++ ) {
709
713
struct dir_entry * ent = dir .entries [i ];
710
- if (cache_name_is_other ( ent -> name , ent -> len ) &&
711
- dir_path_match (& the_index , ent , & s -> pathspec , 0 , NULL ))
714
+ if (index_name_is_other ( istate , ent -> name , ent -> len ) &&
715
+ dir_path_match (istate , ent , & s -> pathspec , 0 , NULL ))
712
716
string_list_insert (& s -> untracked , ent -> name );
713
717
free (ent );
714
718
}
715
719
716
720
for (i = 0 ; i < dir .ignored_nr ; i ++ ) {
717
721
struct dir_entry * ent = dir .ignored [i ];
718
- if (cache_name_is_other ( ent -> name , ent -> len ) &&
719
- dir_path_match (& the_index , ent , & s -> pathspec , 0 , NULL ))
722
+ if (index_name_is_other ( istate , ent -> name , ent -> len ) &&
723
+ dir_path_match (istate , ent , & s -> pathspec , 0 , NULL ))
720
724
string_list_insert (& s -> ignored , ent -> name );
721
725
free (ent );
722
726
}
@@ -1009,7 +1013,7 @@ static void wt_longstatus_print_verbose(struct wt_status *s)
1009
1013
int dirty_submodules ;
1010
1014
const char * c = color (WT_STATUS_HEADER , s );
1011
1015
1012
- repo_init_revisions (the_repository , & rev , NULL );
1016
+ repo_init_revisions (s -> repo , & rev , NULL );
1013
1017
rev .diffopt .flags .allow_textconv = 1 ;
1014
1018
rev .diffopt .ita_invisible_in_index = 1 ;
1015
1019
@@ -1326,7 +1330,7 @@ static void show_rebase_in_progress(struct wt_status *s,
1326
1330
_ (" (use \"git rebase --abort\" to check out the original branch)" ));
1327
1331
}
1328
1332
} else if (s -> state .rebase_in_progress ||
1329
- !stat (git_path_merge_msg (the_repository ), & st )) {
1333
+ !stat (git_path_merge_msg (s -> repo ), & st )) {
1330
1334
print_rebase_state (s , color );
1331
1335
if (s -> hints )
1332
1336
status_printf_ln (s , color ,
@@ -2135,6 +2139,7 @@ static void wt_porcelain_v2_print_unmerged_entry(
2135
2139
struct wt_status * s )
2136
2140
{
2137
2141
struct wt_status_change_data * d = it -> util ;
2142
+ struct index_state * istate = s -> repo -> index ;
2138
2143
const struct cache_entry * ce ;
2139
2144
struct strbuf buf_index = STRBUF_INIT ;
2140
2145
const char * path_index = NULL ;
@@ -2173,11 +2178,11 @@ static void wt_porcelain_v2_print_unmerged_entry(
2173
2178
*/
2174
2179
memset (stages , 0 , sizeof (stages ));
2175
2180
sum = 0 ;
2176
- pos = cache_name_pos ( it -> string , strlen (it -> string ));
2181
+ pos = index_name_pos ( istate , it -> string , strlen (it -> string ));
2177
2182
assert (pos < 0 );
2178
2183
pos = - pos - 1 ;
2179
- while (pos < active_nr ) {
2180
- ce = active_cache [pos ++ ];
2184
+ while (pos < istate -> cache_nr ) {
2185
+ ce = istate -> cache [pos ++ ];
2181
2186
stage = ce_stage (ce );
2182
2187
if (strcmp (ce -> name , it -> string ) || !stage )
2183
2188
break ;
@@ -2302,12 +2307,12 @@ void wt_status_print(struct wt_status *s)
2302
2307
/**
2303
2308
* Returns 1 if there are unstaged changes, 0 otherwise.
2304
2309
*/
2305
- int has_unstaged_changes (int ignore_submodules )
2310
+ int has_unstaged_changes (struct repository * r , int ignore_submodules )
2306
2311
{
2307
2312
struct rev_info rev_info ;
2308
2313
int result ;
2309
2314
2310
- repo_init_revisions (the_repository , & rev_info , NULL );
2315
+ repo_init_revisions (r , & rev_info , NULL );
2311
2316
if (ignore_submodules ) {
2312
2317
rev_info .diffopt .flags .ignore_submodules = 1 ;
2313
2318
rev_info .diffopt .flags .override_submodule_config = 1 ;
@@ -2321,15 +2326,16 @@ int has_unstaged_changes(int ignore_submodules)
2321
2326
/**
2322
2327
* Returns 1 if there are uncommitted changes, 0 otherwise.
2323
2328
*/
2324
- int has_uncommitted_changes (int ignore_submodules )
2329
+ int has_uncommitted_changes (struct repository * r ,
2330
+ int ignore_submodules )
2325
2331
{
2326
2332
struct rev_info rev_info ;
2327
2333
int result ;
2328
2334
2329
- if (is_cache_unborn ( ))
2335
+ if (is_index_unborn ( r -> index ))
2330
2336
return 0 ;
2331
2337
2332
- repo_init_revisions (the_repository , & rev_info , NULL );
2338
+ repo_init_revisions (r , & rev_info , NULL );
2333
2339
if (ignore_submodules )
2334
2340
rev_info .diffopt .flags .ignore_submodules = 1 ;
2335
2341
rev_info .diffopt .flags .quick = 1 ;
@@ -2340,7 +2346,7 @@ int has_uncommitted_changes(int ignore_submodules)
2340
2346
* We have no head (or it's corrupt); use the empty tree,
2341
2347
* which will complain if the index is non-empty.
2342
2348
*/
2343
- struct tree * tree = lookup_tree (the_repository , the_hash_algo -> empty_tree );
2349
+ struct tree * tree = lookup_tree (r , the_hash_algo -> empty_tree );
2344
2350
add_pending_object (& rev_info , & tree -> object , "" );
2345
2351
}
2346
2352
@@ -2353,24 +2359,28 @@ int has_uncommitted_changes(int ignore_submodules)
2353
2359
* If the work tree has unstaged or uncommitted changes, dies with the
2354
2360
* appropriate message.
2355
2361
*/
2356
- int require_clean_work_tree (const char * action , const char * hint , int ignore_submodules , int gently )
2362
+ int require_clean_work_tree (struct repository * r ,
2363
+ const char * action ,
2364
+ const char * hint ,
2365
+ int ignore_submodules ,
2366
+ int gently )
2357
2367
{
2358
2368
struct lock_file lock_file = LOCK_INIT ;
2359
2369
int err = 0 , fd ;
2360
2370
2361
2371
fd = hold_locked_index (& lock_file , 0 );
2362
- refresh_cache ( REFRESH_QUIET );
2372
+ refresh_index ( r -> index , REFRESH_QUIET , NULL , NULL , NULL );
2363
2373
if (0 <= fd )
2364
- update_index_if_able (& the_index , & lock_file );
2374
+ update_index_if_able (r -> index , & lock_file );
2365
2375
rollback_lock_file (& lock_file );
2366
2376
2367
- if (has_unstaged_changes (ignore_submodules )) {
2377
+ if (has_unstaged_changes (r , ignore_submodules )) {
2368
2378
/* TRANSLATORS: the action is e.g. "pull with rebase" */
2369
2379
error (_ ("cannot %s: You have unstaged changes." ), _ (action ));
2370
2380
err = 1 ;
2371
2381
}
2372
2382
2373
- if (has_uncommitted_changes (ignore_submodules )) {
2383
+ if (has_uncommitted_changes (r , ignore_submodules )) {
2374
2384
if (err )
2375
2385
error (_ ("additionally, your index contains uncommitted changes." ));
2376
2386
else
0 commit comments