| 834 | } |
| 835 | |
| 836 | static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec, |
| 837 | struct object *obj, const char *name, const char *path) |
| 838 | { |
| 839 | if (obj->type == OBJ_BLOB) |
| 840 | return grep_oid(opt, &obj->oid, name, 0, path); |
| 841 | if (obj->type == OBJ_COMMIT || obj->type == OBJ_TREE) { |
| 842 | struct tree_desc tree; |
| 843 | void *data; |
| 844 | size_t size; |
| 845 | struct strbuf base; |
| 846 | int hit, len; |
| 847 | |
| 848 | data = odb_read_object_peeled(opt->repo->objects, &obj->oid, |
| 849 | OBJ_TREE, &size, NULL); |
| 850 | if (!data) |
| 851 | die(_("unable to read tree (%s)"), oid_to_hex(&obj->oid)); |
| 852 | |
| 853 | len = name ? strlen(name) : 0; |
| 854 | strbuf_init(&base, PATH_MAX + len + 1); |
| 855 | if (len) { |
| 856 | strbuf_add(&base, name, len); |
| 857 | strbuf_addch(&base, ':'); |
| 858 | } |
| 859 | init_tree_desc(&tree, &obj->oid, data, size); |
| 860 | hit = grep_tree(opt, pathspec, &tree, &base, base.len, |
| 861 | obj->type == OBJ_COMMIT); |
| 862 | strbuf_release(&base); |
| 863 | free(data); |
| 864 | return hit; |
| 865 | } |
| 866 | die(_("unable to grep from object of type %s"), type_name(obj->type)); |
| 867 | } |
| 868 | |
| 869 | static int grep_objects(struct grep_opt *opt, const struct pathspec *pathspec, |
| 870 | const struct object_array *list) |
no test coverage detected