@@ -86,15 +86,15 @@ static pthread_cond_t cond_result;
86
86
static int skip_first_line ;
87
87
88
88
static 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 )
90
90
{
91
91
grep_lock ();
92
92
93
93
while ((todo_end + 1 ) % ARRAY_SIZE (todo ) == todo_done ) {
94
94
pthread_cond_wait (& cond_write , & grep_mutex );
95
95
}
96
96
97
- grep_source_init (& todo [todo_end ].source , type , name , id );
97
+ grep_source_init (& todo [todo_end ].source , type , name , path , id );
98
98
if (opt -> binary != GREP_BINARY_TEXT )
99
99
grep_source_load_driver (& todo [todo_end ].source );
100
100
todo [todo_end ].done = 0 ;
@@ -319,7 +319,8 @@ static void *lock_and_read_sha1_file(const unsigned char *sha1, enum object_type
319
319
}
320
320
321
321
static 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 )
323
324
{
324
325
struct strbuf pathbuf = STRBUF_INIT ;
325
326
@@ -333,7 +334,7 @@ static int grep_sha1(struct grep_opt *opt, const unsigned char *sha1,
333
334
334
335
#ifndef NO_PTHREADS
335
336
if (use_threads ) {
336
- add_work (opt , GREP_SOURCE_SHA1 , pathbuf .buf , sha1 );
337
+ add_work (opt , GREP_SOURCE_SHA1 , pathbuf .buf , path , sha1 );
337
338
strbuf_release (& pathbuf );
338
339
return 0 ;
339
340
} else
@@ -342,7 +343,7 @@ static int grep_sha1(struct grep_opt *opt, const unsigned char *sha1,
342
343
struct grep_source gs ;
343
344
int hit ;
344
345
345
- grep_source_init (& gs , GREP_SOURCE_SHA1 , pathbuf .buf , sha1 );
346
+ grep_source_init (& gs , GREP_SOURCE_SHA1 , pathbuf .buf , path , sha1 );
346
347
strbuf_release (& pathbuf );
347
348
hit = grep_source (opt , & gs );
348
349
@@ -362,7 +363,7 @@ static int grep_file(struct grep_opt *opt, const char *filename)
362
363
363
364
#ifndef NO_PTHREADS
364
365
if (use_threads ) {
365
- add_work (opt , GREP_SOURCE_FILE , buf .buf , filename );
366
+ add_work (opt , GREP_SOURCE_FILE , buf .buf , filename , filename );
366
367
strbuf_release (& buf );
367
368
return 0 ;
368
369
} else
@@ -371,7 +372,7 @@ static int grep_file(struct grep_opt *opt, const char *filename)
371
372
struct grep_source gs ;
372
373
int hit ;
373
374
374
- grep_source_init (& gs , GREP_SOURCE_FILE , buf .buf , filename );
375
+ grep_source_init (& gs , GREP_SOURCE_FILE , buf .buf , filename , filename );
375
376
strbuf_release (& buf );
376
377
hit = grep_source (opt , & gs );
377
378
@@ -427,7 +428,7 @@ static int grep_cache(struct grep_opt *opt, const struct pathspec *pathspec, int
427
428
if (cached || (ce -> ce_flags & CE_VALID ) || ce_skip_worktree (ce )) {
428
429
if (ce_stage (ce ))
429
430
continue ;
430
- hit |= grep_sha1 (opt , ce -> sha1 , ce -> name , 0 );
431
+ hit |= grep_sha1 (opt , ce -> sha1 , ce -> name , 0 , ce -> name );
431
432
}
432
433
else
433
434
hit |= grep_file (opt , ce -> name );
@@ -445,7 +446,8 @@ static int grep_cache(struct grep_opt *opt, const struct pathspec *pathspec, int
445
446
}
446
447
447
448
static 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 )
449
451
{
450
452
int hit = 0 ;
451
453
enum interesting match = entry_not_interesting ;
@@ -466,7 +468,8 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
466
468
strbuf_add (base , entry .path , te_len );
467
469
468
470
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 );
470
473
}
471
474
else if (S_ISDIR (entry .mode )) {
472
475
enum object_type type ;
@@ -481,7 +484,8 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
481
484
482
485
strbuf_addch (base , '/' );
483
486
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 );
485
489
free (data );
486
490
}
487
491
strbuf_setlen (base , old_baselen );
@@ -496,7 +500,7 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,
496
500
struct object * obj , const char * name )
497
501
{
498
502
if (obj -> type == OBJ_BLOB )
499
- return grep_sha1 (opt , obj -> sha1 , name , 0 );
503
+ return grep_sha1 (opt , obj -> sha1 , name , 0 , NULL );
500
504
if (obj -> type == OBJ_COMMIT || obj -> type == OBJ_TREE ) {
501
505
struct tree_desc tree ;
502
506
void * data ;
@@ -519,7 +523,8 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,
519
523
strbuf_addch (& base , ':' );
520
524
}
521
525
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 );
523
528
strbuf_release (& base );
524
529
free (data );
525
530
return hit ;
0 commit comments