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

Function grep_tree

builtin/grep.c:628–696  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

626}
627
628static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
629 struct tree_desc *tree, struct strbuf *base, int tn_len,
630 int check_attr)
631{
632 struct repository *repo = opt->repo;
633 int hit = 0;
634 enum interesting match = entry_not_interesting;
635 struct name_entry entry;
636 int old_baselen = base->len;
637 struct strbuf name = STRBUF_INIT;
638 int name_base_len = 0;
639 if (repo->submodule_prefix) {
640 strbuf_addstr(&name, repo->submodule_prefix);
641 name_base_len = name.len;
642 }
643
644 while (tree_entry(tree, &entry)) {
645 int te_len = tree_entry_len(&entry);
646
647 if (match != all_entries_interesting) {
648 strbuf_addstr(&name, base->buf + tn_len);
649 match = tree_entry_interesting(repo->index,
650 &entry, &name,
651 pathspec);
652 strbuf_setlen(&name, name_base_len);
653
654 if (match == all_entries_not_interesting)
655 break;
656 if (match == entry_not_interesting)
657 continue;
658 }
659
660 strbuf_add(base, entry.path, te_len);
661
662 if (S_ISREG(entry.mode)) {
663 hit |= grep_oid(opt, &entry.oid, base->buf, tn_len,
664 check_attr ? base->buf + tn_len : NULL);
665 } else if (S_ISDIR(entry.mode)) {
666 enum object_type type;
667 struct tree_desc sub;
668 void *data;
669 size_t size;
670
671 data = odb_read_object(the_repository->objects,
672 &entry.oid, &type, &size);
673 if (!data)
674 die(_("unable to read tree (%s)"),
675 oid_to_hex(&entry.oid));
676
677 strbuf_addch(base, '/');
678 init_tree_desc(&sub, &entry.oid, data, size);
679 hit |= grep_tree(opt, pathspec, &sub, base, tn_len,
680 check_attr);
681 free(data);
682 } else if (recurse_submodules && S_ISGITLINK(entry.mode)) {
683 hit |= grep_submodule(opt, pathspec, &entry.oid,
684 base->buf, base->buf + tn_len,
685 1); /* ignored */

Callers 3

grep_submoduleFunction · 0.85
grep_cacheFunction · 0.85
grep_objectFunction · 0.85

Calls 14

strbuf_addstrFunction · 0.85
tree_entry_lenFunction · 0.85
tree_entry_interestingFunction · 0.85
strbuf_setlenFunction · 0.85
strbuf_addFunction · 0.85
grep_oidFunction · 0.85
odb_read_objectFunction · 0.85
oid_to_hexFunction · 0.85
strbuf_addchFunction · 0.85
init_tree_descFunction · 0.85
grep_submoduleFunction · 0.85
strbuf_releaseFunction · 0.85

Tested by

no test coverage detected