From: Junio C Hamano Date: Wed, 5 Oct 2011 19:35:53 +0000 (-0700) Subject: Merge branch 'nm/grep-object-sha1-lock' X-Git-Tag: v1.7.8-rc0~154 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=00723b02912cc9dae1ee5601ab4b942fdd42ff52;p=git.git Merge branch 'nm/grep-object-sha1-lock' * nm/grep-object-sha1-lock: grep: Fix race condition in delta_base_cache Conflicts: builtin/grep.c --- 00723b02912cc9dae1ee5601ab4b942fdd42ff52 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; }