summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b599672)
raw | patch | inline | side by side (parent: b599672)
author | Junio C Hamano <gitster@pobox.com> | |
Tue, 16 Feb 2010 02:34:28 +0000 (18:34 -0800) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Wed, 17 Feb 2010 03:19:05 +0000 (19:19 -0800) |
The program can decide at runtime not to use threading even if the support
is compiled in. In such a case, mutexes are not necessary and left
uninitialized. But the code incorrectly tried to take and release the
read_sha1_mutex unconditionally.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Acked-by: Fredrik Kuivinen <frekui@gmail.com>
is compiled in. In such a case, mutexes are not necessary and left
uninitialized. But the code incorrectly tried to take and release the
read_sha1_mutex unconditionally.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Acked-by: Fredrik Kuivinen <frekui@gmail.com>
builtin-grep.c | patch | blob | history |
diff --git a/builtin-grep.c b/builtin-grep.c
index 26d4deb1cce3e5540411a47fdf35085649669d06..362122c4325a0419a038fda52768d78d3e12dc31 100644 (file)
--- 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));
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));