Merge branch 'nm/grep-object-sha1-lock' into maint
authorJunio C Hamano <gitster@pobox.com>
Sun, 16 Oct 2011 03:46:37 +0000 (20:46 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sun, 16 Oct 2011 03:46:37 +0000 (20:46 -0700)
* nm/grep-object-sha1-lock:
  grep: Fix race condition in delta_base_cache

Conflicts:
builtin/grep.c

1  2 
builtin/grep.c

diff --cc builtin/grep.c
index 1c359c2671536287d97f2049b27a390d33b51e88,0eb192d488e64b693184b7d00f7740cbe075c879..a286692e467710d92346ab6900e98f1126cb967d
@@@ -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;
        }