summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2010-02-16 22:23:25 -0800
committerJunio C Hamano <gitster@pobox.com>2010-02-16 22:23:25 -0800
commit354d9f861b40e9c9bfeae7f939dc61e232aea415 (patch)
treeca5be5534001adfc52fd9cd0c4cc33aad50db519
parente7b3cea0f7589c57f7bb808330e32bdd7f901c95 (diff)
parent5f02d31597df35ca98e9080e12bfbb18dadadcbe (diff)
downloadgit-354d9f861b40e9c9bfeae7f939dc61e232aea415.tar.gz
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
-rw-r--r--builtin-grep.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/builtin-grep.c b/builtin-grep.c
index 26d4deb1cc..362122c432 100644
--- a/builtin-grep.c
+++ b/builtin-grep.c
@@ -408,15 +408,25 @@ static int pathspec_matches(const char **paths, const char *name, int max_depth)
return 0;
}
+static void *lock_and_read_sha1_file(const unsigned char *sha1, enum object_type *type, unsigned long *size)
+{
+ void *data;
+
+ if (use_threads) {
+ read_sha1_lock();
+ data = read_sha1_file(sha1, type, size);
+ read_sha1_unlock();
+ } else {
+ data = read_sha1_file(sha1, type, size);
+ }
+ return data;
+}
+
static void *load_sha1(const unsigned char *sha1, unsigned long *size,
const char *name)
{
enum object_type type;
- char *data;
-
- read_sha1_lock();
- data = read_sha1_file(sha1, &type, size);
- read_sha1_unlock();
+ void *data = lock_and_read_sha1_file(sha1, &type, size);
if (!data)
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,
void *data;
unsigned long size;
- read_sha1_lock();
- data = read_sha1_file(entry.sha1, &type, &size);
- read_sha1_unlock();
-
+ data = lock_and_read_sha1_file(entry.sha1, &type, &size);
if (!data)
die("unable to read tree (%s)",
sha1_to_hex(entry.sha1));