@@ -195,23 +195,21 @@ int add_files_to_cache(const char *prefix,
195195}
196196
197197#define WARN_IMPLICIT_DOT (1u << 0)
198- static char * prune_directory (struct dir_struct * dir , const char * * pathspec ,
198+ static char * prune_directory (struct dir_struct * dir , struct pathspec * pathspec ,
199199 int prefix , unsigned flag )
200200{
201201 char * seen ;
202- int i , specs ;
202+ int i ;
203203 struct dir_entry * * src , * * dst ;
204204
205- for (specs = 0 ; pathspec [specs ]; specs ++ )
206- /* nothing */ ;
207- seen = xcalloc (specs , 1 );
205+ seen = xcalloc (pathspec -> nr , 1 );
208206
209207 src = dst = dir -> entries ;
210208 i = dir -> nr ;
211209 while (-- i >= 0 ) {
212210 struct dir_entry * entry = * src ++ ;
213- if (match_pathspec (pathspec , entry -> name , entry -> len ,
214- prefix , seen ))
211+ if (match_pathspec_depth (pathspec , entry -> name , entry -> len ,
212+ prefix , seen ))
215213 * dst ++ = entry ;
216214 else if (flag & WARN_IMPLICIT_DOT )
217215 /*
@@ -225,7 +223,7 @@ static char *prune_directory(struct dir_struct *dir, const char **pathspec,
225223 warn_pathless_add ();
226224 }
227225 dir -> nr = dst - dir -> entries ;
228- add_pathspec_matches_against_index (pathspec , seen , specs );
226+ add_pathspec_matches_against_index (pathspec , seen );
229227 return seen ;
230228}
231229
@@ -523,7 +521,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
523521 /* This picks up the paths that are not tracked */
524522 baselen = fill_directory (& dir , implicit_dot ? & empty_pathspec : & pathspec );
525523 if (pathspec .nr )
526- seen = prune_directory (& dir , pathspec . raw , baselen ,
524+ seen = prune_directory (& dir , & pathspec , baselen ,
527525 implicit_dot ? WARN_IMPLICIT_DOT : 0 );
528526 }
529527
@@ -538,23 +536,23 @@ int cmd_add(int argc, const char **argv, const char *prefix)
538536 int i ;
539537
540538 if (!seen )
541- seen = find_pathspecs_matching_against_index (pathspec . raw );
539+ seen = find_pathspecs_matching_against_index (& pathspec );
542540
543541 /*
544542 * file_exists() assumes exact match
545543 */
546544 GUARD_PATHSPEC (& pathspec , PATHSPEC_FROMTOP );
547545
548- for (i = 0 ; pathspec .raw [ i ] ; i ++ ) {
549- if (! seen [ i ] && pathspec .raw [i ][ 0 ]
550- && !file_exists (pathspec . raw [ i ] )) {
546+ for (i = 0 ; i < pathspec .nr ; i ++ ) {
547+ const char * path = pathspec .items [i ]. match ;
548+ if (! seen [ i ] && !file_exists (path )) {
551549 if (ignore_missing ) {
552550 int dtype = DT_UNKNOWN ;
553- if (is_excluded (& dir , pathspec . raw [ i ] , & dtype ))
554- dir_add_ignored (& dir , pathspec . raw [ i ], strlen ( pathspec .raw [i ]) );
551+ if (is_excluded (& dir , path , & dtype ))
552+ dir_add_ignored (& dir , path , pathspec .items [i ]. len );
555553 } else
556554 die (_ ("pathspec '%s' did not match any files" ),
557- pathspec .raw [i ]);
555+ pathspec .items [i ]. original );
558556 }
559557 }
560558 free (seen );
0 commit comments