@@ -87,12 +87,37 @@ static int show_modified(struct cache_entry *old,
8787 return 0 ;
8888}
8989
90- static int diff_cache (struct cache_entry * * ac , int entries )
90+ static int ce_path_match (const struct cache_entry * ce , const char * * pathspec )
91+ {
92+ const char * match , * name ;
93+ int len ;
94+
95+ if (!pathspec )
96+ return 1 ;
97+
98+ len = ce_namelen (ce );
99+ name = ce -> name ;
100+ while ((match = * pathspec ++ ) != NULL ) {
101+ int matchlen = strlen (match );
102+ if (matchlen > len )
103+ continue ;
104+ if (memcmp (name , match , matchlen ))
105+ continue ;
106+ if (name [matchlen ] == '/' || !name [matchlen ])
107+ return 1 ;
108+ }
109+ return 0 ;
110+ }
111+
112+ static int diff_cache (struct cache_entry * * ac , int entries , const char * * pathspec )
91113{
92114 while (entries ) {
93115 struct cache_entry * ce = * ac ;
94116 int same = (entries > 1 ) && ce_same_name (ce , ac [1 ]);
95117
118+ if (!ce_path_match (ce , pathspec ))
119+ goto skip_entry ;
120+
96121 switch (ce_stage (ce )) {
97122 case 0 :
98123 /* No stage 1 entry? That means it's a new file */
@@ -130,6 +155,7 @@ static int diff_cache(struct cache_entry **ac, int entries)
130155 die ("impossible cache entry stage" );
131156 }
132157
158+ skip_entry :
133159 /*
134160 * Ignore all the different stages for this file,
135161 * we've handled the relevant cases now.
@@ -281,7 +307,7 @@ int main(int argc, const char **argv)
281307 if (read_tree (tree , size , 1 , pathspec ))
282308 die ("unable to read tree object %s" , tree_name );
283309
284- ret = diff_cache (active_cache , active_nr );
310+ ret = diff_cache (active_cache , active_nr , pathspec );
285311
286312 diffcore_std (pathspec ,
287313 detect_rename , diff_score_opt ,
0 commit comments