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

Function show_line

grep.c:1237–1307  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1235}
1236
1237static void show_line(struct grep_opt *opt,
1238 const char *bol, const char *eol,
1239 const char *name, unsigned lno, ssize_t cno, char sign)
1240{
1241 int rest = eol - bol;
1242 const char *match_color = NULL;
1243 const char *line_color = NULL;
1244
1245 if (opt->file_break && opt->last_shown == 0) {
1246 if (opt->show_hunk_mark)
1247 opt->output(opt, "\n", 1);
1248 } else if (opt->pre_context || opt->post_context || opt->funcbody) {
1249 if (opt->last_shown == 0) {
1250 if (opt->show_hunk_mark) {
1251 output_color(opt, "--", 2, opt->colors[GREP_COLOR_SEP]);
1252 opt->output(opt, "\n", 1);
1253 }
1254 } else if (lno > opt->last_shown + 1) {
1255 output_color(opt, "--", 2, opt->colors[GREP_COLOR_SEP]);
1256 opt->output(opt, "\n", 1);
1257 }
1258 }
1259 if (!opt->only_matching) {
1260 /*
1261 * In case the line we're being called with contains more than
1262 * one match, leave printing each header to the loop below.
1263 */
1264 show_line_header(opt, name, lno, cno, sign);
1265 }
1266 if (want_color(opt->color) || opt->only_matching) {
1267 regmatch_t match;
1268 enum grep_context ctx = GREP_CONTEXT_BODY;
1269 int eflags = 0;
1270 const char *start = bol;
1271
1272 if (want_color(opt->color)) {
1273 if (sign == ':')
1274 match_color = opt->colors[GREP_COLOR_MATCH_SELECTED];
1275 else
1276 match_color = opt->colors[GREP_COLOR_MATCH_CONTEXT];
1277 if (sign == ':')
1278 line_color = opt->colors[GREP_COLOR_SELECTED];
1279 else if (sign == '-')
1280 line_color = opt->colors[GREP_COLOR_CONTEXT];
1281 else if (sign == '=')
1282 line_color = opt->colors[GREP_COLOR_FUNCTION];
1283 }
1284 while (grep_next_match(opt, bol, eol, ctx, &match,
1285 GREP_HEADER_FIELD_MAX, eflags)) {
1286 if (match.rm_so == match.rm_eo)
1287 break;
1288
1289 cno = bol - start + match.rm_so + 1;
1290 if (opt->only_matching)
1291 show_line_header(opt, name, lno, cno, sign);
1292 else
1293 output_color(opt, bol, match.rm_so, line_color);
1294 output_color(opt, bol + match.rm_so,

Callers 3

show_funcname_lineFunction · 0.85
show_pre_contextFunction · 0.85
grep_source_1Function · 0.85

Calls 3

output_colorFunction · 0.85
show_line_headerFunction · 0.85
grep_next_matchFunction · 0.85

Tested by

no test coverage detected