Skip to content

Commit 354d9f8

Browse files
committed
Merge branch 'jc/maint-grep-one-thread-mutex-fix' into maint
* jc/maint-grep-one-thread-mutex-fix: Fix use of mutex in threaded grep
2 parents e7b3cea + 5f02d31 commit 354d9f8

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

builtin-grep.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -408,15 +408,25 @@ static int pathspec_matches(const char **paths, const char *name, int max_depth)
408408
return 0;
409409
}
410410

411+
static void *lock_and_read_sha1_file(const unsigned char *sha1, enum object_type *type, unsigned long *size)
412+
{
413+
void *data;
414+
415+
if (use_threads) {
416+
read_sha1_lock();
417+
data = read_sha1_file(sha1, type, size);
418+
read_sha1_unlock();
419+
} else {
420+
data = read_sha1_file(sha1, type, size);
421+
}
422+
return data;
423+
}
424+
411425
static void *load_sha1(const unsigned char *sha1, unsigned long *size,
412426
const char *name)
413427
{
414428
enum object_type type;
415-
char *data;
416-
417-
read_sha1_lock();
418-
data = read_sha1_file(sha1, &type, size);
419-
read_sha1_unlock();
429+
void *data = lock_and_read_sha1_file(sha1, &type, size);
420430

421431
if (!data)
422432
error("'%s': unable to read %s", name, sha1_to_hex(sha1));
@@ -605,10 +615,7 @@ static int grep_tree(struct grep_opt *opt, const char **paths,
605615
void *data;
606616
unsigned long size;
607617

608-
read_sha1_lock();
609-
data = read_sha1_file(entry.sha1, &type, &size);
610-
read_sha1_unlock();
611-
618+
data = lock_and_read_sha1_file(entry.sha1, &type, &size);
612619
if (!data)
613620
die("unable to read tree (%s)",
614621
sha1_to_hex(entry.sha1));

0 commit comments

Comments
 (0)