MCPcopy Create free account
hub / github.com/git/git / grep_object

Function grep_object

builtin/grep.c:836–867  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

834}
835
836static 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
869static int grep_objects(struct grep_opt *opt, const struct pathspec *pathspec,
870 const struct object_array *list)

Callers 1

grep_objectsFunction · 0.85

Calls 11

grep_oidFunction · 0.85
odb_read_object_peeledFunction · 0.85
oid_to_hexFunction · 0.85
strbuf_initFunction · 0.85
strbuf_addFunction · 0.85
strbuf_addchFunction · 0.85
init_tree_descFunction · 0.85
grep_treeFunction · 0.85
strbuf_releaseFunction · 0.85
type_nameFunction · 0.85
dieFunction · 0.50

Tested by

no test coverage detected