| 229 | } |
| 230 | |
| 231 | void 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(®ex, needle, cflags); |
| 247 | regexp = ®ex; |
| 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(®ex, sb.buf, cflags); |
| 270 | strbuf_release(&sb); |
| 271 | regexp = ®ex; |
| 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); |
no test coverage detected