33 *
44 * Copyright (C) 2006 Linus Torvalds
55 */
6- #define USE_THE_INDEX_VARIABLE
6+
77#include "builtin.h"
88#include "advice.h"
99#include "config.h"
@@ -40,20 +40,20 @@ static int chmod_pathspec(struct pathspec *pathspec, char flip, int show_only)
4040{
4141 int i , ret = 0 ;
4242
43- for (i = 0 ; i < the_index . cache_nr ; i ++ ) {
44- struct cache_entry * ce = the_index . cache [i ];
43+ for (i = 0 ; i < the_repository -> index -> cache_nr ; i ++ ) {
44+ struct cache_entry * ce = the_repository -> index -> cache [i ];
4545 int err ;
4646
4747 if (!include_sparse &&
4848 (ce_skip_worktree (ce ) ||
49- !path_in_sparse_checkout (ce -> name , & the_index )))
49+ !path_in_sparse_checkout (ce -> name , the_repository -> index )))
5050 continue ;
5151
52- if (pathspec && !ce_path_match (& the_index , ce , pathspec , NULL ))
52+ if (pathspec && !ce_path_match (the_repository -> index , ce , pathspec , NULL ))
5353 continue ;
5454
5555 if (!show_only )
56- err = chmod_index_entry (& the_index , ce , flip );
56+ err = chmod_index_entry (the_repository -> index , ce , flip );
5757 else
5858 err = S_ISREG (ce -> ce_mode ) ? 0 : -1 ;
5959
@@ -68,20 +68,20 @@ static int renormalize_tracked_files(const struct pathspec *pathspec, int flags)
6868{
6969 int i , retval = 0 ;
7070
71- for (i = 0 ; i < the_index . cache_nr ; i ++ ) {
72- struct cache_entry * ce = the_index . cache [i ];
71+ for (i = 0 ; i < the_repository -> index -> cache_nr ; i ++ ) {
72+ struct cache_entry * ce = the_repository -> index -> cache [i ];
7373
7474 if (!include_sparse &&
7575 (ce_skip_worktree (ce ) ||
76- !path_in_sparse_checkout (ce -> name , & the_index )))
76+ !path_in_sparse_checkout (ce -> name , the_repository -> index )))
7777 continue ;
7878 if (ce_stage (ce ))
7979 continue ; /* do not touch unmerged paths */
8080 if (!S_ISREG (ce -> ce_mode ) && !S_ISLNK (ce -> ce_mode ))
8181 continue ; /* do not touch non blobs */
82- if (pathspec && !ce_path_match (& the_index , ce , pathspec , NULL ))
82+ if (pathspec && !ce_path_match (the_repository -> index , ce , pathspec , NULL ))
8383 continue ;
84- retval |= add_file_to_index (& the_index , ce -> name ,
84+ retval |= add_file_to_index (the_repository -> index , ce -> name ,
8585 flags | ADD_CACHE_RENORMALIZE );
8686 }
8787
@@ -100,11 +100,11 @@ static char *prune_directory(struct dir_struct *dir, struct pathspec *pathspec,
100100 i = dir -> nr ;
101101 while (-- i >= 0 ) {
102102 struct dir_entry * entry = * src ++ ;
103- if (dir_path_match (& the_index , entry , pathspec , prefix , seen ))
103+ if (dir_path_match (the_repository -> index , entry , pathspec , prefix , seen ))
104104 * dst ++ = entry ;
105105 }
106106 dir -> nr = dst - dir -> entries ;
107- add_pathspec_matches_against_index (pathspec , & the_index , seen ,
107+ add_pathspec_matches_against_index (pathspec , the_repository -> index , seen ,
108108 PS_IGNORE_SKIP_WORKTREE );
109109 return seen ;
110110}
@@ -119,14 +119,14 @@ static int refresh(int verbose, const struct pathspec *pathspec)
119119 (verbose ? REFRESH_IN_PORCELAIN : REFRESH_QUIET );
120120
121121 seen = xcalloc (pathspec -> nr , 1 );
122- refresh_index (& the_index , flags , pathspec , seen ,
122+ refresh_index (the_repository -> index , flags , pathspec , seen ,
123123 _ ("Unstaged changes after refreshing the index:" ));
124124 for (i = 0 ; i < pathspec -> nr ; i ++ ) {
125125 if (!seen [i ]) {
126126 const char * path = pathspec -> items [i ].original ;
127127
128128 if (matches_skip_worktree (pathspec , i , & skip_worktree_seen ) ||
129- !path_in_sparse_checkout (path , & the_index )) {
129+ !path_in_sparse_checkout (path , the_repository -> index )) {
130130 string_list_append (& only_match_skip_worktree ,
131131 pathspec -> items [i ].original );
132132 } else {
@@ -335,12 +335,12 @@ static int add_files(struct dir_struct *dir, int flags)
335335
336336 for (i = 0 ; i < dir -> nr ; i ++ ) {
337337 if (!include_sparse &&
338- !path_in_sparse_checkout (dir -> entries [i ]-> name , & the_index )) {
338+ !path_in_sparse_checkout (dir -> entries [i ]-> name , the_repository -> index )) {
339339 string_list_append (& matched_sparse_paths ,
340340 dir -> entries [i ]-> name );
341341 continue ;
342342 }
343- if (add_file_to_index (& the_index , dir -> entries [i ]-> name , flags )) {
343+ if (add_file_to_index (the_repository -> index , dir -> entries [i ]-> name , flags )) {
344344 if (!ignore_add_errors )
345345 die (_ ("adding files failed" ));
346346 exit_status = 1 ;
@@ -458,8 +458,8 @@ int cmd_add(int argc, const char **argv, const char *prefix)
458458 if (repo_read_index_preload (the_repository , & pathspec , 0 ) < 0 )
459459 die (_ ("index file corrupt" ));
460460
461- die_in_unpopulated_submodule (& the_index , prefix );
462- die_path_inside_submodule (& the_index , & pathspec );
461+ die_in_unpopulated_submodule (the_repository -> index , prefix );
462+ die_path_inside_submodule (the_repository -> index , & pathspec );
463463
464464 if (add_new_files ) {
465465 int baselen ;
@@ -471,7 +471,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
471471 }
472472
473473 /* This picks up the paths that are not tracked */
474- baselen = fill_directory (& dir , & the_index , & pathspec );
474+ baselen = fill_directory (& dir , the_repository -> index , & pathspec );
475475 if (pathspec .nr )
476476 seen = prune_directory (& dir , & pathspec , baselen );
477477 }
@@ -488,7 +488,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
488488
489489 if (!seen )
490490 seen = find_pathspecs_matching_against_index (& pathspec ,
491- & the_index , PS_IGNORE_SKIP_WORKTREE );
491+ the_repository -> index , PS_IGNORE_SKIP_WORKTREE );
492492
493493 /*
494494 * file_exists() assumes exact match
@@ -524,8 +524,8 @@ int cmd_add(int argc, const char **argv, const char *prefix)
524524 !file_exists (path )) {
525525 if (ignore_missing ) {
526526 int dtype = DT_UNKNOWN ;
527- if (is_excluded (& dir , & the_index , path , & dtype ))
528- dir_add_ignored (& dir , & the_index ,
527+ if (is_excluded (& dir , the_repository -> index , path , & dtype ))
528+ dir_add_ignored (& dir , the_repository -> index ,
529529 path , pathspec .items [i ].len );
530530 } else
531531 die (_ ("pathspec '%s' did not match any files" ),
@@ -566,7 +566,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
566566 end_odb_transaction ();
567567
568568finish :
569- if (write_locked_index (& the_index , & lock_file ,
569+ if (write_locked_index (the_repository -> index , & lock_file ,
570570 COMMIT_LOCK | SKIP_IF_UNCHANGED ))
571571 die (_ ("unable to write new index file" ));
572572
0 commit comments