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

Function diffcore_pickaxe

diffcore-pickaxe.c:231–292  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

229}
230
231void diffcore_pickaxe(struct diff_options *o)
232{
233 const char *needle = o->pickaxe;
234 int opts = o->pickaxe_opts;
235 regex_t regex, *regexp = NULL;
236 kwset_t kws = NULL;
237 pickaxe_fn fn;
238
239 if (opts & ~DIFF_PICKAXE_KIND_OBJFIND &&
240 (!needle || !*needle))
241 BUG("should have needle under -G or -S");
242 if (opts & (DIFF_PICKAXE_REGEX | DIFF_PICKAXE_KIND_G)) {
243 int cflags = REG_EXTENDED | REG_NEWLINE;
244 if (o->pickaxe_opts & DIFF_PICKAXE_IGNORE_CASE)
245 cflags |= REG_ICASE;
246 regcomp_or_die(&regex, needle, cflags);
247 regexp = &regex;
248
249 if (opts & DIFF_PICKAXE_KIND_G)
250 fn = diff_grep;
251 else if (opts & DIFF_PICKAXE_REGEX)
252 fn = has_changes;
253 else
254 /*
255 * We don't need to check the combination of
256 * -G and --pickaxe-regex, by the time we get
257 * here diff.c has already died if they're
258 * combined. See the usage tests in
259 * t4209-log-pickaxe.sh.
260 */
261 BUG("unreachable");
262 } else if (opts & DIFF_PICKAXE_KIND_S) {
263 if (o->pickaxe_opts & DIFF_PICKAXE_IGNORE_CASE &&
264 has_non_ascii(needle)) {
265 struct strbuf sb = STRBUF_INIT;
266 int cflags = REG_NEWLINE | REG_ICASE;
267
268 basic_regex_quote_buf(&sb, needle);
269 regcomp_or_die(&regex, sb.buf, cflags);
270 strbuf_release(&sb);
271 regexp = &regex;
272 } else {
273 kws = kwsalloc(o->pickaxe_opts & DIFF_PICKAXE_IGNORE_CASE
274 ? tolower_trans_tbl : NULL);
275 kwsincr(kws, needle, strlen(needle));
276 kwsprep(kws);
277 }
278 fn = has_changes;
279 } else if (opts & DIFF_PICKAXE_KIND_OBJFIND) {
280 fn = NULL;
281 } else {
282 BUG("unknown pickaxe_opts flag");
283 }
284
285 pickaxe(&diff_queued_diff, o, regexp, kws, fn);
286
287 if (regexp)
288 regfree(regexp);

Callers 1

diffcore_stdFunction · 0.85

Calls 10

regcomp_or_dieFunction · 0.85
basic_regex_quote_bufFunction · 0.85
strbuf_releaseFunction · 0.85
kwsallocFunction · 0.85
kwsincrFunction · 0.85
kwsprepFunction · 0.85
pickaxeFunction · 0.85
regfreeFunction · 0.85
kwsfreeFunction · 0.85
has_non_asciiFunction · 0.70

Tested by

no test coverage detected