@@ -86,15 +86,15 @@ static pthread_cond_t cond_result;
8686static int skip_first_line ;
8787
8888static void add_work (struct grep_opt * opt , enum grep_source_type type ,
89- const char * name , const void * id )
89+ const char * name , const char * path , const void * id )
9090{
9191 grep_lock ();
9292
9393 while ((todo_end + 1 ) % ARRAY_SIZE (todo ) == todo_done ) {
9494 pthread_cond_wait (& cond_write , & grep_mutex );
9595 }
9696
97- grep_source_init (& todo [todo_end ].source , type , name , id );
97+ grep_source_init (& todo [todo_end ].source , type , name , path , id );
9898 if (opt -> binary != GREP_BINARY_TEXT )
9999 grep_source_load_driver (& todo [todo_end ].source );
100100 todo [todo_end ].done = 0 ;
@@ -319,7 +319,8 @@ static void *lock_and_read_sha1_file(const unsigned char *sha1, enum object_type
319319}
320320
321321static int grep_sha1 (struct grep_opt * opt , const unsigned char * sha1 ,
322- const char * filename , int tree_name_len )
322+ const char * filename , int tree_name_len ,
323+ const char * path )
323324{
324325 struct strbuf pathbuf = STRBUF_INIT ;
325326
@@ -333,7 +334,7 @@ static int grep_sha1(struct grep_opt *opt, const unsigned char *sha1,
333334
334335#ifndef NO_PTHREADS
335336 if (use_threads ) {
336- add_work (opt , GREP_SOURCE_SHA1 , pathbuf .buf , sha1 );
337+ add_work (opt , GREP_SOURCE_SHA1 , pathbuf .buf , path , sha1 );
337338 strbuf_release (& pathbuf );
338339 return 0 ;
339340 } else
@@ -342,7 +343,7 @@ static int grep_sha1(struct grep_opt *opt, const unsigned char *sha1,
342343 struct grep_source gs ;
343344 int hit ;
344345
345- grep_source_init (& gs , GREP_SOURCE_SHA1 , pathbuf .buf , sha1 );
346+ grep_source_init (& gs , GREP_SOURCE_SHA1 , pathbuf .buf , path , sha1 );
346347 strbuf_release (& pathbuf );
347348 hit = grep_source (opt , & gs );
348349
@@ -362,7 +363,7 @@ static int grep_file(struct grep_opt *opt, const char *filename)
362363
363364#ifndef NO_PTHREADS
364365 if (use_threads ) {
365- add_work (opt , GREP_SOURCE_FILE , buf .buf , filename );
366+ add_work (opt , GREP_SOURCE_FILE , buf .buf , filename , filename );
366367 strbuf_release (& buf );
367368 return 0 ;
368369 } else
@@ -371,7 +372,7 @@ static int grep_file(struct grep_opt *opt, const char *filename)
371372 struct grep_source gs ;
372373 int hit ;
373374
374- grep_source_init (& gs , GREP_SOURCE_FILE , buf .buf , filename );
375+ grep_source_init (& gs , GREP_SOURCE_FILE , buf .buf , filename , filename );
375376 strbuf_release (& buf );
376377 hit = grep_source (opt , & gs );
377378
@@ -427,7 +428,7 @@ static int grep_cache(struct grep_opt *opt, const struct pathspec *pathspec, int
427428 if (cached || (ce -> ce_flags & CE_VALID ) || ce_skip_worktree (ce )) {
428429 if (ce_stage (ce ))
429430 continue ;
430- hit |= grep_sha1 (opt , ce -> sha1 , ce -> name , 0 );
431+ hit |= grep_sha1 (opt , ce -> sha1 , ce -> name , 0 , ce -> name );
431432 }
432433 else
433434 hit |= grep_file (opt , ce -> name );
@@ -445,7 +446,8 @@ static int grep_cache(struct grep_opt *opt, const struct pathspec *pathspec, int
445446}
446447
447448static int grep_tree (struct grep_opt * opt , const struct pathspec * pathspec ,
448- struct tree_desc * tree , struct strbuf * base , int tn_len )
449+ struct tree_desc * tree , struct strbuf * base , int tn_len ,
450+ int check_attr )
449451{
450452 int hit = 0 ;
451453 enum interesting match = entry_not_interesting ;
@@ -466,7 +468,8 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
466468 strbuf_add (base , entry .path , te_len );
467469
468470 if (S_ISREG (entry .mode )) {
469- hit |= grep_sha1 (opt , entry .sha1 , base -> buf , tn_len );
471+ hit |= grep_sha1 (opt , entry .sha1 , base -> buf , tn_len ,
472+ check_attr ? base -> buf + tn_len : NULL );
470473 }
471474 else if (S_ISDIR (entry .mode )) {
472475 enum object_type type ;
@@ -481,7 +484,8 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
481484
482485 strbuf_addch (base , '/' );
483486 init_tree_desc (& sub , data , size );
484- hit |= grep_tree (opt , pathspec , & sub , base , tn_len );
487+ hit |= grep_tree (opt , pathspec , & sub , base , tn_len ,
488+ check_attr );
485489 free (data );
486490 }
487491 strbuf_setlen (base , old_baselen );
@@ -496,7 +500,7 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,
496500 struct object * obj , const char * name )
497501{
498502 if (obj -> type == OBJ_BLOB )
499- return grep_sha1 (opt , obj -> sha1 , name , 0 );
503+ return grep_sha1 (opt , obj -> sha1 , name , 0 , NULL );
500504 if (obj -> type == OBJ_COMMIT || obj -> type == OBJ_TREE ) {
501505 struct tree_desc tree ;
502506 void * data ;
@@ -519,7 +523,8 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,
519523 strbuf_addch (& base , ':' );
520524 }
521525 init_tree_desc (& tree , data , size );
522- hit = grep_tree (opt , pathspec , & tree , & base , base .len );
526+ hit = grep_tree (opt , pathspec , & tree , & base , base .len ,
527+ obj -> type == OBJ_COMMIT );
523528 strbuf_release (& base );
524529 free (data );
525530 return hit ;
0 commit comments