From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS53758 23.128.96.0/24 X-Spam-Status: No, score=-3.7 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by dcvr.yhbt.net (Postfix) with ESMTP id 627691F9E5 for ; Mon, 12 Apr 2021 17:16:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244110AbhDLRQq (ORCPT ); Mon, 12 Apr 2021 13:16:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244183AbhDLRQU (ORCPT ); Mon, 12 Apr 2021 13:16:20 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B06CFC061346 for ; Mon, 12 Apr 2021 10:15:48 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id u20so2725869wmj.0 for ; Mon, 12 Apr 2021 10:15:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SJ9SoNjSLWvJAM/mKOXWgKqyTTcCfnyLuV9X5q6Kx9s=; b=rP51pbCpaCFeGmmo/G/EEj1Sc0jJqyo/5sInbOdpNONdiEmujVO1/6xvKJbboLCbGm 75iboYJUPTi5BZCUxo39kZJdrPoVlwRGRd7CjwLy+rYnPy8dBrm+diqZjDTtef2XsC25 Xhe1+Jyf/vuE+q9tnsp/8IJqYaKROb9tDS6KkzxdWLnDXP2pQHgm08RVGFNFF/eR6Pa6 0yGjZdghSpMD54l9aYzBI59jXbl4of3DIRfMHI7uPMMOQN9xH82U8XwNKszM/uc7yUwD 6srkWqJVrnEcLhqLdb+xrZ4Iyy0K7JKxo5cHvfuP++BDrvfa7C137ZcVL+h8D4BnQXuj rDxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SJ9SoNjSLWvJAM/mKOXWgKqyTTcCfnyLuV9X5q6Kx9s=; b=D/0G8KQqbM0uLsxLLg9CmwIq2OqAAuK1KrWq/aOfD9YcpV79/3owTdnad2T8XCSSFQ mr4uM/lAItXJBXdPbRwUTP+e0dL1ehiSdkT3ijexcKCkYIEEHMvSTWzOJWwrVPllZ0YC CnQbcyr/vMa0Sx/VIHtU4xPknB+VeizdZWyFi9h2nKFQwj58ccN7UWdOq3fL/e53xZPc EldBtUeOpEXA4OiAqpfujJLlGQBNgBeLntEaw/Nw6ISUJ+8R677rrKMcbi0+ewvh+zHr 9TTpBIQuWXi4XQQW8G//Z6vM7+iwppSGwZNjy4ozeVP06h5/xunbOaqP2XeLzrR4H3h5 wyHQ== X-Gm-Message-State: AOAM531/taLOIXxdG0OEDLPQIrCf72PLzVlq/g8vEuBqiBZC9E5eqjpK TMKcNcdK36YCXU5sMl7bjnSQC4tMOLpHmQ== X-Google-Smtp-Source: ABdhPJwqe7SAfrGNuWw4cSRfPb/M9yw8yw72oIX7IIzgeOmvZEND6EpnOEopwbQwtWU37y7cYjrZsQ== X-Received: by 2002:a1c:a78b:: with SMTP id q133mr175424wme.68.1618247747217; Mon, 12 Apr 2021 10:15:47 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j1sm7828625wrr.33.2021.04.12.10.15.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Apr 2021 10:15:46 -0700 (PDT) From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Johannes Schindelin , =?UTF-8?q?Carlo=20Marcelo=20Arenas=20Bel=C3=B3n?= , =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Subject: [PATCH v3 12/22] pickaxe: refactor function selection in diffcore-pickaxe() Date: Mon, 12 Apr 2021 19:15:19 +0200 Message-Id: X-Mailer: git-send-email 2.31.1.639.g3d04783866f In-Reply-To: References: <20210216115801.4773-1-avarab@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org 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 --- diffcore-pickaxe.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/diffcore-pickaxe.c b/diffcore-pickaxe.c index a278b9b71d9..953b6ec1b4a 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(®ex, needle, cflags); regexp = ®ex; + + 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); -- 2.31.1.639.g3d04783866f