Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>2021-04-12 20:15:19 +0300
committerJunio C Hamano <gitster@pobox.com>2021-05-11 06:47:31 +0300
commit03c1f14acf5169d8e6c06a60c28ee5a6cfb9fd54 (patch)
treee5b7b3b1c08f6d898e8d65582bb5bb0fc16f6d79 /diffcore-pickaxe.c
parentd90d441c336cc120b47e025d14c3879864ce60c5 (diff)
pickaxe: refactor function selection in diffcore-pickaxe()
It's hard to read this codepath at a glance and reason about exactly what combination of -G and -S will compile either regexes or kwset, and whether we'll then dispatch to "diff_grep" or "has_changes". Then in the "--find-object" case we aren't using the callback function, but were previously passing down "has_changes". Refactor this code to exhaustively check "opts", it's now more obvious what callback function (or none) we want under what mode. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'diffcore-pickaxe.c')
-rw-r--r--diffcore-pickaxe.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/diffcore-pickaxe.c b/diffcore-pickaxe.c
index a278b9b71d..953b6ec1b4 100644
--- a/diffcore-pickaxe.c
+++ b/diffcore-pickaxe.c
@@ -228,6 +228,7 @@ void diffcore_pickaxe(struct diff_options *o)
int opts = o->pickaxe_opts;
regex_t regex, *regexp = NULL;
kwset_t kws = NULL;
+ pickaxe_fn fn;
if (opts & (DIFF_PICKAXE_REGEX | DIFF_PICKAXE_KIND_G)) {
int cflags = REG_EXTENDED | REG_NEWLINE;
@@ -235,6 +236,20 @@ void diffcore_pickaxe(struct diff_options *o)
cflags |= REG_ICASE;
regcomp_or_die(&regex, needle, cflags);
regexp = &regex;
+
+ if (opts & DIFF_PICKAXE_KIND_G)
+ fn = diff_grep;
+ else if (opts & DIFF_PICKAXE_REGEX)
+ fn = has_changes;
+ else
+ /*
+ * We don't need to check the combination of
+ * -G and --pickaxe-regex, by the time we get
+ * here diff.c has already died if they're
+ * combined. See the usage tests in
+ * t4209-log-pickaxe.sh.
+ */
+ BUG("unreachable");
} else if (opts & DIFF_PICKAXE_KIND_S) {
if (o->pickaxe_opts & DIFF_PICKAXE_IGNORE_CASE &&
has_non_ascii(needle)) {
@@ -251,10 +266,14 @@ void diffcore_pickaxe(struct diff_options *o)
kwsincr(kws, needle, strlen(needle));
kwsprep(kws);
}
+ fn = has_changes;
+ } else if (opts & DIFF_PICKAXE_KIND_OBJFIND) {
+ fn = NULL;
+ } else {
+ BUG("unknown pickaxe_opts flag");
}
- pickaxe(&diff_queued_diff, o, regexp, kws,
- (opts & DIFF_PICKAXE_KIND_G) ? diff_grep : has_changes);
+ pickaxe(&diff_queued_diff, o, regexp, kws, fn);
if (regexp)
regfree(regexp);