summaryrefslogtreecommitdiff
path: root/diffcore-pickaxe.c
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2018-01-23 13:16:37 -0800
committerLibravatar Junio C Hamano <gitster@pobox.com>2018-01-23 13:16:37 -0800
commitc0d75f0e2e2cbf432358bfd00be593fd28e257a3 (patch)
treeddf40ec50af3fb5dae3793950ec366fd3a03e2b5 /diffcore-pickaxe.c
parentMerge branch 'jk/abort-clone-with-existing-dest' (diff)
parentdiff: use HAS_MULTI_BITS instead of counting bits manually (diff)
downloadtgif-c0d75f0e2e2cbf432358bfd00be593fd28e257a3.tar.xz
Merge branch 'sb/diff-blobfind-pickaxe'
"diff" family of commands learned "--find-object=<object-id>" option to limit the findings to changes that involve the named object. * sb/diff-blobfind-pickaxe: diff: use HAS_MULTI_BITS instead of counting bits manually diff: properly error out when combining multiple pickaxe options diffcore: add a pickaxe option to find a specific blob diff: introduce DIFF_PICKAXE_KINDS_MASK diff: migrate diff_flags.pickaxe_ignore_case to a pickaxe_opts bit diff.h: make pickaxe_opts an unsigned bit field
Diffstat (limited to 'diffcore-pickaxe.c')
-rw-r--r--diffcore-pickaxe.c48
1 files changed, 28 insertions, 20 deletions
diff --git a/diffcore-pickaxe.c b/diffcore-pickaxe.c
index 9476bd2108..239ce5122b 100644
--- a/diffcore-pickaxe.c
+++ b/diffcore-pickaxe.c
@@ -124,13 +124,20 @@ static int pickaxe_match(struct diff_filepair *p, struct diff_options *o,
mmfile_t mf1, mf2;
int ret;
- if (!o->pickaxe[0])
- return 0;
-
/* ignore unmerged */
if (!DIFF_FILE_VALID(p->one) && !DIFF_FILE_VALID(p->two))
return 0;
+ if (o->objfind) {
+ return (DIFF_FILE_VALID(p->one) &&
+ oidset_contains(o->objfind, &p->one->oid)) ||
+ (DIFF_FILE_VALID(p->two) &&
+ oidset_contains(o->objfind, &p->two->oid));
+ }
+
+ if (!o->pickaxe[0])
+ return 0;
+
if (o->flags.allow_textconv) {
textconv_one = get_textconv(p->one);
textconv_two = get_textconv(p->two);
@@ -222,33 +229,34 @@ void diffcore_pickaxe(struct diff_options *o)
if (opts & (DIFF_PICKAXE_REGEX | DIFF_PICKAXE_KIND_G)) {
int cflags = REG_EXTENDED | REG_NEWLINE;
- if (o->flags.pickaxe_ignore_case)
+ if (o->pickaxe_opts & DIFF_PICKAXE_IGNORE_CASE)
cflags |= REG_ICASE;
regcomp_or_die(&regex, needle, cflags);
regexp = &regex;
- } else if (o->flags.pickaxe_ignore_case &&
- has_non_ascii(needle)) {
- struct strbuf sb = STRBUF_INIT;
- int cflags = REG_NEWLINE | REG_ICASE;
-
- basic_regex_quote_buf(&sb, needle);
- regcomp_or_die(&regex, sb.buf, cflags);
- strbuf_release(&sb);
- regexp = &regex;
- } else {
- kws = kwsalloc(o->flags.pickaxe_ignore_case
- ? tolower_trans_tbl : NULL);
- kwsincr(kws, needle, strlen(needle));
- kwsprep(kws);
+ } else if (opts & DIFF_PICKAXE_KIND_S) {
+ if (o->pickaxe_opts & DIFF_PICKAXE_IGNORE_CASE &&
+ has_non_ascii(needle)) {
+ struct strbuf sb = STRBUF_INIT;
+ int cflags = REG_NEWLINE | REG_ICASE;
+
+ basic_regex_quote_buf(&sb, needle);
+ regcomp_or_die(&regex, sb.buf, cflags);
+ strbuf_release(&sb);
+ regexp = &regex;
+ } else {
+ kws = kwsalloc(o->pickaxe_opts & DIFF_PICKAXE_IGNORE_CASE
+ ? tolower_trans_tbl : NULL);
+ kwsincr(kws, needle, strlen(needle));
+ kwsprep(kws);
+ }
}
- /* Might want to warn when both S and G are on; I don't care... */
pickaxe(&diff_queued_diff, o, regexp, kws,
(opts & DIFF_PICKAXE_KIND_G) ? diff_grep : has_changes);
if (regexp)
regfree(regexp);
- else
+ if (kws)
kwsfree(kws);
return;
}