aboutsummaryrefslogtreecommitdiff
path: root/builtin-grep.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2010-02-16 22:40:45 -0800
committerJunio C Hamano <gitster@pobox.com>2010-02-16 22:40:45 -0800
commit72cd63c008c673e185740a694cdf3e85711df3d2 (patch)
tree769aa7f5f340d15e71777eb6337bb711b2f5630e /builtin-grep.c
parent7e5eb8f1834722507e2d2171a253b78b1d924458 (diff)
parentd3f69766c431bab6321fed1ce64d914dc44ff87f (diff)
downloadgit-72cd63c008c673e185740a694cdf3e85711df3d2.tar.gz
git-72cd63c008c673e185740a694cdf3e85711df3d2.tar.xz
Merge branch 'maint'
* maint: Prepare 1.7.0.1 release notes Fix use of mutex in threaded grep dwim_ref: fix dangling symref warning stash pop: remove 'apply' options during 'drop' invocation diff: make sure --output=/bad/path is caught Remove hyphen from "git-command" in two error messages
Diffstat (limited to 'builtin-grep.c')
-rw-r--r--builtin-grep.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/builtin-grep.c b/builtin-grep.c
index 46ffc1d1d..552ef1fac 100644
--- a/builtin-grep.c
+++ b/builtin-grep.c
@@ -409,15 +409,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));
@@ -606,10 +616,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));