From: Junio C Hamano Date: Sun, 16 Oct 2011 03:46:37 +0000 (-0700) Subject: Merge branch 'nm/grep-object-sha1-lock' into maint X-Git-Tag: v1.7.7.1~21 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=7c4f050ae1e140a81f66b5cf92ad2c8673cfda8b;p=git.git Merge branch 'nm/grep-object-sha1-lock' into maint * nm/grep-object-sha1-lock: grep: Fix race condition in delta_base_cache Conflicts: builtin/grep.c --- 7c4f050ae1e140a81f66b5cf92ad2c8673cfda8b diff --cc builtin/grep.c index 1c359c267,0eb192d48..a286692e4 --- a/builtin/grep.c +++ b/builtin/grep.c @@@ -595,23 -631,17 +595,26 @@@ static int grep_object(struct grep_opt struct tree_desc tree; void *data; unsigned long size; - int hit; + struct strbuf base; + int hit, len; + read_sha1_lock(); data = read_object_with_reference(obj->sha1, tree_type, &size, NULL); + read_sha1_unlock(); + if (!data) - die("unable to read tree (%s)", sha1_to_hex(obj->sha1)); + die(_("unable to read tree (%s)"), sha1_to_hex(obj->sha1)); + + len = name ? strlen(name) : 0; + strbuf_init(&base, PATH_MAX + len + 1); + if (len) { + strbuf_add(&base, name, len); + strbuf_addch(&base, ':'); + } init_tree_desc(&tree, data, size); - hit = grep_tree(opt, paths, &tree, name, ""); + hit = grep_tree(opt, pathspec, &tree, &base, base.len); + strbuf_release(&base); free(data); return hit; }