MCPcopy Index your code
hub / github.com/git/git / grep_source_1

Function grep_source_1

grep.c:1566–1803  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1564}
1565
1566static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int collect_hits)
1567{
1568 const char *bol;
1569 const char *peek_bol = NULL;
1570 unsigned long left;
1571 unsigned lno = 1;
1572 unsigned last_hit = 0;
1573 int binary_match_only = 0;
1574 unsigned count = 0;
1575 int try_lookahead = 0;
1576 int show_function = 0;
1577 struct userdiff_driver *textconv = NULL;
1578 enum grep_context ctx = GREP_CONTEXT_HEAD;
1579 xdemitconf_t xecfg;
1580
1581 if (!opt->status_only && gs->name == NULL)
1582 BUG("grep call which could print a name requires "
1583 "grep_source.name be non-NULL");
1584
1585 if (!opt->output)
1586 opt->output = std_output;
1587
1588 if (opt->pre_context || opt->post_context || opt->file_break ||
1589 opt->funcbody) {
1590 /* Show hunk marks, except for the first file. */
1591 if (opt->last_shown)
1592 opt->show_hunk_mark = 1;
1593 /*
1594 * If we're using threads then we can't easily identify
1595 * the first file. Always put hunk marks in that case
1596 * and skip the very first one later in work_done().
1597 */
1598 if (opt->output != std_output)
1599 opt->show_hunk_mark = 1;
1600 }
1601 opt->last_shown = 0;
1602
1603 if (opt->allow_textconv) {
1604 grep_source_load_driver(gs, opt->repo->index);
1605 /*
1606 * We might set up the shared textconv cache data here, which
1607 * is not thread-safe. Also, get_oid_with_context() and
1608 * parse_object() might be internally called. As they are not
1609 * currently thread-safe and might be racy with object reading,
1610 * obj_read_lock() must be called.
1611 */
1612 grep_attr_lock();
1613 obj_read_lock();
1614 textconv = userdiff_get_textconv(opt->repo, gs->driver);
1615 obj_read_unlock();
1616 grep_attr_unlock();
1617 }
1618
1619 /*
1620 * We know the result of a textconv is text, so we only have to care
1621 * about binary handling if we are not using it.
1622 */
1623 if (!textconv) {

Callers 1

grep_sourceFunction · 0.85

Calls 15

grep_source_load_driverFunction · 0.85
grep_attr_lockFunction · 0.85
obj_read_lockFunction · 0.85
userdiff_get_textconvFunction · 0.85
obj_read_unlockFunction · 0.85
grep_attr_unlockFunction · 0.85
grep_source_is_binaryFunction · 0.85
should_lookaheadFunction · 0.85
fill_textconv_grepFunction · 0.85
look_aheadFunction · 0.85
end_of_lineFunction · 0.85
match_lineFunction · 0.85

Tested by

no test coverage detected