@@ -31,7 +31,7 @@ static int debug_mode;
3131static const char * prefix ;
3232static int max_prefix_len ;
3333static int prefix_len ;
34- static const char * * pathspec ;
34+ static struct pathspec pathspec ;
3535static int error_unmatch ;
3636static char * ps_matched ;
3737static const char * with_tree ;
@@ -60,7 +60,7 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent)
6060 if (len >= ent -> len )
6161 die ("git ls-files: internal error - directory entry not superset of prefix" );
6262
63- if (!match_pathspec ( pathspec , ent -> name , ent -> len , len , ps_matched ))
63+ if (!match_pathspec_depth ( & pathspec , ent -> name , ent -> len , len , ps_matched ))
6464 return ;
6565
6666 fputs (tag , stdout );
@@ -135,7 +135,7 @@ static void show_ce_entry(const char *tag, struct cache_entry *ce)
135135 if (len >= ce_namelen (ce ))
136136 die ("git ls-files: internal error - cache entry not superset of prefix" );
137137
138- if (!match_pathspec ( pathspec , ce -> name , ce_namelen (ce ), len , ps_matched ))
138+ if (!match_pathspec_depth ( & pathspec , ce -> name , ce_namelen (ce ), len , ps_matched ))
139139 return ;
140140
141141 if (tag && * tag && show_valid_bit &&
@@ -191,7 +191,7 @@ static void show_ru_info(void)
191191 len = strlen (path );
192192 if (len < max_prefix_len )
193193 continue ; /* outside of the prefix */
194- if (!match_pathspec ( pathspec , path , len , max_prefix_len , ps_matched ))
194+ if (!match_pathspec_depth ( & pathspec , path , len , max_prefix_len , ps_matched ))
195195 continue ; /* uninterested */
196196 for (i = 0 ; i < 3 ; i ++ ) {
197197 if (!ui -> mode [i ])
@@ -216,7 +216,7 @@ static void show_files(struct dir_struct *dir)
216216
217217 /* For cached/deleted files we don't need to even do the readdir */
218218 if (show_others || show_killed ) {
219- fill_directory (dir , pathspec );
219+ fill_directory (dir , pathspec . raw );
220220 if (show_others )
221221 show_other_files (dir );
222222 if (show_killed )
@@ -284,21 +284,6 @@ static void prune_cache(const char *prefix)
284284 active_nr = last ;
285285}
286286
287- static void strip_trailing_slash_from_submodules (void )
288- {
289- const char * * p ;
290-
291- for (p = pathspec ; * p != NULL ; p ++ ) {
292- int len = strlen (* p ), pos ;
293-
294- if (len < 1 || (* p )[len - 1 ] != '/' )
295- continue ;
296- pos = cache_name_pos (* p , len - 1 );
297- if (pos >= 0 && S_ISGITLINK (active_cache [pos ]-> ce_mode ))
298- * p = xstrndup (* p , len - 1 );
299- }
300- }
301-
302287/*
303288 * Read the tree specified with --with-tree option
304289 * (typically, HEAD) into stage #1 and then
@@ -552,23 +537,18 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
552537 if (require_work_tree && !is_inside_work_tree ())
553538 setup_work_tree ();
554539
555- pathspec = get_pathspec (prefix , argv );
556-
557- /* be nice with submodule paths ending in a slash */
558- if (pathspec )
559- strip_trailing_slash_from_submodules ();
540+ parse_pathspec (& pathspec , 0 ,
541+ PATHSPEC_PREFER_CWD |
542+ PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP ,
543+ prefix , argv );
560544
561545 /* Find common prefix for all pathspec's */
562- max_prefix = common_prefix (pathspec );
546+ max_prefix = common_prefix (pathspec . raw );
563547 max_prefix_len = max_prefix ? strlen (max_prefix ) : 0 ;
564548
565549 /* Treat unmatching pathspec elements as errors */
566- if (pathspec && error_unmatch ) {
567- int num ;
568- for (num = 0 ; pathspec [num ]; num ++ )
569- ;
570- ps_matched = xcalloc (1 , num );
571- }
550+ if (pathspec .nr && error_unmatch )
551+ ps_matched = xcalloc (1 , pathspec .nr );
572552
573553 if ((dir .flags & DIR_SHOW_IGNORED ) && !exc_given )
574554 die ("ls-files --ignored needs some exclude pattern" );
@@ -595,7 +575,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
595575
596576 if (ps_matched ) {
597577 int bad ;
598- bad = report_path_error (ps_matched , pathspec , prefix );
578+ bad = report_path_error (ps_matched , pathspec . raw , prefix );
599579 if (bad )
600580 fprintf (stderr , "Did you forget to 'git add'?\n" );
601581
0 commit comments