From patchwork Wed Dec 22 02:58:51 2021 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: 12690881 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 65503C433FE for ; Wed, 22 Dec 2021 02:59:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241997AbhLVC7F (ORCPT ); Tue, 21 Dec 2021 21:59:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231389AbhLVC7E (ORCPT ); Tue, 21 Dec 2021 21:59:04 -0500 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27E1DC061574 for ; Tue, 21 Dec 2021 18:59:04 -0800 (PST) Received: by mail-wr1-x430.google.com with SMTP id d9so1934422wrb.0 for ; Tue, 21 Dec 2021 18:59:04 -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=AML3ZjL347kzJSZXZgXNllQTMcZSbqh/GAX7r+JSXm8=; b=KPEMNLglXgyZ65E+OJUPAn5jLqfeLY4Oi09cFphTfzFIyd+uHIlwAkoUBZngCzeuWX NGL6YMVDjuaFL1k14qrEaBss4B39XTn7dO0QPlbsqRp69goSWmhozA/jfCHJEWa6MowC H76zCDUkbLmX1W25Ep6F42vh1NAbEgEDRG94uPU3kWlPI3pFyMF6X1N5AnvEBAfSVrp8 uE2C2bfTAls8PfggCdOaRi6E9X+D560XsVAVbu45E6uYyt6mKtJ80MCjkEdqcAcesj8L X2VvXgKwgC3BMAMld23GcA8KGi4b9c6ZUK9ginyAMu2gGow++ubwYDsQXhcVpVQC4Yum YfvA== 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=AML3ZjL347kzJSZXZgXNllQTMcZSbqh/GAX7r+JSXm8=; b=tc35lIMJjiV6+VulIucvgrskRDuGXXF0Z7OHwQiwM5j6gbyTUtHSTLRC1JEjkp+E2y WvjuXR+FwXnUXXoEr+Or1Xr88Sg274Qucw+LRAJUCS1RU9tROgNrTTZFKHKyuSdx/8sb Bfar98pTN0QI+EhliSlNPlzXExENoiL5Gygjlrb87ApgTRSdcepd5Eo/py1x1qBOKyHw Xx8VMIWbewWOGonpaKQRs+nS0+L8DZ6kOqoWElIcsezowc7gWEGEOERrnkgpBMwIHdOi H1K0go/43K/9qPuO618RjBaZXi2u+ApgNc9WTil9R76JrPlOws9am2oGNOU7wPSuEPx+ WUnA== X-Gm-Message-State: AOAM533IGbuXuWN1FDBd9UeknZFkBdap7mbB4egEYKFwk4YRp3edy4Ux hjY6A9U20SboH3O9WWHjLwhhLrll9A8oWw== X-Google-Smtp-Source: ABdhPJwQ4jxMpjbI1XQmQaHdUHUgvH1dffAYC0vitbzV6WB4iPmTlmKUIxU9ood6TNeDGLGkpHRM+w== X-Received: by 2002:a5d:5988:: with SMTP id n8mr608184wri.309.1640141941759; Tue, 21 Dec 2021 18:59:01 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n15sm611577wru.66.2021.12.21.18.59.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 18:59:01 -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 v5 1/7] grep.h: remove unused "regex_t regexp" from grep_opt Date: Wed, 22 Dec 2021 03:58:51 +0100 Message-Id: X-Mailer: git-send-email 2.34.1.1146.gb52885e7c44 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 3e8815c347b..95cccb670f9 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 Wed Dec 22 02:58:52 2021 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: 12690883 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 BC3F7C433F5 for ; Wed, 22 Dec 2021 02:59:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241999AbhLVC7G (ORCPT ); Tue, 21 Dec 2021 21:59:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241994AbhLVC7E (ORCPT ); Tue, 21 Dec 2021 21:59:04 -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 496FBC06173F for ; Tue, 21 Dec 2021 18:59:04 -0800 (PST) Received: by mail-wm1-x335.google.com with SMTP id bg2-20020a05600c3c8200b0034565c2be15so2991491wmb.0 for ; Tue, 21 Dec 2021 18:59:04 -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=62a1o0w8Pk9iAtUhtGeLygphHrIw0v5yGwT58iybur4=; b=PctDhI1/Fef7D/vBbjQuq72WhhwC14G9EYrWtJqD15wEry9ni4UiuSB2G6jsOMXd7o NIQqzlHNIIVvf10X3ZbuphzrBdHjxijKf4d6VZqEGUPuHhllql4bl67M37yUPIHT7zdv UCO6IUtaNtW8j9EBG3wapwUBs+xhv8rqEux711al11vaHeEdq5VABJKWPnlLpuMpjw+0 fymU0VdDx6pWYWMy3Y4eNy06/hLvWHuve/yJAmZXTUNT/9oYdZEAWJaffpxDUN8i0k7K mQhxxhe+B1jNfXqm5r9V6O0a4AEoIxNLpnJRD4YiENdAIZVimohuRkyYJCMGAGdzJHo9 siaQ== 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=62a1o0w8Pk9iAtUhtGeLygphHrIw0v5yGwT58iybur4=; b=iaGQWOYLijII5vYYsWHBEJ63gRrXLn8F16fpvXDPw0YvfD76y8gtiRsyQoh8tkRK4m rSpNmalZ5inP0m2Dp5C6bm/K8w3EIzYMCFOmoJURet+lK1+mA0zk6YSIt/bkkrlcoDyt LMIHhzn/LEf/iRvAmozg1feRWA1Bct+/PDJ/3+0TJrJkWh9vnQcV7db90HUbufmaA35o sS64iOEFH1VvFiq3Yzrbv3XvCZ1wwebHbGWg1sjluERV8yYjSJRNqZlf2sirkxTcmXT8 M9A2KMdhHoxwNyByDYwpojejvgefWjaocvEv8rCVSckxHPOVZ7S4tRSputCSYYDQ3TH4 berw== X-Gm-Message-State: AOAM530MPLx8jbiTGTo4irOab2Lt3XNPP4qHHplSlv5OxlokfcVMlWcN VNBQzQUGeymPixZU84W1MS0uE7pYyS9Emg== X-Google-Smtp-Source: ABdhPJyKSU1JEBk0tRf9M6BGT4Y3P/2GSTXt7Fv/8KFHijD/PK9kw2ZaSCvxlKx3i0m9KqIsauVIAw== X-Received: by 2002:a7b:ce16:: with SMTP id m22mr828211wmc.149.1640141942501; Tue, 21 Dec 2021 18:59:02 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n15sm611577wru.66.2021.12.21.18.59.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 18:59:01 -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 v5 2/7] log tests: check if grep_config() is called by "log"-like cmds Date: Wed, 22 Dec 2021 03:58:52 +0100 Message-Id: X-Mailer: git-send-email 2.34.1.1146.gb52885e7c44 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 2ced7e9d817..2490f2cd5ed 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 Wed Dec 22 02:58:53 2021 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: 12690885 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 D9620C433EF for ; Wed, 22 Dec 2021 02:59:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242003AbhLVC7G (ORCPT ); Tue, 21 Dec 2021 21:59:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242001AbhLVC7G (ORCPT ); Tue, 21 Dec 2021 21:59:06 -0500 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81983C061574 for ; Tue, 21 Dec 2021 18:59:05 -0800 (PST) Received: by mail-wr1-x430.google.com with SMTP id r17so1856994wrc.3 for ; Tue, 21 Dec 2021 18:59:05 -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=M4gXma/8cAPxQp7flO4XHKVGbDGmiA3qObLzIdSU6Lo=; b=WJMNMlsiZ2eKF5+QSpVNUmUXXxz3pQOChjPIMMtRaRe3YIUeqHgIQKNTS0ddKsGx1r auQKEOtUnvPh8SFtNcu5dzm2LraONSoKudFJ8Aptsq/bx5RmLn05cJ6K5LDvmHhHNA58 x9bGzoCYwlLN1gVFBHQZM0A4/X6XL8dh82Gz8RgIoCCWWc/rTL50dJAoNVhUcNuKH9J3 h5Rdiw9mmJ0U3gxLktCD/z6+b24o6zZzzdMEyQkqHeKP0Z8cN60IfUcO/RSGpK8hw0Fq u8+VoyBcP23AE+WrUfNbzDDNE67M9N3XuGmxoZChbQLNG7zIFbjbdxRgg7irRHkGCERE ashg== 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=M4gXma/8cAPxQp7flO4XHKVGbDGmiA3qObLzIdSU6Lo=; b=BAsurjdepicIovvxCP3TVG6Mki38/8WpuM/bt0or6OXWvXYBjx1AS9p9KsFBwjWWpN RHMtPoSts62DWBV5K4d9lAIdUQ5n87/W0dL1Rhoivv0ULxSQaacXxCokttWPgmhnfef8 fidsvw7/CgScu+AOQiaXwYVmiybPDpHqv4tCbSI5zfL205YdK6MICaNs4hVBYGxp3gNj tZRZ44WJRr92vpCFL6hF+oLTVjQeqotvgAjHecwabeWXRHuWBSuKXn1qaKfH28zUGiRW 2gRY6cUnbSyGKy37UnwtqSZudQ+o7GEanHVrAfF9P4+9EhktZ2xJmfKODGY96M0bcV8U 8m6w== X-Gm-Message-State: AOAM533wvxJ2A0E9rA9R4hJHklARc7NPYlEOw9bSCCzO8bIu436yPDzO G8vZy8S3IRoIJYD5CtGjR90pOLIiMXOPFA== X-Google-Smtp-Source: ABdhPJxojldgZpIjMvR2ib6gWL1GQExr+b1HW7vg8M/5pyjSMCyge2Lpq0TWTQES6NJgAhVpkp2C5w== X-Received: by 2002:adf:c7d2:: with SMTP id y18mr588874wrg.717.1640141943946; Tue, 21 Dec 2021 18:59:03 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n15sm611577wru.66.2021.12.21.18.59.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 18:59:02 -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 v5 3/7] grep tests: add missing "grep.patternType" config test Date: Wed, 22 Dec 2021 03:58:53 +0100 Message-Id: X-Mailer: git-send-email 2.34.1.1146.gb52885e7c44 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. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t7810-grep.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh index 6b6423a07c3..113902c3bda 100755 --- a/t/t7810-grep.sh +++ b/t/t7810-grep.sh @@ -451,6 +451,25 @@ do 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 \ From patchwork Wed Dec 22 02:58:54 2021 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: 12690887 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 E312CC433F5 for ; Wed, 22 Dec 2021 02:59:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242006AbhLVC7I (ORCPT ); Tue, 21 Dec 2021 21:59:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241994AbhLVC7G (ORCPT ); Tue, 21 Dec 2021 21:59:06 -0500 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7EA8BC06173F for ; Tue, 21 Dec 2021 18:59:06 -0800 (PST) Received: by mail-wr1-x434.google.com with SMTP id r17so1857084wrc.3 for ; Tue, 21 Dec 2021 18:59:06 -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=s17x1lXzl7lnMJmvxG+3BogZ0nChdliJQYTNidjZDQU=; b=ekg5ljL558tdxS9G9SZeH20TEDllJ3DJzO051rxQKxOFHN0npYx4iSQAL9lwZeXyZf UP+Y0/1kXgj81NBygx07eE6x5f23VenjAgUOZPEtVDOAh7S4jhQNJfHyqmnK0zRQ4qYp iiBZG+6TmmTp9osm/gbtrqCaDds3Vl0Lx9is3e9/mhowL72+uYb6oNit2vo27LhUPFpa QngqzpFI9ccfb/GZvr+gdIVrq8M8FQELKdfzz03YWFZK5pHBlfFI1KS3BX2JQpUTW0c+ 2v1TzPerdfZyfBkfJShVTf4Bveuk76vAbuEb0FDcNqu0uqxzPD+Yn25mRMolEPThSQPv dwVw== 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=s17x1lXzl7lnMJmvxG+3BogZ0nChdliJQYTNidjZDQU=; b=xHxO9lmsYHgtqqwgp9iNAWeLUwURqvyBZfGIH/cOZEtC8qZpyZb6zruthjzis/c99Z GNv8LZOHOBZox8/dtylv28jx0iZTeLccqfwB3+nAgao83pzpym5mzGALoC9Rw7kkS6lr VTm5UhGeDAJ9xbv6qK9YOR5LPRrUKIp4sdoX/05rtQyoDu1naF5evYvpdoTHpDfvZY8O hDEv/eXl1HEhCHbLIOQbP2DmJNg3yCgQ98VPDoWcYHqJGG2W3s2Qt1TxvQKyKUWsPvM+ CiYXVldnTzd/PpkXw0R8jFYBZQDWCLo1+jTkhfGgpvWxRSiAWj76C+S622hSXL+ue/qU OcYw== X-Gm-Message-State: AOAM531H9NTs210o7BGVdm5Gfve0mLJzVrAoXg8Ig9AVtxNOYXSiEOWa M9RhnGk16ojsotPQIq008TuH219fm8mKuA== X-Google-Smtp-Source: ABdhPJwX+YFDKdqCEbegV0eHG5N/G0iC5FZrfBLoQ+7QjLoAhJ9SHANGD5yLA5DQkxAj8el6kTrH6Q== X-Received: by 2002:a05:6000:389:: with SMTP id u9mr605244wrf.22.1640141944818; Tue, 21 Dec 2021 18:59:04 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n15sm611577wru.66.2021.12.21.18.59.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 18:59:04 -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 v5 4/7] built-ins: trust the "prefix" from run_builtin() Date: Wed, 22 Dec 2021 03:58:54 +0100 Message-Id: X-Mailer: git-send-email 2.34.1.1146.gb52885e7c44 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 7edafd8ecff..575d95046f2 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 fe847a0111a..12b202598a9 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 95cccb670f9..62deadb885f 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; @@ -180,7 +178,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 5390a479b30..495328e859c 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 Wed Dec 22 02:58:55 2021 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: 12690889 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 97B77C433EF for ; Wed, 22 Dec 2021 02:59:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242004AbhLVC7J (ORCPT ); Tue, 21 Dec 2021 21:59:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242005AbhLVC7H (ORCPT ); Tue, 21 Dec 2021 21:59:07 -0500 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 337DAC061574 for ; Tue, 21 Dec 2021 18:59:07 -0800 (PST) Received: by mail-wr1-x429.google.com with SMTP id v7so1765757wrv.12 for ; Tue, 21 Dec 2021 18:59:07 -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=gdyqqH01hTjXcKQTZW6SEM/Rs93OoJrEu9Zvy8CRHiE=; b=PKC+cqaytaRx0qpvWC0pEp/j1sRr8qr6OA9jVp+d+s8HyTx0uUwz2ys3dYJqaOZp5Q f8oZlObFF0Bm/fNjgOmJbS+dK7psNjJZt5Ei7ggI9tRmkrwPYz7gK/mqUrbjdTcRaoh1 sjckuMJj0u/8gmIq43mBMwOyrw6f4PXEP8SxtzD7O+z9N9kOy0QUWXfGVew8D2t+F6VW yU0tSbivvoJ5/CjJpAWgWXDXK0bemzwwQ6VqZ4vwV6KLwUkEHEoFBrA2mS4HbR0K682e 32vT4lASO0bsQipeuYP37qInXn6wQgdEWXGEF1AnWKE/nHyjMTuH9GU1arfaIzkxtWDo PkWg== 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=gdyqqH01hTjXcKQTZW6SEM/Rs93OoJrEu9Zvy8CRHiE=; b=Wy5KQaN9d5FJH9Qjd8DWLI4KZgJOc9QtOx+TeRO9aAH7n9AKqdDDQE6wDpQ0MK5v8U h4oPtHJLn2n3AzcjISP/VUvap7P9Iy7drCI0xAwuM3dDNyb/VEC4rAbY+8ElraO6VdHe Jg0qSAqRZ44niRkBO8MRNXC2vYZ/q9kO2e0oaND799U9hbSGodbcsdLHpXd/Nr6X395C d3TNDjAu4XP11ghXI7xVQ2d4YL3O9/Aug/ET+Jc4ZFh7sq9h291Jemu3dlOkMkzy9v1y sL9dMoPEBV/wMFcbUcLL7U5xhiHO9M8n5C8xHs9lhR/1BEkgnQIc1kVqg1oBAf/KZLnX VHnA== X-Gm-Message-State: AOAM530hzUa85e67drmOvqiD7nF+QtmVtbwrKIFOPk/7KWMNy2u7vfpB M2dttvqMTjJvOXILLrJxmiLx9e8ycblE2Q== X-Google-Smtp-Source: ABdhPJyILKDRv5+UFiA/TdcGYiq36BMMS3fqYdjZJiXp3RECaTy/g09J5D584KhC5zYlZ5pnp0jzvA== X-Received: by 2002:adf:b1d5:: with SMTP id r21mr629463wra.520.1640141945568; Tue, 21 Dec 2021 18:59:05 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n15sm611577wru.66.2021.12.21.18.59.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 18:59:05 -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 v5 5/7] grep.c: don't pass along NULL callback value Date: Wed, 22 Dec 2021 03:58:55 +0100 Message-Id: X-Mailer: git-send-email 2.34.1.1146.gb52885e7c44 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 Wed Dec 22 02:58:56 2021 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: 12690891 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 8E5F0C433EF for ; Wed, 22 Dec 2021 02:59:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242014AbhLVC7K (ORCPT ); Tue, 21 Dec 2021 21:59:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242008AbhLVC7I (ORCPT ); Tue, 21 Dec 2021 21:59:08 -0500 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 183BDC061574 for ; Tue, 21 Dec 2021 18:59:08 -0800 (PST) Received: by mail-wr1-x436.google.com with SMTP id s1so1817756wra.6 for ; Tue, 21 Dec 2021 18:59:08 -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=xMv+g7xMGEm9hwDCmxn8W2mAC/iWLT+hYLofdwdtCnI=; b=Br8g73knb5WImRGccFPFnXRysYpSss3k6Og2+3xcx5JbDIo/rmajgfC48VVDI7JBsk cyAV5Zobin7yH/5zIyQCdjrfQeQbsLKNOehJBu6zvmHZV3J2BUg/mcfsXpLK4Roshg/5 ULWM7BsyCPdF+5vRFcxWasgf+DkinJESCkNJF3JRGG/plWzCEpZDm7BWjwYDb1ibdj0a HsQvUTVfQwLdLUJptYr7jib6G5zA/dOWobdDZYyc9vqa9YlLmOM2AN0+4V5coTKCOSkR R8f3rcZJZtmfdGh950/T5Lm/EFSOSdse6MKME/YnUqhIy7Y/8ddwE+U6n3t67iao32TX 99xg== 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=xMv+g7xMGEm9hwDCmxn8W2mAC/iWLT+hYLofdwdtCnI=; b=VBW+e7aUsEDvxLLvJdYGr5eToM47awodfS4tnMO74gS1djcUGcZBeyh5BxkjZFQdCW L8pP9Ud5BxOOeodxc/NdoRd2aDKlIbS3IxrojMUPUi3rnSpUqOq5TfjCCU1kCvP0Oc9X 13JPafzRP5aNyHcQ527sbia4fu6h/p0N95MzohGSBC2dKmosC1mXejBtvawYdjjhj+T5 YEHwZ3tU4qMsQKYVY5a/Zp4iWiqHbltJEq0A/iylqlJRulIyFlh65RMFoGt1CT4kvdaV 7RNp0DpsKP0TdRTDZZdaygV7a4Hucm1ioNvLH6WblVyydUxrpTz3/T4gCvS2yQPQBEUx RgkA== X-Gm-Message-State: AOAM532bh2Noko1V38Z7l3edof3ims9L4zWMm0YC46st1tB9s4JmhTkr zULXVOYMQYC5jqdG7UsnwIXrWZIkFR47Nw== X-Google-Smtp-Source: ABdhPJzGqNJkxJS2EYFF8yQtc74IOFt1TgLBtUaWvwbPSQPwVosg38SRWBna+vPL585whoIuSOSeDA== X-Received: by 2002:adf:d1cf:: with SMTP id b15mr614861wrd.323.1640141946398; Tue, 21 Dec 2021 18:59:06 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n15sm611577wru.66.2021.12.21.18.59.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 18:59:05 -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 v5 6/7] grep API: call grep_config() after grep_init() Date: Wed, 22 Dec 2021 03:58:56 +0100 Message-Id: X-Mailer: git-send-email 2.34.1.1146.gb52885e7c44 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 93ace0dde7d..fdde77e4ebb 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 12b202598a9..8dfa0300786 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] = "", - [GREP_COLOR_FUNCTION] = "", - [GREP_COLOR_LINENO] = "", - [GREP_COLOR_COLUMNNO] = "", - [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 62deadb885f..b651eb291f7 100644 --- a/grep.h +++ b/grep.h @@ -177,6 +177,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] = "", \ + [GREP_COLOR_FUNCTION] = "", \ + [GREP_COLOR_LINENO] = "", \ + [GREP_COLOR_COLUMNNO] = "", \ + [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 Wed Dec 22 02:58:57 2021 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: 12690893 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 855E5C433FE for ; Wed, 22 Dec 2021 02:59:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242023AbhLVC7L (ORCPT ); Tue, 21 Dec 2021 21:59:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242009AbhLVC7J (ORCPT ); Tue, 21 Dec 2021 21:59:09 -0500 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F09B0C06173F for ; Tue, 21 Dec 2021 18:59:08 -0800 (PST) Received: by mail-wr1-x434.google.com with SMTP id v11so1794885wrw.10 for ; Tue, 21 Dec 2021 18:59:08 -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=8/ffV74A+23WdxJZGAnIA4wFSTAA5QeJVrn9NMY32Mw=; b=IXQuJaErwEr6zWb86JRNX2pXkXH6hXVOHshMp6MSWwpCn7efn/5a7s0tuzeBvXT508 7B55nQADNEIKy6s2yzpmBxzWJs50XCcZ5QontWLGoNqTUG8UDgsEC1jbbN7pnr8LFulH SJF8Zytakw7wzf8bBx7jGGu1IzEATo38dOH3hS+WBqDx+bFVEBSlZrR6g1rbMyi2wQWE cOdWItaxIoDZi7sAxnuBeGkWMv9KnV5gq4HiobSOJeJ5Qsbo4uMTc/4CuUkkN184jsGe 9OHyCaoKkXT3YlalqG1p+8wSJbC2UjdbbLTdtVW94tzsfMjBOs+/gxSW1TgVYZqkTM7i Ri5g== 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=8/ffV74A+23WdxJZGAnIA4wFSTAA5QeJVrn9NMY32Mw=; b=C5JV3Q1VfdN5OPN/ThUoDf0kBwWzXfwlB62v/Oz/QnVxItb5t+Bz1IYx4cjMWIWlIw rvm6qRMfg9YBaV7e40oTkOu8LfJG4f+QAJwVxyl9gPz90Qsjj0vxJfz5qwwWz+CLwVFY K0wksrUXKWgrjwaQmZ8IEnH/9ANGbt12dhc0XSTfkOODbdYxmBgOJ/YPHGnU31OYVNnE bd02Xb+gvv3nvls2WEzjvr85QYBFcOYYrF4AUzUU8S3aWKA5HPotHj54hRetkA3Yx1Pa +hBBbwI3pSymULtE4OCLeIkK+T972YnLvfs1LS1ynKqHzsczC35czG9w/Uhc6KMdCMV8 Gicg== X-Gm-Message-State: AOAM533/lTz1hDZ5IFaYqppPqjE66SiWU2gus97ocTRjPyFw2l5M7Q4n SyxFI7oUPsHbUNhBSS4bUUaOxvC9rPfa1Q== X-Google-Smtp-Source: ABdhPJzgSGQ3G8WDbWDudF1OVzaYWkWAyNAauIw1sC0RPwZG2OhLMHU7RYCk0/MPrRUbPFHC0vENiA== X-Received: by 2002:adf:ec09:: with SMTP id x9mr628358wrn.111.1640141947320; Tue, 21 Dec 2021 18:59:07 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n15sm611577wru.66.2021.12.21.18.59.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 18:59:06 -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 v5 7/7] grep: simplify config parsing and option parsing Date: Wed, 22 Dec 2021 03:58:57 +0100 Message-Id: X-Mailer: git-send-email 2.34.1.1146.gb52885e7c44 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". 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. Now as before when we only understand a "grep.extendedRegexp" setting of "true", and if "grep.patterntype=default" is set we'll interpret it as "grep.patterntype=basic", except if we previously saw a "grep.extendedRegexp", then it's interpreted as "grep.patterntype=extended". 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. We don't need grep_commit_pattern_type() anymore, we can instead have OPT_SET_INT() in "builtin/grep.c" manipulate the "pattern_type_option" member in "struct grep_opt" directly. We can also do away with the indirection of the "int fixed" and "int pcre2" members in favor of using "pattern_type_option" directly in "grep.c". Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/grep.c | 10 +++---- grep.c | 81 +++++++++++--------------------------------------- grep.h | 9 ++---- revision.c | 2 -- 4 files changed, 24 insertions(+), 78 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 8dfa0300786..b5342064066 100644 --- a/grep.c +++ b/grep.c @@ -33,9 +33,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; - else if (!strcmp(arg, "basic")) + if (!strcmp(arg, "basic")) return GREP_PATTERN_TYPE_BRE; else if (!strcmp(arg, "extended")) return GREP_PATTERN_TYPE_ERE; @@ -61,11 +59,23 @@ int grep_config(const char *var, const char *value, void *cb) return -1; if (!strcmp(var, "grep.extendedregexp")) { + if (opt->extended_regexp_option) + return 0; opt->extended_regexp_option = git_config_bool(var, value); + if (opt->extended_regexp_option) + opt->pattern_type_option = GREP_PATTERN_TYPE_ERE; + return 0; + } + + if (!strcmp(var, "grep.patterntype") && + !strcmp(value, "default")) { + opt->pattern_type_option = opt->extended_regexp_option == 1 + ? GREP_PATTERN_TYPE_ERE : GREP_PATTERN_TYPE_BRE; return 0; } if (!strcmp(var, "grep.patterntype")) { + opt->extended_regexp_option = -1; /* ignore */ opt->pattern_type_option = parse_pattern_type_arg(var, value); return 0; } @@ -115,62 +125,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 +444,10 @@ 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 (memchr(p->pattern, 0, p->patternlen) && !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")); p->is_fixed = is_fixed(p->pattern, p->patternlen); @@ -543,14 +498,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 b651eb291f7..ab2ce833b40 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 = 0, GREP_PATTERN_TYPE_ERE, GREP_PATTERN_TYPE_FIXED, GREP_PATTERN_TYPE_PCRE @@ -143,7 +142,6 @@ struct grep_opt { int unmatch_name_only; int count; int word_regexp; - int fixed; int all_match; #define GREP_BINARY_DEFAULT 0 #define GREP_BINARY_NOMATCH 1 @@ -152,7 +150,6 @@ struct grep_opt { int allow_textconv; int extended; int use_reflog_filter; - int pcre2; int relative; int pathname; int null_following_name; @@ -162,7 +159,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; @@ -181,7 +178,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] = "", \ @@ -200,7 +196,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 495328e859c..298d0ea7574 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);