@@ -119,9 +119,10 @@ static void status_printf_more(struct wt_status *s, const char *color,
119119 va_end (ap );
120120}
121121
122- void wt_status_prepare (struct wt_status * s )
122+ void wt_status_prepare (struct repository * r , struct wt_status * s )
123123{
124124 memset (s , 0 , sizeof (* s ));
125+ s -> repo = r ;
125126 memcpy (s -> color_palette , default_wt_status_colors ,
126127 sizeof (default_wt_status_colors ));
127128 s -> show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES ;
@@ -494,19 +495,19 @@ static void wt_status_collect_changed_cb(struct diff_queue_struct *q,
494495 }
495496}
496497
497- static int unmerged_mask (const char * path )
498+ static int unmerged_mask (struct index_state * istate , const char * path )
498499{
499500 int pos , mask ;
500501 const struct cache_entry * ce ;
501502
502- pos = cache_name_pos ( path , strlen (path ));
503+ pos = index_name_pos ( istate , path , strlen (path ));
503504 if (0 <= pos )
504505 return 0 ;
505506
506507 mask = 0 ;
507508 pos = - pos - 1 ;
508- while (pos < active_nr ) {
509- ce = active_cache [pos ++ ];
509+ while (pos < istate -> cache_nr ) {
510+ ce = istate -> cache [pos ++ ];
510511 if (strcmp (ce -> name , path ) || !ce_stage (ce ))
511512 break ;
512513 mask |= (1 << (ce_stage (ce ) - 1 ));
@@ -566,7 +567,8 @@ static void wt_status_collect_updated_cb(struct diff_queue_struct *q,
566567 s -> committable = 1 ;
567568 break ;
568569 case DIFF_STATUS_UNMERGED :
569- d -> stagemask = unmerged_mask (p -> two -> path );
570+ d -> stagemask = unmerged_mask (s -> repo -> index ,
571+ p -> two -> path );
570572 /*
571573 * Don't bother setting {mode,oid}_{head,index} since the print
572574 * 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)
585587{
586588 struct rev_info rev ;
587589
588- repo_init_revisions (the_repository , & rev , NULL );
590+ repo_init_revisions (s -> repo , & rev , NULL );
589591 setup_revisions (0 , NULL , & rev , NULL );
590592 rev .diffopt .output_format |= DIFF_FORMAT_CALLBACK ;
591593 rev .diffopt .flags .dirty_submodules = 1 ;
@@ -610,7 +612,7 @@ static void wt_status_collect_changes_index(struct wt_status *s)
610612 struct rev_info rev ;
611613 struct setup_revision_opt opt ;
612614
613- repo_init_revisions (the_repository , & rev , NULL );
615+ repo_init_revisions (s -> repo , & rev , NULL );
614616 memset (& opt , 0 , sizeof (opt ));
615617 opt .def = s -> is_initial ? empty_tree_oid_hex () : s -> reference ;
616618 setup_revisions (0 , NULL , & rev , & opt );
@@ -643,14 +645,15 @@ static void wt_status_collect_changes_index(struct wt_status *s)
643645
644646static void wt_status_collect_changes_initial (struct wt_status * s )
645647{
648+ struct index_state * istate = s -> repo -> index ;
646649 int i ;
647650
648- for (i = 0 ; i < active_nr ; i ++ ) {
651+ for (i = 0 ; i < istate -> cache_nr ; i ++ ) {
649652 struct string_list_item * it ;
650653 struct wt_status_change_data * d ;
651- const struct cache_entry * ce = active_cache [i ];
654+ const struct cache_entry * ce = istate -> cache [i ];
652655
653- if (!ce_path_match (& the_index , ce , & s -> pathspec , NULL ))
656+ if (!ce_path_match (istate , ce , & s -> pathspec , NULL ))
654657 continue ;
655658 if (ce_intent_to_add (ce ))
656659 continue ;
@@ -684,6 +687,7 @@ static void wt_status_collect_untracked(struct wt_status *s)
684687 int i ;
685688 struct dir_struct dir ;
686689 uint64_t t_begin = getnanotime ();
690+ struct index_state * istate = s -> repo -> index ;
687691
688692 if (!s -> show_untracked_files )
689693 return ;
@@ -698,25 +702,25 @@ static void wt_status_collect_untracked(struct wt_status *s)
698702 if (s -> show_ignored_mode == SHOW_MATCHING_IGNORED )
699703 dir .flags |= DIR_SHOW_IGNORED_TOO_MODE_MATCHING ;
700704 } else {
701- dir .untracked = the_index . untracked ;
705+ dir .untracked = istate -> untracked ;
702706 }
703707
704708 setup_standard_excludes (& dir );
705709
706- fill_directory (& dir , & the_index , & s -> pathspec );
710+ fill_directory (& dir , istate , & s -> pathspec );
707711
708712 for (i = 0 ; i < dir .nr ; i ++ ) {
709713 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 ))
712716 string_list_insert (& s -> untracked , ent -> name );
713717 free (ent );
714718 }
715719
716720 for (i = 0 ; i < dir .ignored_nr ; i ++ ) {
717721 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 ))
720724 string_list_insert (& s -> ignored , ent -> name );
721725 free (ent );
722726 }
@@ -1009,7 +1013,7 @@ static void wt_longstatus_print_verbose(struct wt_status *s)
10091013 int dirty_submodules ;
10101014 const char * c = color (WT_STATUS_HEADER , s );
10111015
1012- repo_init_revisions (the_repository , & rev , NULL );
1016+ repo_init_revisions (s -> repo , & rev , NULL );
10131017 rev .diffopt .flags .allow_textconv = 1 ;
10141018 rev .diffopt .ita_invisible_in_index = 1 ;
10151019
@@ -1326,7 +1330,7 @@ static void show_rebase_in_progress(struct wt_status *s,
13261330 _ (" (use \"git rebase --abort\" to check out the original branch)" ));
13271331 }
13281332 } 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 )) {
13301334 print_rebase_state (s , color );
13311335 if (s -> hints )
13321336 status_printf_ln (s , color ,
@@ -2135,6 +2139,7 @@ static void wt_porcelain_v2_print_unmerged_entry(
21352139 struct wt_status * s )
21362140{
21372141 struct wt_status_change_data * d = it -> util ;
2142+ struct index_state * istate = s -> repo -> index ;
21382143 const struct cache_entry * ce ;
21392144 struct strbuf buf_index = STRBUF_INIT ;
21402145 const char * path_index = NULL ;
@@ -2173,11 +2178,11 @@ static void wt_porcelain_v2_print_unmerged_entry(
21732178 */
21742179 memset (stages , 0 , sizeof (stages ));
21752180 sum = 0 ;
2176- pos = cache_name_pos ( it -> string , strlen (it -> string ));
2181+ pos = index_name_pos ( istate , it -> string , strlen (it -> string ));
21772182 assert (pos < 0 );
21782183 pos = - pos - 1 ;
2179- while (pos < active_nr ) {
2180- ce = active_cache [pos ++ ];
2184+ while (pos < istate -> cache_nr ) {
2185+ ce = istate -> cache [pos ++ ];
21812186 stage = ce_stage (ce );
21822187 if (strcmp (ce -> name , it -> string ) || !stage )
21832188 break ;
@@ -2302,12 +2307,12 @@ void wt_status_print(struct wt_status *s)
23022307/**
23032308 * Returns 1 if there are unstaged changes, 0 otherwise.
23042309 */
2305- int has_unstaged_changes (int ignore_submodules )
2310+ int has_unstaged_changes (struct repository * r , int ignore_submodules )
23062311{
23072312 struct rev_info rev_info ;
23082313 int result ;
23092314
2310- repo_init_revisions (the_repository , & rev_info , NULL );
2315+ repo_init_revisions (r , & rev_info , NULL );
23112316 if (ignore_submodules ) {
23122317 rev_info .diffopt .flags .ignore_submodules = 1 ;
23132318 rev_info .diffopt .flags .override_submodule_config = 1 ;
@@ -2321,15 +2326,16 @@ int has_unstaged_changes(int ignore_submodules)
23212326/**
23222327 * Returns 1 if there are uncommitted changes, 0 otherwise.
23232328 */
2324- int has_uncommitted_changes (int ignore_submodules )
2329+ int has_uncommitted_changes (struct repository * r ,
2330+ int ignore_submodules )
23252331{
23262332 struct rev_info rev_info ;
23272333 int result ;
23282334
2329- if (is_cache_unborn ( ))
2335+ if (is_index_unborn ( r -> index ))
23302336 return 0 ;
23312337
2332- repo_init_revisions (the_repository , & rev_info , NULL );
2338+ repo_init_revisions (r , & rev_info , NULL );
23332339 if (ignore_submodules )
23342340 rev_info .diffopt .flags .ignore_submodules = 1 ;
23352341 rev_info .diffopt .flags .quick = 1 ;
@@ -2340,7 +2346,7 @@ int has_uncommitted_changes(int ignore_submodules)
23402346 * We have no head (or it's corrupt); use the empty tree,
23412347 * which will complain if the index is non-empty.
23422348 */
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 );
23442350 add_pending_object (& rev_info , & tree -> object , "" );
23452351 }
23462352
@@ -2353,24 +2359,28 @@ int has_uncommitted_changes(int ignore_submodules)
23532359 * If the work tree has unstaged or uncommitted changes, dies with the
23542360 * appropriate message.
23552361 */
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 )
23572367{
23582368 struct lock_file lock_file = LOCK_INIT ;
23592369 int err = 0 , fd ;
23602370
23612371 fd = hold_locked_index (& lock_file , 0 );
2362- refresh_cache ( REFRESH_QUIET );
2372+ refresh_index ( r -> index , REFRESH_QUIET , NULL , NULL , NULL );
23632373 if (0 <= fd )
2364- update_index_if_able (& the_index , & lock_file );
2374+ update_index_if_able (r -> index , & lock_file );
23652375 rollback_lock_file (& lock_file );
23662376
2367- if (has_unstaged_changes (ignore_submodules )) {
2377+ if (has_unstaged_changes (r , ignore_submodules )) {
23682378 /* TRANSLATORS: the action is e.g. "pull with rebase" */
23692379 error (_ ("cannot %s: You have unstaged changes." ), _ (action ));
23702380 err = 1 ;
23712381 }
23722382
2373- if (has_uncommitted_changes (ignore_submodules )) {
2383+ if (has_uncommitted_changes (r , ignore_submodules )) {
23742384 if (err )
23752385 error (_ ("additionally, your index contains uncommitted changes." ));
23762386 else
0 commit comments