@@ -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 ;
@@ -280,7 +280,8 @@ static void *lock_and_read_sha1_file(const unsigned char *sha1, enum object_type
280
280
}
281
281
282
282
static int grep_sha1 (struct grep_opt * opt , const unsigned char * sha1 ,
283
- const char * filename , int tree_name_len )
283
+ const char * filename , int tree_name_len ,
284
+ const char * path )
284
285
{
285
286
struct strbuf pathbuf = STRBUF_INIT ;
286
287
@@ -294,7 +295,7 @@ static int grep_sha1(struct grep_opt *opt, const unsigned char *sha1,
294
295
295
296
#ifndef NO_PTHREADS
296
297
if (use_threads ) {
297
- add_work (opt , GREP_SOURCE_SHA1 , pathbuf .buf , sha1 );
298
+ add_work (opt , GREP_SOURCE_SHA1 , pathbuf .buf , path , sha1 );
298
299
strbuf_release (& pathbuf );
299
300
return 0 ;
300
301
} else
@@ -303,7 +304,7 @@ static int grep_sha1(struct grep_opt *opt, const unsigned char *sha1,
303
304
struct grep_source gs ;
304
305
int hit ;
305
306
306
- grep_source_init (& gs , GREP_SOURCE_SHA1 , pathbuf .buf , sha1 );
307
+ grep_source_init (& gs , GREP_SOURCE_SHA1 , pathbuf .buf , path , sha1 );
307
308
strbuf_release (& pathbuf );
308
309
hit = grep_source (opt , & gs );
309
310
@@ -323,7 +324,7 @@ static int grep_file(struct grep_opt *opt, const char *filename)
323
324
324
325
#ifndef NO_PTHREADS
325
326
if (use_threads ) {
326
- add_work (opt , GREP_SOURCE_FILE , buf .buf , filename );
327
+ add_work (opt , GREP_SOURCE_FILE , buf .buf , filename , filename );
327
328
strbuf_release (& buf );
328
329
return 0 ;
329
330
} else
@@ -332,7 +333,7 @@ static int grep_file(struct grep_opt *opt, const char *filename)
332
333
struct grep_source gs ;
333
334
int hit ;
334
335
335
- grep_source_init (& gs , GREP_SOURCE_FILE , buf .buf , filename );
336
+ grep_source_init (& gs , GREP_SOURCE_FILE , buf .buf , filename , filename );
336
337
strbuf_release (& buf );
337
338
hit = grep_source (opt , & gs );
338
339
@@ -388,7 +389,7 @@ static int grep_cache(struct grep_opt *opt, const struct pathspec *pathspec, int
388
389
if (cached || (ce -> ce_flags & CE_VALID ) || ce_skip_worktree (ce )) {
389
390
if (ce_stage (ce ))
390
391
continue ;
391
- hit |= grep_sha1 (opt , ce -> sha1 , ce -> name , 0 );
392
+ hit |= grep_sha1 (opt , ce -> sha1 , ce -> name , 0 , ce -> name );
392
393
}
393
394
else
394
395
hit |= grep_file (opt , ce -> name );
@@ -406,7 +407,8 @@ static int grep_cache(struct grep_opt *opt, const struct pathspec *pathspec, int
406
407
}
407
408
408
409
static int grep_tree (struct grep_opt * opt , const struct pathspec * pathspec ,
409
- struct tree_desc * tree , struct strbuf * base , int tn_len )
410
+ struct tree_desc * tree , struct strbuf * base , int tn_len ,
411
+ int check_attr )
410
412
{
411
413
int hit = 0 ;
412
414
enum interesting match = entry_not_interesting ;
@@ -427,7 +429,8 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
427
429
strbuf_add (base , entry .path , te_len );
428
430
429
431
if (S_ISREG (entry .mode )) {
430
- hit |= grep_sha1 (opt , entry .sha1 , base -> buf , tn_len );
432
+ hit |= grep_sha1 (opt , entry .sha1 , base -> buf , tn_len ,
433
+ check_attr ? base -> buf + tn_len : NULL );
431
434
}
432
435
else if (S_ISDIR (entry .mode )) {
433
436
enum object_type type ;
@@ -442,7 +445,8 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
442
445
443
446
strbuf_addch (base , '/' );
444
447
init_tree_desc (& sub , data , size );
445
- hit |= grep_tree (opt , pathspec , & sub , base , tn_len );
448
+ hit |= grep_tree (opt , pathspec , & sub , base , tn_len ,
449
+ check_attr );
446
450
free (data );
447
451
}
448
452
strbuf_setlen (base , old_baselen );
@@ -457,7 +461,7 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,
457
461
struct object * obj , const char * name )
458
462
{
459
463
if (obj -> type == OBJ_BLOB )
460
- return grep_sha1 (opt , obj -> sha1 , name , 0 );
464
+ return grep_sha1 (opt , obj -> sha1 , name , 0 , NULL );
461
465
if (obj -> type == OBJ_COMMIT || obj -> type == OBJ_TREE ) {
462
466
struct tree_desc tree ;
463
467
void * data ;
@@ -480,7 +484,8 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,
480
484
strbuf_addch (& base , ':' );
481
485
}
482
486
init_tree_desc (& tree , data , size );
483
- hit = grep_tree (opt , pathspec , & tree , & base , base .len );
487
+ hit = grep_tree (opt , pathspec , & tree , & base , base .len ,
488
+ obj -> type == OBJ_COMMIT );
484
489
strbuf_release (& base );
485
490
free (data );
486
491
return hit ;
0 commit comments