@@ -581,7 +581,7 @@ static void run_pager(struct grep_opt *opt, const char *prefix)
581
581
free (argv );
582
582
}
583
583
584
- static int grep_cache (struct grep_opt * opt , const char * * paths , int cached )
584
+ static int grep_cache (struct grep_opt * opt , const struct pathspec * pathspec , int cached )
585
585
{
586
586
int hit = 0 ;
587
587
int nr ;
@@ -591,7 +591,7 @@ static int grep_cache(struct grep_opt *opt, const char **paths, int cached)
591
591
struct cache_entry * ce = active_cache [nr ];
592
592
if (!S_ISREG (ce -> ce_mode ))
593
593
continue ;
594
- if (!pathspec_matches (paths , ce -> name , opt -> max_depth ))
594
+ if (!pathspec_matches (pathspec -> raw , ce -> name , opt -> max_depth ))
595
595
continue ;
596
596
/*
597
597
* If CE_VALID is on, we assume worktree file and its cache entry
@@ -618,7 +618,7 @@ static int grep_cache(struct grep_opt *opt, const char **paths, int cached)
618
618
return hit ;
619
619
}
620
620
621
- static int grep_tree (struct grep_opt * opt , const char * * paths ,
621
+ static int grep_tree (struct grep_opt * opt , const struct pathspec * pathspec ,
622
622
struct tree_desc * tree ,
623
623
const char * tree_name , const char * base )
624
624
{
@@ -652,7 +652,7 @@ static int grep_tree(struct grep_opt *opt, const char **paths,
652
652
strbuf_addch (& pathbuf , '/' );
653
653
654
654
down = pathbuf .buf + tn_len ;
655
- if (!pathspec_matches (paths , down , opt -> max_depth ))
655
+ if (!pathspec_matches (pathspec -> raw , down , opt -> max_depth ))
656
656
;
657
657
else if (S_ISREG (entry .mode ))
658
658
hit |= grep_sha1 (opt , entry .sha1 , pathbuf .buf , tn_len );
@@ -667,7 +667,7 @@ static int grep_tree(struct grep_opt *opt, const char **paths,
667
667
die ("unable to read tree (%s)" ,
668
668
sha1_to_hex (entry .sha1 ));
669
669
init_tree_desc (& sub , data , size );
670
- hit |= grep_tree (opt , paths , & sub , tree_name , down );
670
+ hit |= grep_tree (opt , pathspec , & sub , tree_name , down );
671
671
free (data );
672
672
}
673
673
if (hit && opt -> status_only )
@@ -677,7 +677,7 @@ static int grep_tree(struct grep_opt *opt, const char **paths,
677
677
return hit ;
678
678
}
679
679
680
- static int grep_object (struct grep_opt * opt , const char * * paths ,
680
+ static int grep_object (struct grep_opt * opt , const struct pathspec * pathspec ,
681
681
struct object * obj , const char * name )
682
682
{
683
683
if (obj -> type == OBJ_BLOB )
@@ -692,14 +692,14 @@ static int grep_object(struct grep_opt *opt, const char **paths,
692
692
if (!data )
693
693
die ("unable to read tree (%s)" , sha1_to_hex (obj -> sha1 ));
694
694
init_tree_desc (& tree , data , size );
695
- hit = grep_tree (opt , paths , & tree , name , "" );
695
+ hit = grep_tree (opt , pathspec , & tree , name , "" );
696
696
free (data );
697
697
return hit ;
698
698
}
699
699
die ("unable to grep from object of type %s" , typename (obj -> type ));
700
700
}
701
701
702
- static int grep_objects (struct grep_opt * opt , const char * * paths ,
702
+ static int grep_objects (struct grep_opt * opt , const struct pathspec * pathspec ,
703
703
const struct object_array * list )
704
704
{
705
705
unsigned int i ;
@@ -709,7 +709,7 @@ static int grep_objects(struct grep_opt *opt, const char **paths,
709
709
for (i = 0 ; i < nr ; i ++ ) {
710
710
struct object * real_obj ;
711
711
real_obj = deref_tag (list -> objects [i ].item , NULL , 0 );
712
- if (grep_object (opt , paths , real_obj , list -> objects [i ].name )) {
712
+ if (grep_object (opt , pathspec , real_obj , list -> objects [i ].name )) {
713
713
hit = 1 ;
714
714
if (opt -> status_only )
715
715
break ;
@@ -718,15 +718,15 @@ static int grep_objects(struct grep_opt *opt, const char **paths,
718
718
return hit ;
719
719
}
720
720
721
- static int grep_directory (struct grep_opt * opt , const char * * paths )
721
+ static int grep_directory (struct grep_opt * opt , const struct pathspec * pathspec )
722
722
{
723
723
struct dir_struct dir ;
724
724
int i , hit = 0 ;
725
725
726
726
memset (& dir , 0 , sizeof (dir ));
727
727
setup_standard_excludes (& dir );
728
728
729
- fill_directory (& dir , paths );
729
+ fill_directory (& dir , pathspec -> raw );
730
730
for (i = 0 ; i < dir .nr ; i ++ ) {
731
731
hit |= grep_file (opt , dir .entries [i ]-> name );
732
732
if (hit && opt -> status_only )
@@ -832,6 +832,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
832
832
struct grep_opt opt ;
833
833
struct object_array list = OBJECT_ARRAY_INIT ;
834
834
const char * * paths = NULL ;
835
+ struct pathspec pathspec ;
835
836
struct string_list path_list = STRING_LIST_INIT_NODUP ;
836
837
int i ;
837
838
int dummy ;
@@ -1059,6 +1060,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
1059
1060
paths [0 ] = prefix ;
1060
1061
paths [1 ] = NULL ;
1061
1062
}
1063
+ init_pathspec (& pathspec , paths );
1062
1064
1063
1065
if (show_in_pager && (cached || list .nr ))
1064
1066
die ("--open-files-in-pager only works on the worktree" );
@@ -1089,16 +1091,16 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
1089
1091
die ("--cached cannot be used with --no-index." );
1090
1092
if (list .nr )
1091
1093
die ("--no-index cannot be used with revs." );
1092
- hit = grep_directory (& opt , paths );
1094
+ hit = grep_directory (& opt , & pathspec );
1093
1095
} else if (!list .nr ) {
1094
1096
if (!cached )
1095
1097
setup_work_tree ();
1096
1098
1097
- hit = grep_cache (& opt , paths , cached );
1099
+ hit = grep_cache (& opt , & pathspec , cached );
1098
1100
} else {
1099
1101
if (cached )
1100
1102
die ("both --cached and trees are given." );
1101
- hit = grep_objects (& opt , paths , & list );
1103
+ hit = grep_objects (& opt , & pathspec , & list );
1102
1104
}
1103
1105
1104
1106
if (use_threads )
0 commit comments