From patchwork Tue Jan 18 15:55:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12716662 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 02196C433FE for ; Tue, 18 Jan 2022 15:55:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346068AbiARPzd (ORCPT ); Tue, 18 Jan 2022 10:55:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235165AbiARPzc (ORCPT ); Tue, 18 Jan 2022 10:55:32 -0500 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4E09C061574 for ; Tue, 18 Jan 2022 07:55:31 -0800 (PST) Received: by mail-wm1-x331.google.com with SMTP id c66so28664272wma.5 for ; Tue, 18 Jan 2022 07:55:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=htWFYEwkxqxb9Qkmb+ym08W7UtCr6ApdcJvQbF/gtI8=; b=KitXeAV7Fk/azh6FlwJsj7nKVZH2NOyWrSicy2xdjgIV4OeONXeK7Zz9zqlluuQ6gC ffSAxI7sxyhhteug7LUDqNjsTZM9QGwtxJ+6jCDzYdiVn6Dc9zCbYbtyysZpOspy8DxV ZZSOVUP9ZpBeIWw5yntCbb2v/GTM9aIvle9zrbvOJj8ABbF60GsFgrUaa7HREpxJv42E vIZ0AEM6Aa6u3Kai/zRxwsc9fYaIZ3JNySQFQI0tpJn2sbOIu1700BaH5jK7vH2m6Jdz 8NDgtaSOB07xEOu6b8l+xxIIuI/jDTJNUkMqAkpHcUQEADCzzJAobwqJm4YW+Zzo4gyC X56g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=htWFYEwkxqxb9Qkmb+ym08W7UtCr6ApdcJvQbF/gtI8=; b=PSJJwtt6YL66czk9MHz0akGfXvrAZh7wX8t/hyS130vEkuX2xP1xCquUGm7SjssAr5 NPMdu4jnhz05OyUECajrb0M2qkJfvI/eOmPBczakeOfy7d2EnpdIYTM5HLglAsBKdCWw aR46Ve/SN5rHts725JNl4LoQ1XSX52pOpCDaadLAqp/I/0zXCInBOJcERsdr1cD+3nj1 wRLC79PpYxcolTnt2aHXuYbGTdkdbA2m/19VgtccgT2DoVb8IFStjaKaebazUbEQKHVN +tXQv2+iLOj+U+2grDHwz+3ntwv+9Qi/DPuy+ijDqqTJFwaKtf4Cst9Vdv3Q5QNGlGTT lEkw== X-Gm-Message-State: AOAM531U2YpKwd9qMWfhjDtYEL0UaW5f/gFURZ+TEbToteMM81IcMT8b lUCjGLAFG6m07Cp+stN5sB1VPZmWYOr+0Q== X-Google-Smtp-Source: ABdhPJw0atZVq0fer4sJ53fsHbLF5JGndlyBk/UUFKEOW5qeF3L3MOQQ1+YQb+hH/VVw5GC/LaJYNA== X-Received: by 2002:a05:6000:178b:: with SMTP id e11mr22133264wrg.126.1642521330181; Tue, 18 Jan 2022 07:55:30 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id f15sm1220522wrd.45.2022.01.18.07.55.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jan 2022 07:55:29 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , J Smith , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFz?= =?utf-8?b?b24=?= Subject: [PATCH v8 01/10] grep.h: remove unused "regex_t regexp" from grep_opt Date: Tue, 18 Jan 2022 16:55:13 +0100 Message-Id: X-Mailer: git-send-email 2.35.0.rc1.864.g57621b115b6 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org This "regex_t" in grep_opt has not been used since f9b9faf6f8a (builtin-grep: allow more than one patterns., 2006-05-02), we still use a "regex_t" for compiling regexes, but that's in the "grep_pat" struct". Signed-off-by: Ævar Arnfjörð Bjarmason --- grep.h | 1 - 1 file changed, 1 deletion(-) diff --git a/grep.h b/grep.h index 6a1f0ab0172..400172676a1 100644 --- a/grep.h +++ b/grep.h @@ -136,7 +136,6 @@ struct grep_opt { const char *prefix; int prefix_length; - regex_t regexp; int linenum; int columnnum; int invert; From patchwork Tue Jan 18 15:55:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12716663 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C774C433F5 for ; Tue, 18 Jan 2022 15:55:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346095AbiARPze (ORCPT ); Tue, 18 Jan 2022 10:55:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235165AbiARPzd (ORCPT ); Tue, 18 Jan 2022 10:55:33 -0500 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE68DC061574 for ; Tue, 18 Jan 2022 07:55:32 -0800 (PST) Received: by mail-wm1-x335.google.com with SMTP id 25-20020a05600c231900b003497473a9c4so6885584wmo.5 for ; Tue, 18 Jan 2022 07:55:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PL4wpSjoF8uf4oVqlcrEZ+XNhgLG2HLlzjpO6lMpTTA=; b=LmClfM75/ZmBKBUHvKOubFtfi2Hhr4ISUNthnPMdHnTwEYmb3Y94qrUtAx/+8Ep8GQ 9ZDqjCeF+6zgE3V+R+u1CpemntMd2QTcwW/BbR3caIGhyQDCcZTg3FyRBeliX/bbKRHP QOfu5VNy89OjmhtlDw/+5H3sgbbICDWtcfP5cHXKyTp4/iD+v9xKrkBApRufl6vMWehW Z6N6xG6r+IUX9An5WpBYa+hbW7Tbvjv8hJqJCjjk7Rxqsr7MQ1GO6yzezIUIFUL8lGzM WsIXi92vn+LILuq9iNvNv1xLvh2KFmBi8LsT2tfwq+nbXV3YT5pyBAWZvSFGanaZSiRm cK3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PL4wpSjoF8uf4oVqlcrEZ+XNhgLG2HLlzjpO6lMpTTA=; b=nPjelSX0p45556I4UIXefHWcEsDnL87iCq0SSb5Q6H2WZngDzXP7U3fS5LHIS9pjXK HFf1MxV02SXXZegyieHUFtnDeK2zm4v8Dhjc3z8UYHkiTk/pIoHpw6/jAzOYvboasdb+ 7Hv3gePf1KnUi7HMTCOA3jEzRcdMKoTRQOFsuWJ9ZodSR0MFzpZ89rhehy7jCrUc3neq G6qXP/+7QZAfXUJ/Fp1tDxfYM84frCoS0SIX4q5mR3zP6EspNLuIA5nPClZDrGCtrC6m 9bxBum7j1qRTO8E1gnIN9tDZtkb4Po1YLttPWk4d1HUe/LpWGvw3YBzY2LN+1nCl9HdC OmRQ== X-Gm-Message-State: AOAM530KdTmjsGAD33RFotToncm3ForKLO8PVzqTUob3a/YSyMLesXL7 Yxl28J15qOpy7kNa4UNsPKu3hOCQ+/FP8A== X-Google-Smtp-Source: ABdhPJyCNCeteX3dehc7RywePX/10lUPqg+Q4AE8watHjp0eaQTbeW9A3geEfvmchRzttjQFqF7rXg== X-Received: by 2002:a5d:488a:: with SMTP id g10mr24502903wrq.653.1642521331081; Tue, 18 Jan 2022 07:55:31 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id f15sm1220522wrd.45.2022.01.18.07.55.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jan 2022 07:55:30 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , J Smith , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFz?= =?utf-8?b?b24=?= Subject: [PATCH v8 02/10] log tests: check if grep_config() is called by "log"-like cmds Date: Tue, 18 Jan 2022 16:55:14 +0100 Message-Id: X-Mailer: git-send-email 2.35.0.rc1.864.g57621b115b6 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Extend the tests added in my 9df46763ef1 (log: add exhaustive tests for pattern style options & config, 2017-05-20) to check not only whether "git log" handles "grep.patternType", but also "git show" etc. It's sufficient to check whether we match a "fixed" or a "basic" regex here to see if these codepaths correctly invoked grep_config(). We don't need to check the details of their regular expression matching as the "log" test does. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t4202-log.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/t/t4202-log.sh b/t/t4202-log.sh index 50495598619..e775b378e4b 100755 --- a/t/t4202-log.sh +++ b/t/t4202-log.sh @@ -449,6 +449,30 @@ test_expect_success !FAIL_PREREQS 'log with various grep.patternType configurati ) ' +for cmd in show whatchanged reflog format-patch +do + case "$cmd" in + format-patch) myarg="HEAD~.." ;; + *) myarg= ;; + esac + + test_expect_success "$cmd: understands grep.patternType, like 'log'" ' + git init "pattern-type-$cmd" && + ( + cd "pattern-type-$cmd" && + test_commit 1 file A && + test_commit "(1|2)" file B 2 && + + git -c grep.patternType=fixed $cmd --grep="..." $myarg >actual && + test_must_be_empty actual && + + git -c grep.patternType=basic $cmd --grep="..." $myarg >actual && + test_file_not_empty actual + ) + ' +done +test_done + test_expect_success 'log --author' ' cat >expect <<-\EOF && Author: A U Thor From patchwork Tue Jan 18 15:55:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12716664 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9AF32C433FE for ; Tue, 18 Jan 2022 15:55:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346074AbiARPzf (ORCPT ); Tue, 18 Jan 2022 10:55:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346079AbiARPze (ORCPT ); Tue, 18 Jan 2022 10:55:34 -0500 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A91D9C061574 for ; Tue, 18 Jan 2022 07:55:33 -0800 (PST) Received: by mail-wm1-x32c.google.com with SMTP id c2so23130466wml.1 for ; Tue, 18 Jan 2022 07:55:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=agf5irCqbwactz4W2Ijf8GjmALs7sGe7+n69YR7sr3k=; b=cikItxXFKyx8bU/PsAqoxaw+obGPhLn5spaZX5XSd30z1qQHy6dQGR6Zueh9ujKwDP Oy/fqlUxVZSffgInlrcpeYVIau+L010gJuSGZd6gTZeA4aRW7Qbm2xIsPdpUQKfWcoLM uzeCW2JAbFrApuKTGUO3GKx5tylSVfaWo+EquEnoMFfm29iQZJlTzx4XR95SXrz7z9BS 1IuSkMYz/7xiqvILbD0ZJ3lutXqxyU2zU0w7RKuRr3YedTTfVS1lrNGLA5ERmoIkS53m QztyfGWfVkgs3CQvh3C/9D0YFv3p5B5nFysuk2RVh8zU3XM27qf/VGwvpX5QR4HU4dHL qrjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=agf5irCqbwactz4W2Ijf8GjmALs7sGe7+n69YR7sr3k=; b=0DkamLF94g6UybpUeVJA/J53mhvYz5wj/+UeXSc6sjq37fB98gMeeEb6d3saBbbTGO dLEOHv2ejbLz1pp+yVNqLynZZxAaz/HW8ZTmdI62P5k8qN4A+VqJr7hrwdbD9+txUX1g hPGyS1BYK93AIgVp6i4eaF4u0yMx6+IocXugdn6wO7Ox4J8fm6lRHFJ2UMFd58xZlkQS RAjO42ZpHAZFqfpB2fiSLlb60ywaruCLyt6QnH0S9WgrAH/qAcrOaGR+MTLPosexxLqa 50GREBlo/GtErZvgQ4Oi79/ivi7UquCx4g77k6lVx5WF7K6uWujfM4zKKAYn2/Ojp2Vt bbtg== X-Gm-Message-State: AOAM53249AyyOiZleFJBtIKmn1ednID+cq+ENsirpnlpbf0mu2e1JaM2 nDa8Oaugup+5SI5DKxw9vEt/8h7Owyo/wQ== X-Google-Smtp-Source: ABdhPJwVaUeiHg9uoxX29h7J/jAiIRIYud1fCvBwULxoZ8KwbaXxLW5kn18MhedV8rjVSb6mGkb22Q== X-Received: by 2002:a7b:c931:: with SMTP id h17mr32939996wml.49.1642521332008; Tue, 18 Jan 2022 07:55:32 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id f15sm1220522wrd.45.2022.01.18.07.55.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jan 2022 07:55:31 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , J Smith , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFz?= =?utf-8?b?b24=?= Subject: [PATCH v8 03/10] grep tests: add missing "grep.patternType" config tests Date: Tue, 18 Jan 2022 16:55:15 +0100 Message-Id: X-Mailer: git-send-email 2.35.0.rc1.864.g57621b115b6 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Extend the grep tests to assert that setting "grep.patternType=extended" followed by "grep.patternType=default" will behave as if "--basic-regexp" was provided, and not as "--extended-regexp". In a subsequent commit we'll need to treat "grep.patternType=default" as a special-case, but let's make sure we ignore it if it's being set to "default" following an earlier non-"default" "grep.patternType" setting. Let's also test what happens when we have a sequence of "extended" followed by "default" and "fixed". In that case the "fixed" should prevail, as well as tests to check that a "grep.extendedRegexp=true" followed by a "grep.extendedRegexp=false" behaves as though "grep.extendedRegexp" wasn't provided. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- t/t7810-grep.sh | 68 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh index 424c31c3287..34d8f69c1de 100755 --- a/t/t7810-grep.sh +++ b/t/t7810-grep.sh @@ -451,6 +451,65 @@ do test_cmp expected actual ' + test_expect_success "grep $L with grep.extendedRegexp is last-one-wins" ' + echo "${HC}ab:a+bc" >expected && + git \ + -c grep.extendedRegexp=true \ + -c grep.patternType=basic \ + -c grep.extendedRegexp=false \ + grep "a+b*c" $H ab >actual && + test_cmp expected actual + ' + + test_expect_success "grep $L with grep.extendedRegexp is last-one-wins & defers to grep.patternType" ' + echo "${HC}ab:abc" >expected && + git \ + -c grep.extendedRegexp=true \ + -c grep.patternType=extended \ + -c grep.extendedRegexp=false \ + grep "a+b*c" $H ab >actual && + test_cmp expected actual + ' + + test_expect_success "grep $L with grep.extendedRegexp and grep.patternType are both last-one-wins independently (BRE)" ' + echo "${HC}ab:abc" >expected && + git \ + -c grep.patternType=fixed \ + -c grep.extendedRegexp=true \ + -c grep.patternType=default \ + grep "a+b*c" $H ab >actual && + test_cmp expected actual + ' + + test_expect_success "grep $L with grep.extendedRegexp and grep.patternType are both last-one-wins independently (ERE)" ' + echo "${HC}ab:a+bc" >expected && + git \ + -c grep.patternType=default \ + -c grep.extendedRegexp=true \ + -c grep.patternType=basic \ + grep "a+b*c" $H ab >actual && + test_cmp expected actual + ' + + test_expect_success "grep $L with grep.patternType=extended and grep.patternType=default" ' + echo "${HC}ab:a+bc" >expected && + git \ + -c grep.patternType=extended \ + -c grep.patternType=default \ + grep "a+b*c" $H ab >actual && + test_cmp expected actual + ' + + test_expect_success "grep $L with grep.patternType=[extended -> default -> fixed]" ' + echo "${HC}ab:a+b*c" >expected && + git \ + -c grep.patternType=extended \ + -c grep.patternType=default \ + -c grep.patternType=fixed \ + grep "a+b*c" $H ab >actual && + test_cmp expected actual + ' + test_expect_success "grep $L with grep.patternType=extended and grep.extendedRegexp=false" ' echo "${HC}ab:abc" >expected && git \ @@ -478,6 +537,15 @@ do test_cmp expected actual ' + test_expect_success "grep $L with grep.extendedRegexp=false and grep.patternType=default" ' + echo "${HC}ab:abc" >expected && + git \ + -c grep.extendedRegexp=false \ + -c grep.patternType=extended \ + grep "a+b*c" $H ab >actual && + test_cmp expected actual + ' + test_expect_success "grep $L with grep.extendedRegexp=true and grep.patternType=basic" ' echo "${HC}ab:a+bc" >expected && git \ From patchwork Tue Jan 18 15:55:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12716665 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74C2BC433EF for ; Tue, 18 Jan 2022 15:55:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346094AbiARPzh (ORCPT ); Tue, 18 Jan 2022 10:55:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346101AbiARPzf (ORCPT ); Tue, 18 Jan 2022 10:55:35 -0500 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23CE2C061574 for ; Tue, 18 Jan 2022 07:55:35 -0800 (PST) Received: by mail-wm1-x32b.google.com with SMTP id j5-20020a05600c1c0500b0034d2e956aadso6056239wms.4 for ; Tue, 18 Jan 2022 07:55:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dorSffzVSmU8eAU5RLqqGN+qZBqwQZ3Kswl5NT5KBmk=; b=WVXNs2QmeOryWOH2Xbtu740/ehGh41coRtRrQhL35HNnvmwiOUCMr8Mwh0d1Intsoz QZNgn2oXx0fvV6wtAJ8jrity8bTIsgRqQaKbdTyUYFxjTR9CKGId9OUo+SgpOO/JjeD+ lHZi0DHNXuo5XmCJWzzGfBPwfmRB88JLhrPCLlLdnbOGKc1/5ZqGyq1tiBhE3uMVehEf IFlqlQpuEwOQ11OJZUD59kzcBjdVS4/rqah2fmJZO1upYj4WhzugNTambJjeeiu/cgWp Pm8II37PYdVRSsDd9pEl0B2JN8u1NJOF29F90Oz41XcxnBy82L6L+PjJQ3Y11XqnDupp +N5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dorSffzVSmU8eAU5RLqqGN+qZBqwQZ3Kswl5NT5KBmk=; b=hyDDeu0cqwhZsU9To6elPB6FHJwdgDysX2L7x/6jDR+8BB88Xh19b7xJxzuCLZl+a6 Qfdd2zDaHRpeGubv1vmMIw8/vgk9zQY8jgSUMLI10WO6dOavqsMvJYI2pw6aiva2Tz/K IZHQoMFmn78oUrhRgmRdHvf6q4qUSXCyTgn2ER3f099Op8o8xnxtwawTNX66IdP96P7f MEnHj3Wxcji7FNJ3x+DPiqJxfl6Sbsv+Ie9/YBWv4ASoVYX/bp7m5KMC+t6l33RwX4My RvAbeT0EVRQvj6OD8fvmsyBPiy1F83jKAS3vldjdFVVEuvGWx6gdiTxdAvUQoZTHvN25 qqRQ== X-Gm-Message-State: AOAM531hi8XWo4nlgOoD2U2sa3fy6h/oBw3R0bpG18UGpFY+51L/Xe3s 1HpFQ3qfUKLJuGdARejz/ILzorZRY2c1bA== X-Google-Smtp-Source: ABdhPJxkE0OF48I0ma4BvAcBSYVc71omMX8yfe7Gc/mTjfF3ut++HKcWB+nXB3fet9l/0r3zJIfLUA== X-Received: by 2002:adf:bc06:: with SMTP id s6mr3488130wrg.612.1642521333290; Tue, 18 Jan 2022 07:55:33 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id f15sm1220522wrd.45.2022.01.18.07.55.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jan 2022 07:55:32 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , J Smith , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFz?= =?utf-8?b?b24=?= Subject: [PATCH v8 04/10] built-ins: trust the "prefix" from run_builtin() Date: Tue, 18 Jan 2022 16:55:16 +0100 Message-Id: X-Mailer: git-send-email 2.35.0.rc1.864.g57621b115b6 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change code in "builtin/grep.c" and "builtin/ls-tree.c" to trust the "prefix" passed from "run_builtin()". The "prefix" we get from setup.c is either going to be NULL or a string of length >0, never "". So we can drop the "prefix && *prefix" checks added for "builtin/grep.c" in 0d042fecf2f (git-grep: show pathnames relative to the current directory, 2006-08-11), and for "builtin/ls-tree.c" in a69dd585fca (ls-tree: chomp leading directories when run from a subdirectory, 2005-12-23). As seen in code in revision.c that was added in cd676a51367 (diff --relative: output paths as relative to the current subdirectory, 2008-02-12) we already have existing code that does away with this assertion. This makes it easier to reason about a subsequent change to the "prefix_length" code in grep.c in a subsequent commit, and since we're going to the trouble of doing that let's leave behind an assert() to promise this to any future callers. For "builtin/grep.c" it would be painful to pass the "prefix" down the callchain of: cmd_grep -> grep_tree -> grep_submodule -> grep_cache -> grep_oid -> grep_source_name So for the code that needs it in grep_source_name() let's add a "grep_prefix" variable similar to the existing "ls_tree_prefix". While at it let's move the code in cmd_ls_tree() around so that we assign to the "ls_tree_prefix" right after declaring the variables, and stop assigning to "prefix". We only subsequently used that variable later in the function after clobbering it. Let's just use our own "grep_prefix" instead. Let's also add an assert() in git.c, so that we'll make this promise about the "prefix" to any current and future callers, as well as to any readers of the code. Code history: * The strlen() in "grep.c" hasn't been used since 493b7a08d80 (grep: accept relative paths outside current working directory, 2009-09-05). When that code was added in 0d042fecf2f (git-grep: show pathnames relative to the current directory, 2006-08-11) we used the length. But since 493b7a08d80 we haven't used it for anything except a boolean check that we could have done on the "prefix" member itself. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/grep.c | 13 ++++++++----- builtin/ls-tree.c | 2 +- git.c | 1 + grep.c | 4 +--- grep.h | 4 +--- revision.c | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/builtin/grep.c b/builtin/grep.c index 9e34a820ad4..d85cbabea67 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -26,6 +26,8 @@ #include "object-store.h" #include "packfile.h" +static const char *grep_prefix; + static char const * const grep_usage[] = { N_("git grep [] [-e] [...] [[--] ...]"), NULL @@ -315,11 +317,11 @@ static void grep_source_name(struct grep_opt *opt, const char *filename, strbuf_reset(out); if (opt->null_following_name) { - if (opt->relative && opt->prefix_length) { + if (opt->relative && grep_prefix) { struct strbuf rel_buf = STRBUF_INIT; const char *rel_name = relative_path(filename + tree_name_len, - opt->prefix, &rel_buf); + grep_prefix, &rel_buf); if (tree_name_len) strbuf_add(out, filename, tree_name_len); @@ -332,8 +334,8 @@ static void grep_source_name(struct grep_opt *opt, const char *filename, return; } - if (opt->relative && opt->prefix_length) - quote_path(filename + tree_name_len, opt->prefix, out, 0); + if (opt->relative && grep_prefix) + quote_path(filename + tree_name_len, grep_prefix, out, 0); else quote_c_style(filename + tree_name_len, out, NULL, 0); @@ -962,9 +964,10 @@ int cmd_grep(int argc, const char **argv, const char *prefix) PARSE_OPT_NOCOMPLETE), OPT_END() }; + grep_prefix = prefix; git_config(grep_cmd_config, NULL); - grep_init(&opt, the_repository, prefix); + grep_init(&opt, the_repository); /* * If there is no -- then the paths must exist in the working diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c index 3a442631c71..6cb554cbb0a 100644 --- a/builtin/ls-tree.c +++ b/builtin/ls-tree.c @@ -150,7 +150,7 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix) git_config(git_default_config, NULL); ls_tree_prefix = prefix; - if (prefix && *prefix) + if (prefix) chomp_prefix = strlen(prefix); argc = parse_options(argc, argv, prefix, ls_tree_options, diff --git a/git.c b/git.c index edda922ce6d..9d257e092da 100644 --- a/git.c +++ b/git.c @@ -436,6 +436,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv) } else { prefix = NULL; } + assert(!prefix || *prefix); precompose_argv_prefix(argc, argv, NULL); if (use_pager == -1 && run_setup && !(p->option & DELAY_PAGER_CONFIG)) diff --git a/grep.c b/grep.c index 7bb0360869a..8421dc55486 100644 --- a/grep.c +++ b/grep.c @@ -139,13 +139,11 @@ int grep_config(const char *var, const char *value, void *cb) * default values from the template we read the configuration * information in an earlier call to git_config(grep_config). */ -void grep_init(struct grep_opt *opt, struct repository *repo, const char *prefix) +void grep_init(struct grep_opt *opt, struct repository *repo) { *opt = grep_defaults; opt->repo = repo; - opt->prefix = prefix; - opt->prefix_length = (prefix && *prefix) ? strlen(prefix) : 0; opt->pattern_tail = &opt->pattern_list; opt->header_tail = &opt->header_list; } diff --git a/grep.h b/grep.h index 400172676a1..23a2a41d2c4 100644 --- a/grep.h +++ b/grep.h @@ -134,8 +134,6 @@ struct grep_opt { */ struct repository *repo; - const char *prefix; - int prefix_length; int linenum; int columnnum; int invert; @@ -182,7 +180,7 @@ struct grep_opt { }; int grep_config(const char *var, const char *value, void *); -void grep_init(struct grep_opt *, struct repository *repo, const char *prefix); +void grep_init(struct grep_opt *, struct repository *repo); void grep_commit_pattern_type(enum grep_pattern_type, struct grep_opt *opt); void append_grep_pat(struct grep_opt *opt, const char *pat, size_t patlen, const char *origin, int no, enum grep_pat_token t); diff --git a/revision.c b/revision.c index ad4286fbdde..d6e0e2b23b5 100644 --- a/revision.c +++ b/revision.c @@ -1838,7 +1838,7 @@ void repo_init_revisions(struct repository *r, revs->commit_format = CMIT_FMT_DEFAULT; revs->expand_tabs_in_log_default = 8; - grep_init(&revs->grep_filter, revs->repo, prefix); + grep_init(&revs->grep_filter, revs->repo); revs->grep_filter.status_only = 1; repo_diff_setup(revs->repo, &revs->diffopt); From patchwork Tue Jan 18 15:55:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12716666 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1384DC433F5 for ; Tue, 18 Jan 2022 15:55:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346102AbiARPzi (ORCPT ); Tue, 18 Jan 2022 10:55:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346079AbiARPzg (ORCPT ); Tue, 18 Jan 2022 10:55:36 -0500 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6145C06173F for ; Tue, 18 Jan 2022 07:55:35 -0800 (PST) Received: by mail-wm1-x332.google.com with SMTP id d18-20020a05600c251200b0034974323cfaso6880768wma.4 for ; Tue, 18 Jan 2022 07:55:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9Ft9tXQgPoU/SG9CvZK2TUDKGHqxEj46b1nQVDCP1bk=; b=TqcRY5wBBcup8mfHoRn27KNCiMwwy50VRUb58jfaxWBm01sqScNeoQtzOqMzT6DdVE T2D90LBmLGfM0mmGt0aMokeT2rHuR6Cptgou3nINDQTNYMna7SPQImHoPPR34N3KDkZ3 7O5QHknfmmhJnh1LmeQB2FrCGf67vfT7AIUqlEIPIUmgZdQ4OR4cLlgy4lZjiWce5csV 9GbTqrQ8ZXBP96eBEGwSGbVzvh8ia0Ge+4wRzgil4K4vc+KAgUPpQqVJWsyWugzuWn6F CZb130fgKrAr5LU2482VxgKtu1gHnzRsZh5zwdbidn/91wUPEbYJrQ9sAHlktEawbHix dwaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9Ft9tXQgPoU/SG9CvZK2TUDKGHqxEj46b1nQVDCP1bk=; b=42TBLaaOm1BzTW60+cbtHVKF1AWltSdFOsdiS/CxSaOp1TM/qMo+9G978j9scydpx8 QVK5r5JWnElGW1GlEn9gOnOBlBnHAchAMypd61zoa6+DkrqTPm5u4HWa+Fl10FLCJHGF p35kLkVv+yrG/BLtgi/zDgOt0CkKknvVi06siWLeaanX2owiYBOTVrV6xShhTZF5576f uK4EiUpItgRU0nylYvx58sBIifM5+nBpTVzXVHeqWpzWLxjlR/MulY8Qqf+4/m85VD8x OQVURaxJ9RHAE21Zz1N224nefzYjFjlgowgr0zuxO328RXwmCnnaNgtEOCWef8qSKs0D hAug== X-Gm-Message-State: AOAM530UmpJHvcvysrgyzGmgu4xcz6fOFHbstfmdrspblTLwT0Gw1j/U AcFODcPZKcuJtae1R43Xk1A2uflQ3bDk0g== X-Google-Smtp-Source: ABdhPJxGuZrpYXVdTzRke1d7Wib0KVRT3h+7QRT1Aswt9CmC24210/UgGnBPkxnX1LC3FX2D0W+Fag== X-Received: by 2002:adf:df84:: with SMTP id z4mr4165497wrl.519.1642521334152; Tue, 18 Jan 2022 07:55:34 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id f15sm1220522wrd.45.2022.01.18.07.55.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jan 2022 07:55:33 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , J Smith , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFz?= =?utf-8?b?b24=?= Subject: [PATCH v8 05/10] grep.c: don't pass along NULL callback value Date: Tue, 18 Jan 2022 16:55:17 +0100 Message-Id: X-Mailer: git-send-email 2.35.0.rc1.864.g57621b115b6 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change grep_cmd_config() to stop passing around the always-NULL "cb" value. When this code was added in 7e8f59d577e (grep: color patterns in output, 2009-03-07) it was non-NULL, but when that changed in 15fabd1bbd4 (builtin/grep.c: make configuration callback more reusable, 2012-10-09) this code was left behind. In a subsequent change I'll start using the "cb" value, this will make it clear which functions we call need it, and which don't. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/grep.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builtin/grep.c b/builtin/grep.c index d85cbabea67..5ec4cecae45 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -285,8 +285,8 @@ static int wait_all(void) static int grep_cmd_config(const char *var, const char *value, void *cb) { - int st = grep_config(var, value, cb); - if (git_color_default_config(var, value, cb) < 0) + int st = grep_config(var, value, NULL); + if (git_color_default_config(var, value, NULL) < 0) st = -1; if (!strcmp(var, "grep.threads")) { From patchwork Tue Jan 18 15:55:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12716667 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E8B88C433EF for ; Tue, 18 Jan 2022 15:55:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346121AbiARPzk (ORCPT ); Tue, 18 Jan 2022 10:55:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346106AbiARPzh (ORCPT ); Tue, 18 Jan 2022 10:55:37 -0500 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98D7AC061401 for ; Tue, 18 Jan 2022 07:55:36 -0800 (PST) Received: by mail-wm1-x32b.google.com with SMTP id p18so28661532wmg.4 for ; Tue, 18 Jan 2022 07:55:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2HyVbJw600ZIthCV9t0k+HNG8dPz/i6GqIAVhVLwUW0=; b=SiJMJZpUuLR/+SJFwKDHi8hGHGRvOHDRM2ttydEt0K7Ttxyr0dGmIqfE+VO+B4errr 6bewmaFXLR5l6V0EO6WF+SdbX43BaLwLDyXIQbJ5flr0GCMJVfqK7MlPXCjn886UlV9u HQtwmzLbKVGdj83EMdG5CUcT8aL5qTCBS7idtdZ8YpL+t8MznOatFIGxFMbFwFdGOwre bQaEybApyxxhVdFZ1MBz9tHIg1kF+ScS4OVRUwSyCZ/HDtiaYs/Kaq0RTUmRS4zRtpi7 K7DGWzl8B/yJ7TYogPFBsr2R2EZlAXc7Fz6vkwVmg6+CbG4oSaDP9yY4xEXniY1VMnPD +qoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2HyVbJw600ZIthCV9t0k+HNG8dPz/i6GqIAVhVLwUW0=; b=B8K21azCN1DvohpTrD1+C3s6lQtnQnq2yJLkQ2T7Oku2OeJFgY1/A8AJ90c6DH4qcf xjcTxmFnpOxsheC6EPmIjlz4WsDOjnQm/yq6EGgscEmtC1GhO5ZjSqt4YyRQStNzWTqf mUga2G3BrOH7F639uRSypwWhAcdbj9SgK13wx6GnQZgCHc3rVqq5tMaY1FaHJvfb8sGe sXg5o+XijaQRIq3eOux/aOml1uqXptHbYMiiRC5Vv51fArOTY1GPX551R07clX8//9kR S55CJENKZfSbBln/znjP8l4OOzm9HnNIkVultFP9xe8IVfchJSTthErUlUqsWMflL6bw TEHg== X-Gm-Message-State: AOAM530h35CuYlMdrkEnDpm8lTfyu4BIoNTxS0Bufe7GMwpgiRkIHBNM lLKc7lJb1tYsb1qucP6WRR50LxCj9ce7gg== X-Google-Smtp-Source: ABdhPJzX4/zlvCnnB/6kJYs1/kCvT407U8yvV38vCQsA8z2AWHCyJ5XMzVL4uwKXa8nCCgnqaPbvEg== X-Received: by 2002:a5d:4ad2:: with SMTP id y18mr24890854wrs.141.1642521335005; Tue, 18 Jan 2022 07:55:35 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id f15sm1220522wrd.45.2022.01.18.07.55.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jan 2022 07:55:34 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , J Smith , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFz?= =?utf-8?b?b24=?= Subject: [PATCH v8 06/10] grep API: call grep_config() after grep_init() Date: Tue, 18 Jan 2022 16:55:18 +0100 Message-Id: X-Mailer: git-send-email 2.35.0.rc1.864.g57621b115b6 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The grep_init() function used the odd pattern of initializing the passed-in "struct grep_opt" with a statically defined "grep_defaults" struct, which would be modified in-place when we invoked grep_config(). So we effectively (b) initialized config, (a) then defaults, (c) followed by user options. Usually those are ordered as "a", "b" and "c" instead. As the comments being removed here show the previous behavior needed to be carefully explained as we'd potentially share the populated configuration among different instances of grep_init(). In practice we didn't do that, but now that it can't be a concern anymore let's remove those comments. This does not change the behavior of any of the configuration variables or options. That would have been the case if we didn't move around the grep_config() call in "builtin/log.c". But now that we call "grep_config" after "git_log_config" and "git_format_config" we'll need to pass in the already initialized "struct grep_opt *". See 6ba9bb76e02 (grep: copy struct in one fell swoop, 2020-11-29) and 7687a0541e0 (grep: move the configuration parsing logic to grep.[ch], 2012-10-09) for the commits that added the comments. The memcpy() pattern here will be optimized away and follows the convention of other *_init() functions. See 5726a6b4012 (*.c *_init(): define in terms of corresponding *_INIT macro, 2021-07-01). Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/grep.c | 4 ++-- builtin/log.c | 13 +++++++++++-- grep.c | 39 +++------------------------------------ grep.h | 21 +++++++++++++++++++++ 4 files changed, 37 insertions(+), 40 deletions(-) diff --git a/builtin/grep.c b/builtin/grep.c index 5ec4cecae45..0ea124321b6 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -285,7 +285,7 @@ static int wait_all(void) static int grep_cmd_config(const char *var, const char *value, void *cb) { - int st = grep_config(var, value, NULL); + int st = grep_config(var, value, cb); if (git_color_default_config(var, value, NULL) < 0) st = -1; @@ -966,8 +966,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix) }; grep_prefix = prefix; - git_config(grep_cmd_config, NULL); grep_init(&opt, the_repository); + git_config(grep_cmd_config, &opt); /* * If there is no -- then the paths must exist in the working diff --git a/builtin/log.c b/builtin/log.c index 4b493408cc5..06283b37e7a 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -520,8 +520,6 @@ static int git_log_config(const char *var, const char *value, void *cb) return 0; } - if (grep_config(var, value, cb) < 0) - return -1; if (git_gpg_config(var, value, cb) < 0) return -1; return git_diff_ui_config(var, value, cb); @@ -536,6 +534,8 @@ int cmd_whatchanged(int argc, const char **argv, const char *prefix) git_config(git_log_config, NULL); repo_init_revisions(the_repository, &rev, prefix); + git_config(grep_config, &rev.grep_filter); + rev.diff = 1; rev.simplify_history = 0; memset(&opt, 0, sizeof(opt)); @@ -650,6 +650,8 @@ int cmd_show(int argc, const char **argv, const char *prefix) memset(&match_all, 0, sizeof(match_all)); repo_init_revisions(the_repository, &rev, prefix); + git_config(grep_config, &rev.grep_filter); + rev.diff = 1; rev.always_show_header = 1; rev.no_walk = 1; @@ -733,6 +735,8 @@ int cmd_log_reflog(int argc, const char **argv, const char *prefix) repo_init_revisions(the_repository, &rev, prefix); init_reflog_walk(&rev.reflog_info); + git_config(grep_config, &rev.grep_filter); + rev.verbose_header = 1; memset(&opt, 0, sizeof(opt)); opt.def = "HEAD"; @@ -766,6 +770,8 @@ int cmd_log(int argc, const char **argv, const char *prefix) git_config(git_log_config, NULL); repo_init_revisions(the_repository, &rev, prefix); + git_config(grep_config, &rev.grep_filter); + rev.always_show_header = 1; memset(&opt, 0, sizeof(opt)); opt.def = "HEAD"; @@ -1848,10 +1854,13 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) extra_hdr.strdup_strings = 1; extra_to.strdup_strings = 1; extra_cc.strdup_strings = 1; + init_log_defaults(); init_display_notes(¬es_opt); git_config(git_format_config, NULL); repo_init_revisions(the_repository, &rev, prefix); + git_config(grep_config, &rev.grep_filter); + rev.show_notes = show_notes; memcpy(&rev.notes_opt, ¬es_opt, sizeof(notes_opt)); rev.commit_format = CMIT_FMT_EMAIL; diff --git a/grep.c b/grep.c index 8421dc55486..35e12e43c09 100644 --- a/grep.c +++ b/grep.c @@ -19,27 +19,6 @@ static void std_output(struct grep_opt *opt, const void *buf, size_t size) fwrite(buf, size, 1, stdout); } -static struct grep_opt grep_defaults = { - .relative = 1, - .pathname = 1, - .max_depth = -1, - .pattern_type_option = GREP_PATTERN_TYPE_UNSPECIFIED, - .colors = { - [GREP_COLOR_CONTEXT] = "", - [GREP_COLOR_FILENAME] = GIT_COLOR_MAGENTA, - [GREP_COLOR_FUNCTION] = "", - [GREP_COLOR_LINENO] = GIT_COLOR_GREEN, - [GREP_COLOR_COLUMNNO] = GIT_COLOR_GREEN, - [GREP_COLOR_MATCH_CONTEXT] = GIT_COLOR_BOLD_RED, - [GREP_COLOR_MATCH_SELECTED] = GIT_COLOR_BOLD_RED, - [GREP_COLOR_SELECTED] = "", - [GREP_COLOR_SEP] = GIT_COLOR_CYAN, - }, - .only_matching = 0, - .color = -1, - .output = std_output, -}; - static const char *color_grep_slots[] = { [GREP_COLOR_CONTEXT] = "context", [GREP_COLOR_FILENAME] = "filename", @@ -75,20 +54,12 @@ define_list_config_array_extra(color_grep_slots, {"match"}); */ int grep_config(const char *var, const char *value, void *cb) { - struct grep_opt *opt = &grep_defaults; + struct grep_opt *opt = cb; const char *slot; if (userdiff_config(var, value) < 0) return -1; - /* - * The instance of grep_opt that we set up here is copied by - * grep_init() to be used by each individual invocation. - * When populating a new field of this structure here, be - * sure to think about ownership -- e.g., you might need to - * override the shallow copy in grep_init() with a deep copy. - */ - if (!strcmp(var, "grep.extendedregexp")) { opt->extended_regexp_option = git_config_bool(var, value); return 0; @@ -134,14 +105,10 @@ int grep_config(const char *var, const char *value, void *cb) return 0; } -/* - * Initialize one instance of grep_opt and copy the - * default values from the template we read the configuration - * information in an earlier call to git_config(grep_config). - */ void grep_init(struct grep_opt *opt, struct repository *repo) { - *opt = grep_defaults; + struct grep_opt blank = GREP_OPT_INIT; + memcpy(opt, &blank, sizeof(*opt)); opt->repo = repo; opt->pattern_tail = &opt->pattern_list; diff --git a/grep.h b/grep.h index 23a2a41d2c4..3112d1c2a38 100644 --- a/grep.h +++ b/grep.h @@ -179,6 +179,27 @@ struct grep_opt { void *output_priv; }; +#define GREP_OPT_INIT { \ + .relative = 1, \ + .pathname = 1, \ + .max_depth = -1, \ + .pattern_type_option = GREP_PATTERN_TYPE_UNSPECIFIED, \ + .colors = { \ + [GREP_COLOR_CONTEXT] = "", \ + [GREP_COLOR_FILENAME] = GIT_COLOR_MAGENTA, \ + [GREP_COLOR_FUNCTION] = "", \ + [GREP_COLOR_LINENO] = GIT_COLOR_GREEN, \ + [GREP_COLOR_COLUMNNO] = GIT_COLOR_GREEN, \ + [GREP_COLOR_MATCH_CONTEXT] = GIT_COLOR_BOLD_RED, \ + [GREP_COLOR_MATCH_SELECTED] = GIT_COLOR_BOLD_RED, \ + [GREP_COLOR_SELECTED] = "", \ + [GREP_COLOR_SEP] = GIT_COLOR_CYAN, \ + }, \ + .only_matching = 0, \ + .color = -1, \ + .output = std_output, \ +} + int grep_config(const char *var, const char *value, void *); void grep_init(struct grep_opt *, struct repository *repo); void grep_commit_pattern_type(enum grep_pattern_type, struct grep_opt *opt); From patchwork Tue Jan 18 15:55:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12716668 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA7C8C433F5 for ; Tue, 18 Jan 2022 15:55:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346140AbiARPzl (ORCPT ); Tue, 18 Jan 2022 10:55:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346116AbiARPzh (ORCPT ); Tue, 18 Jan 2022 10:55:37 -0500 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7162CC06173E for ; Tue, 18 Jan 2022 07:55:37 -0800 (PST) Received: by mail-wm1-x32f.google.com with SMTP id v123so28680446wme.2 for ; Tue, 18 Jan 2022 07:55:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=iYF24mQ3Zuf4xjpcAzIMtBSOaXVlviXkRAbi/lKmP6Q=; b=S5xkfD5v/C92QWj0X1jk977t5BQLmR+XI1CCEx6GUfPc5QIDAQQi7uchH8npTXz3vi 2/iz0di3JIhfe6/r/8fGjRjEi/gjgYEZd0zA+EeRNjnMGniXc8DuJzxz9+KvUKbDc0Y0 qGKSC1BbnJiw7FVij7wi6awUnV5zbZfFjLMqjuo6w/IF5gLQ5W5pdVWj40SAHY7TKRzv /tRfkroDbrTzwTDaaWLHYwRtz2i/3nzyaOWDB8LhdwIHHm98999TKErlCVTm3eytGGRl iGomUjDRRSUjpvh/WwZzSt5Zvwwuolc4v6MqFm6CKTcwfbkgf5Yqo++D5nTBMe339urE LVRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=iYF24mQ3Zuf4xjpcAzIMtBSOaXVlviXkRAbi/lKmP6Q=; b=y4usdBHJYx2EP1QEj0gKcovKaDCYXLmg2EpgL1xSDhDj9tCTusiyEShTYIO2tg5uMI eVFvhJlS9WnuK3rtLHU4mNtWRKiWoEU8KHMe2JP5JFeB4z8an9ukBGC3kL2tsbFp4/qK DN/rSdeAgi6lxZyRpTCUnyZ+t4akEf6HisXoqYQTtCYi4gznSlGkNa3Wc7N3BZYZpqk+ sK5U7pv1B1tgsluHxX5OuVOV2/3ZT9qgPhVSygQjV5JJpNAdmRfiUaNmqL9eAxgnkHGq QEDMbdhUw8QtkAcPF3nrJTFdCgaJl6/UAFKhvvV3Bz3rpbf9ZXkGw5OWm8O32bCV/2OQ 97Ig== X-Gm-Message-State: AOAM532Aie5HeFJ9aINOyfbJonLmNlGv0LGy3D0f1d+oeYyZRevhV+sa Ag557bI659H7vSw/Zy3vH0JXXPEkQlSCEQ== X-Google-Smtp-Source: ABdhPJxDl7WaTk8ywmazI8jNRlwYTB2FBkfxOcv+5xpt3ZBaQbRUNQfxYET7YdT4Yo9Tdv0N8MqN/w== X-Received: by 2002:a5d:6848:: with SMTP id o8mr25222956wrw.2.1642521335886; Tue, 18 Jan 2022 07:55:35 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id f15sm1220522wrd.45.2022.01.18.07.55.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jan 2022 07:55:35 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , J Smith , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFz?= =?utf-8?b?b24=?= Subject: [PATCH v8 07/10] grep.h: make "grep_opt.pattern_type_option" use its enum Date: Tue, 18 Jan 2022 16:55:19 +0100 Message-Id: X-Mailer: git-send-email 2.35.0.rc1.864.g57621b115b6 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change the "pattern_type_option" member of "struct grep_opt" to use the enum type we use for it. Signed-off-by: Ævar Arnfjörð Bjarmason --- grep.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grep.h b/grep.h index 3112d1c2a38..89a2ce51130 100644 --- a/grep.h +++ b/grep.h @@ -164,7 +164,7 @@ struct grep_opt { int funcname; int funcbody; int extended_regexp_option; - int pattern_type_option; + enum grep_pattern_type pattern_type_option; int ignore_locale; char colors[NR_GREP_COLORS][COLOR_MAXLEN]; unsigned pre_context; From patchwork Tue Jan 18 15:55:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12716669 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A695C433F5 for ; Tue, 18 Jan 2022 15:55:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242594AbiARPzo (ORCPT ); Tue, 18 Jan 2022 10:55:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346079AbiARPzi (ORCPT ); Tue, 18 Jan 2022 10:55:38 -0500 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F805C06161C for ; Tue, 18 Jan 2022 07:55:38 -0800 (PST) Received: by mail-wm1-x330.google.com with SMTP id w26so28682725wmi.0 for ; Tue, 18 Jan 2022 07:55:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=44E2QQjApQiFIbq9QhTLYaN8aThUFeOEerdUja7PAtI=; b=WKygFcZNKUMaEuDSRW50UnK05Zy3apw7B57nq+RMhVznZ6M/NHcKPF1mtCe+QFzFg9 hoRDfVI6DiDJfnbtU4hRu+bmwfO5S90MoBC7YHbZqoDWhWprDefa6B2CA/lGWOTh3cIC 0QiORdr+jUDOgKzOQgRBzmmYkfOSNCaolpy23h5jCDuyuiGfzSIfDXotp4vcSgbY4Du2 /KUHEKgEn+hDS4cOGEG1WEc1186XnoTiUcVWTCaU+S/skHHJLyyWLJwHQlD2vjeXOYlI iCD3ybV1oNdvP1fp3JUK59X3bvAEm1IT550gPkVgIDyABzks+RkC6+0TJtcgh9/0y8tc Xabw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=44E2QQjApQiFIbq9QhTLYaN8aThUFeOEerdUja7PAtI=; b=7Dk4RHsw2LxkK3t6gW0Q1SBOPH4DRm1xMJ7mGJFoZ8YTIUIf9bbBobUOZj64hPRihW MEOPw5Yv6xe2hPLvSSAg15JVv58MtKcZbOGRd0BpQuJGqI9CTymBA9cSrcbupi02ZnVE KOux5WnsPBF9qqFj6JhHRiChzhtCj3AF47C4OXfaq3pHMKHiBnqobQzh4fK6WU1jRXdR gUOnDQvUjseO67FsQZ7Mv7CRxDB46dZXQFbX3AvrctVJVV3pZNSU/vuXx3oXCWECmGt9 gZ2BkHC/o4ewM2wFmKNa0lH7DM1V+EMYbc9uvEH7J4K0xKsozWDjPqHgHHHLQfCdRFEX ngDA== X-Gm-Message-State: AOAM531H0gKjzhy0v0q1PWZszJM1wufGmMVmnWEJm4lU/Snd6H3oxyKO rzuHRKjm9oSGtCL8xutfPCjp7V371NjRiA== X-Google-Smtp-Source: ABdhPJxDMgA0UAbER/q+Y+BIUkrgEBfdXTYpXSBUrO0nZGOPT/aTCSDxsKlGwC3xuT8wwIy9sxj4BA== X-Received: by 2002:a05:6000:1c0c:: with SMTP id ba12mr22310337wrb.285.1642521336774; Tue, 18 Jan 2022 07:55:36 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id f15sm1220522wrd.45.2022.01.18.07.55.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jan 2022 07:55:36 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , J Smith , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFz?= =?utf-8?b?b24=?= Subject: [PATCH v8 08/10] grep.c: do "if (bool && memchr())" not "if (memchr() && bool)" Date: Tue, 18 Jan 2022 16:55:20 +0100 Message-Id: X-Mailer: git-send-email 2.35.0.rc1.864.g57621b115b6 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change code in compile_regexp() to check the cheaper boolean "!opt->pcre2" condition before the "memchr()" search. This doesn't noticeably optimize anything, but makes the code more obvious and conventional. The line wrapping being added here also makes a subsequent commit smaller. Signed-off-by: Ævar Arnfjörð Bjarmason --- grep.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/grep.c b/grep.c index 35e12e43c09..60228a95a4f 100644 --- a/grep.c +++ b/grep.c @@ -492,7 +492,8 @@ static void compile_regexp(struct grep_pat *p, struct grep_opt *opt) p->ignore_case = opt->ignore_case; p->fixed = opt->fixed; - if (memchr(p->pattern, 0, p->patternlen) && !opt->pcre2) + if (!opt->pcre2 && + memchr(p->pattern, 0, p->patternlen)) die(_("given pattern contains NULL byte (via -f ). This is only supported with -P under PCRE v2")); p->is_fixed = is_fixed(p->pattern, p->patternlen); From patchwork Tue Jan 18 15:55:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12716671 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 390A2C433FE for ; Tue, 18 Jan 2022 15:55:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346159AbiARPzr (ORCPT ); Tue, 18 Jan 2022 10:55:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346152AbiARPzm (ORCPT ); Tue, 18 Jan 2022 10:55:42 -0500 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69DEAC06173E for ; Tue, 18 Jan 2022 07:55:39 -0800 (PST) Received: by mail-wm1-x329.google.com with SMTP id l12-20020a7bc34c000000b003467c58cbdfso6938116wmj.2 for ; Tue, 18 Jan 2022 07:55:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fCZPOrkHqLyNI93iHC3spYA3L+KtLSTyfugjQrFwGao=; b=K0jOSl/TLN4nsPGMRkHrbXao2clFCP718HXavYocqFxI3zTJsk4j6Q2nTBw+TlXECK Njv3Pi0VztcSqY7bcD9cF+YVeoXe2matqDTIRunQlkWbFZeFvqLkBayZJGBscgp1Xmvb 8IP9Pjej0rNbKM0tvoD89oOIcrJzH4zekGF5GSAM3sobCP4hpkWsiuUrsiCRXG/n49T/ vXGzqUGzR4CYOpPa2lawkgvDLGecsBynbbo8PVPlZWdljsnLv50xC3KjFT7Cgg3BcSRW Lc/cJmjCyxyfb802yCYT0BSVga/a9YoSDNtxubbOuu6BW0u6ex6rqzqD1TJxkSsHYhZ7 OdUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fCZPOrkHqLyNI93iHC3spYA3L+KtLSTyfugjQrFwGao=; b=7+kHmpSSUFZcES5nApuKbJfujZMbzeATGEu6mY6tjhLQlybRutAw4k3z02f2zFtMIX wCEwVtGsMyAi5rqmYkxP0Yr8ThnqTzUBeuEw1P38HBbtseTJNwf1Y2bVSHs36cbQzNUL aJyCO1j9yh3iuQXMVWuOXfvSMuFy9zxNS5OzVsiQhtSLis2f5gVPFqk9KmAfjiVFI9yE jISakcHYhxRKrdo9L0Ne9N6sIvBeU4u1rxMZ4ulhc2b8BOOcgMUqYP8bPRTc7gm8kbsw UWp65LN8HIhkC/ibrdflU0uIQvgARccELrFWHhscQmYAFzy4xoZYf5N4fmR5ZnnTZsoJ BVzA== X-Gm-Message-State: AOAM533ejO32oC8TwzRXE7M3BFDTccuRG4/W5m4y30L/EsR3VrVuEumx WbbXoVbzTYSnlzNLLQ3lbwUSP3oEA+O2ZA== X-Google-Smtp-Source: ABdhPJwMzkWAWdIXVM5J2WnjTD2m7IyzI+ZVquea9P6VaPwoIZnUBWKD06zwbPmGMiWoaxHSHD5PPA== X-Received: by 2002:a7b:cb88:: with SMTP id m8mr23373356wmi.64.1642521337664; Tue, 18 Jan 2022 07:55:37 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id f15sm1220522wrd.45.2022.01.18.07.55.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jan 2022 07:55:37 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , J Smith , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFz?= =?utf-8?b?b24=?= Subject: [PATCH v8 09/10] grep: simplify config parsing and option parsing Date: Tue, 18 Jan 2022 16:55:21 +0100 Message-Id: X-Mailer: git-send-email 2.35.0.rc1.864.g57621b115b6 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Simplify the parsing of "grep.patternType" and "grep.extendedRegexp". This changes no behavior, but gets rid of complex parsing logic that isn't needed anymore. When "grep.patternType" was introduced in 84befcd0a4a (grep: add a grep.patternType configuration setting, 2012-08-03) we promised that: 1. You can set "grep.patternType", and "[setting it to] 'default' will return to the default matching behavior". In that context "the default" meant whatever the configuration system specified before that change, i.e. via grep.extendedRegexp. 2. We'd support the existing "grep.extendedRegexp" option, but ignore it when the new "grep.patternType" option is set. We said we'd only ignore the older "grep.extendedRegexp" option "when the `grep.patternType` option is set. to a value other than 'default'". In a preceding commit we changed grep_config() to be called after grep_init(), which means that much of the complexity here can go away. As before both "grep.patternType" and "grep.extendedRegexp" are last-one-wins variable, with "grep.extendedRegexp" yielding to "grep.patternType", except when "grep.patternType=default". Note that this applies as we parse the config, i.e. a sequence of: -c grep.patternType=perl -c grep.extendedRegexp=true \ -c grep.patternType=default Should select ERE due to "grep.extendedRegexp=true and grep.extendedRegexp=default", not BRE, even though that's the "default" patternType. We can determine this as we parse the config, because: * If we see "grep.extendedRegexp" we set the internal "ero" to its boolean value. * If we see "grep.extendedRegexp" but "grep.patternType=[default|]" is in effect we *don't* set the internal "pattern_type_option" to update the pattern type. * If we see "grep.patternType!=default" we can set our internal "pattern_type_option" directly, it doesn't matter what the state of "grep.extendedRegexp" is, but we don't forget what it was, in case we see a "grep.patternType=default" again. * If we see a "grep.patternType=default" we can set the pattern to ERE or BRE depending on whether we last saw a "grep.extendedRegexp=true" or "grep.extendedRegexp=[false|]". We could equally call this new adjust_pattern_type() in compile_regexp(), i.e. this fixup on top of this passes all our tests (with -U0 for brevity): @@ -60,0 +61 @@ static void adjust_pattern_type(enum grep_pattern_type *pto, const int ero) +static int ero = -1; @@ -65 +65,0 @@ int grep_config(const char *var, const char *value, void *cb) - static int ero = -1; @@ -72 +71,0 @@ int grep_config(const char *var, const char *value, void *cb) - adjust_pattern_type(&opt->pattern_type_option, ero); @@ -80 +78,0 @@ int grep_config(const char *var, const char *value, void *cb) - adjust_pattern_type(&opt->pattern_type_option, ero); @@ -445,0 +444,2 @@ static void compile_regexp(struct grep_pat *p, struct grep_opt *opt) + if (ero != -1) + adjust_pattern_type(&opt->pattern_type_option, ero); But doing it as we stream the git_config() makes it clear that we can determine the interplay between these two variables as we go. We don't need to wait until we see the last value of the two configuration variables. This is true because of the rationale above, and because the subsequent code in compile_regexp() treats "pattern_type_option=GREP_PATTERN_TYPE_{UNSPECIFIED,BRE}" equally. I.e. we'll end up with different internal ""pattern_type_option" values there for: # UNSPECIFIED -c grep.patternType=default # BRE -c grep.extendedRegexp=false -c grep.patternType=default But the difference won't matter, which simplifies some of this logic, we never need to adjust a "grep.patternType" if we didn't see a "grep.extendedRegexp" before. We can also remove the "extended_regexp_option" member from "struct grep_opt" in favor of a static variable in grep_config(). The command-line parsing in cmd_grep() can then completely ignore "grep.extendedRegexp". Whatever effect it had before that step won't matter if we see -G, -E, -P etc. See my 07a3d411739 (grep: remove regflags from the public grep_opt API, 2017-06-29) for addition of the two comments being removed here, i.e. the complexity noted in that commit is now going away. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/grep.c | 10 +++---- grep.c | 77 +++++++++++--------------------------------------- grep.h | 4 --- revision.c | 2 -- 4 files changed, 20 insertions(+), 73 deletions(-) diff --git a/builtin/grep.c b/builtin/grep.c index 0ea124321b6..942c4b25077 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -845,7 +845,6 @@ int cmd_grep(int argc, const char **argv, const char *prefix) int i; int dummy; int use_index = 1; - int pattern_type_arg = GREP_PATTERN_TYPE_UNSPECIFIED; int allow_revs; struct option options[] = { @@ -879,16 +878,16 @@ int cmd_grep(int argc, const char **argv, const char *prefix) N_("descend at most levels"), PARSE_OPT_NONEG, NULL, 1 }, OPT_GROUP(""), - OPT_SET_INT('E', "extended-regexp", &pattern_type_arg, + OPT_SET_INT('E', "extended-regexp", &opt.pattern_type_option, N_("use extended POSIX regular expressions"), GREP_PATTERN_TYPE_ERE), - OPT_SET_INT('G', "basic-regexp", &pattern_type_arg, + OPT_SET_INT('G', "basic-regexp", &opt.pattern_type_option, N_("use basic POSIX regular expressions (default)"), GREP_PATTERN_TYPE_BRE), - OPT_SET_INT('F', "fixed-strings", &pattern_type_arg, + OPT_SET_INT('F', "fixed-strings", &opt.pattern_type_option, N_("interpret patterns as fixed strings"), GREP_PATTERN_TYPE_FIXED), - OPT_SET_INT('P', "perl-regexp", &pattern_type_arg, + OPT_SET_INT('P', "perl-regexp", &opt.pattern_type_option, N_("use Perl-compatible regular expressions"), GREP_PATTERN_TYPE_PCRE), OPT_GROUP(""), @@ -982,7 +981,6 @@ int cmd_grep(int argc, const char **argv, const char *prefix) argc = parse_options(argc, argv, prefix, options, grep_usage, PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_STOP_AT_NON_OPTION); - grep_commit_pattern_type(pattern_type_arg, &opt); if (use_index && !startup_info->have_repository) { int fallback = 0; diff --git a/grep.c b/grep.c index 60228a95a4f..bb487e994d0 100644 --- a/grep.c +++ b/grep.c @@ -48,6 +48,12 @@ static int parse_pattern_type_arg(const char *opt, const char *arg) define_list_config_array_extra(color_grep_slots, {"match"}); +static void adjust_pattern_type(enum grep_pattern_type *pto, const int ero) +{ + if (*pto == GREP_PATTERN_TYPE_UNSPECIFIED) + *pto = ero ? GREP_PATTERN_TYPE_ERE : GREP_PATTERN_TYPE_BRE; +} + /* * Read the configuration file once and store it in * the grep_defaults template. @@ -56,17 +62,22 @@ int grep_config(const char *var, const char *value, void *cb) { struct grep_opt *opt = cb; const char *slot; + static int ero = -1; if (userdiff_config(var, value) < 0) return -1; if (!strcmp(var, "grep.extendedregexp")) { - opt->extended_regexp_option = git_config_bool(var, value); + ero = git_config_bool(var, value); + adjust_pattern_type(&opt->pattern_type_option, ero); return 0; } if (!strcmp(var, "grep.patterntype")) { opt->pattern_type_option = parse_pattern_type_arg(var, value); + if (ero == -1) + return 0; + adjust_pattern_type(&opt->pattern_type_option, ero); return 0; } @@ -115,62 +126,6 @@ void grep_init(struct grep_opt *opt, struct repository *repo) opt->header_tail = &opt->header_list; } -static void grep_set_pattern_type_option(enum grep_pattern_type pattern_type, struct grep_opt *opt) -{ - /* - * When committing to the pattern type by setting the relevant - * fields in grep_opt it's generally not necessary to zero out - * the fields we're not choosing, since they won't have been - * set by anything. The extended_regexp_option field is the - * only exception to this. - * - * This is because in the process of parsing grep.patternType - * & grep.extendedRegexp we set opt->pattern_type_option and - * opt->extended_regexp_option, respectively. We then - * internally use opt->extended_regexp_option to see if we're - * compiling an ERE. It must be unset if that's not actually - * the case. - */ - if (pattern_type != GREP_PATTERN_TYPE_ERE && - opt->extended_regexp_option) - opt->extended_regexp_option = 0; - - switch (pattern_type) { - case GREP_PATTERN_TYPE_UNSPECIFIED: - /* fall through */ - - case GREP_PATTERN_TYPE_BRE: - break; - - case GREP_PATTERN_TYPE_ERE: - opt->extended_regexp_option = 1; - break; - - case GREP_PATTERN_TYPE_FIXED: - opt->fixed = 1; - break; - - case GREP_PATTERN_TYPE_PCRE: - opt->pcre2 = 1; - break; - } -} - -void grep_commit_pattern_type(enum grep_pattern_type pattern_type, struct grep_opt *opt) -{ - if (pattern_type != GREP_PATTERN_TYPE_UNSPECIFIED) - grep_set_pattern_type_option(pattern_type, opt); - else if (opt->pattern_type_option != GREP_PATTERN_TYPE_UNSPECIFIED) - grep_set_pattern_type_option(opt->pattern_type_option, opt); - else if (opt->extended_regexp_option) - /* - * This branch *must* happen after setting from the - * opt->pattern_type_option above, we don't want - * grep.extendedRegexp to override grep.patternType! - */ - grep_set_pattern_type_option(GREP_PATTERN_TYPE_ERE, opt); -} - static struct grep_pat *create_grep_pat(const char *pat, size_t patlen, const char *origin, int no, enum grep_pat_token t, @@ -490,9 +445,9 @@ static void compile_regexp(struct grep_pat *p, struct grep_opt *opt) p->word_regexp = opt->word_regexp; p->ignore_case = opt->ignore_case; - p->fixed = opt->fixed; + p->fixed = opt->pattern_type_option == GREP_PATTERN_TYPE_FIXED; - if (!opt->pcre2 && + if (opt->pattern_type_option != GREP_PATTERN_TYPE_PCRE && memchr(p->pattern, 0, p->patternlen)) die(_("given pattern contains NULL byte (via -f ). This is only supported with -P under PCRE v2")); @@ -544,14 +499,14 @@ static void compile_regexp(struct grep_pat *p, struct grep_opt *opt) return; } - if (opt->pcre2) { + if (opt->pattern_type_option == GREP_PATTERN_TYPE_PCRE) { compile_pcre2_pattern(p, opt); return; } if (p->ignore_case) regflags |= REG_ICASE; - if (opt->extended_regexp_option) + if (opt->pattern_type_option == GREP_PATTERN_TYPE_ERE) regflags |= REG_EXTENDED; err = regcomp(&p->regexp, p->pattern, regflags); if (err) { diff --git a/grep.h b/grep.h index 89a2ce51130..ab0f8290784 100644 --- a/grep.h +++ b/grep.h @@ -143,7 +143,6 @@ struct grep_opt { int unmatch_name_only; int count; int word_regexp; - int fixed; int all_match; int no_body_match; int body_hit; @@ -154,7 +153,6 @@ struct grep_opt { int allow_textconv; int extended; int use_reflog_filter; - int pcre2; int relative; int pathname; int null_following_name; @@ -163,7 +161,6 @@ struct grep_opt { int max_depth; int funcname; int funcbody; - int extended_regexp_option; enum grep_pattern_type pattern_type_option; int ignore_locale; char colors[NR_GREP_COLORS][COLOR_MAXLEN]; @@ -202,7 +199,6 @@ struct grep_opt { int grep_config(const char *var, const char *value, void *); void grep_init(struct grep_opt *, struct repository *repo); -void grep_commit_pattern_type(enum grep_pattern_type, struct grep_opt *opt); void append_grep_pat(struct grep_opt *opt, const char *pat, size_t patlen, const char *origin, int no, enum grep_pat_token t); void append_grep_pattern(struct grep_opt *opt, const char *pat, const char *origin, int no, enum grep_pat_token t); diff --git a/revision.c b/revision.c index d6e0e2b23b5..dd301e30147 100644 --- a/revision.c +++ b/revision.c @@ -2860,8 +2860,6 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s diff_setup_done(&revs->diffopt); - grep_commit_pattern_type(GREP_PATTERN_TYPE_UNSPECIFIED, - &revs->grep_filter); if (!is_encoding_utf8(get_log_output_encoding())) revs->grep_filter.ignore_locale = 1; compile_grep_patterns(&revs->grep_filter); From patchwork Tue Jan 18 15:55:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12716670 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D97DC433EF for ; Tue, 18 Jan 2022 15:55:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346157AbiARPzq (ORCPT ); Tue, 18 Jan 2022 10:55:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346160AbiARPzn (ORCPT ); Tue, 18 Jan 2022 10:55:43 -0500 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 683EFC061753 for ; Tue, 18 Jan 2022 07:55:40 -0800 (PST) Received: by mail-wm1-x332.google.com with SMTP id l35-20020a05600c1d2300b0034d477271c1so5190908wms.3 for ; Tue, 18 Jan 2022 07:55:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Zz+gwGP+Z3t7vmFWolGxN5S5/PabW00eNF0jUoAPvBM=; b=EgdJE/9JwpdgPUC499OswBfxvD6dqHWZDSwHKOdJu+FJjU8Ss5YDHY6XEZNy62Y7Ah dnHO6WnITBNnl3ukG3MDIVtY5rd1LBA6jH3claaVVZOfxRKb5dQhX0DUtNM6wXOYTZIL KMK/xY7CnekQVWoHRpRS5TySqiAAkED5gZe4OGQG7tC//bP3g6tFg/pqKqxei5ywH3aZ 9OGw86j2yEC2wTsK/5il6phBf+BAnDvfkd8M0snwQd77ExMq5fwI78sjAlXplmIkHpeU GwGVnbT6W8I0i6Cdh8EJbBKUMPJ+bNLhLpzjndTUBmfG3Bpv+do+3oIeRpZ9INoYjX9K TD4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Zz+gwGP+Z3t7vmFWolGxN5S5/PabW00eNF0jUoAPvBM=; b=yORZ1RwYo/Ti01ULQVyObuOgTY+OyLSycQdmItbugZ44oiagZDC1xV4ykc7weXT8zB pXB6+TWhVZo+pwrn7vJ9E6xgWkIRC6NKE3Y210VdOZ3+8FRvEucyeeODHwZuFSqGu2vJ D9qJrc1hhoyn8+KfYn0qQ5vLMbqWpjyq8Yz/rEw1oVZQUa7ASYwZnxxpceWaMdCqJK8I 9BrjXWo9/HOELiVCBBxrbbqsPaxGQHcBkmafzu3TNmrPgak996NGtCHWnwFrr8Du+O8J ARWII58zn4yX1rB9HaD5VdAhM1vvYdGfeHy1tIRrFah2njWIC2WZ5ttMHvL4ajjl43xR 7l+Q== X-Gm-Message-State: AOAM532ygsAtZooImPZ0AtWMuOQJ06KMXs1SowWiCrX1JU89ve2Uahkj sZNCAAnKHP/jwdkv6a06s0BMsHibig5Yfg== X-Google-Smtp-Source: ABdhPJxNxrImS2rDw7KNF6umqKN32WsdMJkT629sbu6+Nlasbymg7UITM82skJDRjWF0JGQ3q7N07g== X-Received: by 2002:a05:6000:178b:: with SMTP id e11mr22133749wrg.126.1642521338789; Tue, 18 Jan 2022 07:55:38 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id f15sm1220522wrd.45.2022.01.18.07.55.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jan 2022 07:55:38 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , J Smith , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFz?= =?utf-8?b?b24=?= Subject: [PATCH v8 10/10] grep.[ch]: remove GREP_PATTERN_TYPE_UNSPECIFIED Date: Tue, 18 Jan 2022 16:55:22 +0100 Message-Id: X-Mailer: git-send-email 2.35.0.rc1.864.g57621b115b6 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Remove the need for "GREP_PATTERN_TYPE_UNSPECIFIED" in favor of having the users of the "pattern_type_option" member check whether that member is set or not. The "UNSPECIFIED" case was already handled implicitly in compile_regexp(), and we don't use this "enum" in a "switch" statement, so let's not explicitly name the "GREP_PATTERN_TYPE_UNSPECIFIED = 0" case. It is still important that "GREP_PATTERN_TYPE_BRE != 0", as can be seen in failing tests if the parsing for "basic" in parse_pattern_type_arg() is made to "return 0". Signed-off-by: Ævar Arnfjörð Bjarmason --- grep.c | 9 ++++++--- grep.h | 4 +--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/grep.c b/grep.c index bb487e994d0..3497df48ca6 100644 --- a/grep.c +++ b/grep.c @@ -34,7 +34,7 @@ static const char *color_grep_slots[] = { static int parse_pattern_type_arg(const char *opt, const char *arg) { if (!strcmp(arg, "default")) - return GREP_PATTERN_TYPE_UNSPECIFIED; + return 0; else if (!strcmp(arg, "basic")) return GREP_PATTERN_TYPE_BRE; else if (!strcmp(arg, "extended")) @@ -50,8 +50,7 @@ define_list_config_array_extra(color_grep_slots, {"match"}); static void adjust_pattern_type(enum grep_pattern_type *pto, const int ero) { - if (*pto == GREP_PATTERN_TYPE_UNSPECIFIED) - *pto = ero ? GREP_PATTERN_TYPE_ERE : GREP_PATTERN_TYPE_BRE; + *pto = ero ? GREP_PATTERN_TYPE_ERE : GREP_PATTERN_TYPE_BRE; } /* @@ -69,12 +68,16 @@ int grep_config(const char *var, const char *value, void *cb) if (!strcmp(var, "grep.extendedregexp")) { ero = git_config_bool(var, value); + if (opt->pattern_type_option) + return 0; adjust_pattern_type(&opt->pattern_type_option, ero); return 0; } if (!strcmp(var, "grep.patterntype")) { opt->pattern_type_option = parse_pattern_type_arg(var, value); + if (opt->pattern_type_option) + return 0; if (ero == -1) return 0; adjust_pattern_type(&opt->pattern_type_option, ero); diff --git a/grep.h b/grep.h index ab0f8290784..460cb75a357 100644 --- a/grep.h +++ b/grep.h @@ -94,8 +94,7 @@ enum grep_expr_node { }; enum grep_pattern_type { - GREP_PATTERN_TYPE_UNSPECIFIED = 0, - GREP_PATTERN_TYPE_BRE, + GREP_PATTERN_TYPE_BRE = 1, GREP_PATTERN_TYPE_ERE, GREP_PATTERN_TYPE_FIXED, GREP_PATTERN_TYPE_PCRE @@ -180,7 +179,6 @@ struct grep_opt { .relative = 1, \ .pathname = 1, \ .max_depth = -1, \ - .pattern_type_option = GREP_PATTERN_TYPE_UNSPECIFIED, \ .colors = { \ [GREP_COLOR_CONTEXT] = "", \ [GREP_COLOR_FILENAME] = GIT_COLOR_MAGENTA, \