From patchwork Wed Nov 10 01:43:43 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: 12611251 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 079D2C433F5 for ; Wed, 10 Nov 2021 01:44:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DB46061207 for ; Wed, 10 Nov 2021 01:43:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229647AbhKJBqp (ORCPT ); Tue, 9 Nov 2021 20:46:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229470AbhKJBqn (ORCPT ); Tue, 9 Nov 2021 20:46:43 -0500 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DEE6C061764 for ; Tue, 9 Nov 2021 17:43:56 -0800 (PST) Received: by mail-ed1-x531.google.com with SMTP id x15so4062392edv.1 for ; Tue, 09 Nov 2021 17:43:56 -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=hAtfKNdCTtF2HY5pW9XfukK+7SN8KwhlYcfVTdzPkQ0=; b=Lwnb8pxggMeI2o6obOE8udd1zATGIo1milrDzL1mxw3kVo78lwGJdjTlHcl0OVK+Xi 3De5LjqAdgZUeAimuHpIi0HUofOJslcvuiROLoLfXIhwRdT5fZPE2i6u27nOPmYDn/SE 8L8sGa22TkvhiBZ6/0BGg+VjcdV9j0iq1C2m4wSYNq9suyGiiFIFkJ97DbVhoFDM5fab ww/SxYVSFdvvxPWPipKx3VL/pNcyfMNh5O2YB+OSjX/u4x44lYj4pCZbGs3+c6I2I9ix cbyOcdhQgrryZ75Spexb+AC246BL/46DuIpY0FwB89pN3u1X34k9fZSj0kB2vhTy+pIh 4AhA== 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=hAtfKNdCTtF2HY5pW9XfukK+7SN8KwhlYcfVTdzPkQ0=; b=cMu65lGCYpkSwEjwarSFh5+ldWEEDKaXB1NStJ7Qyh8hH4TBhZRJ2gwIbnaR0Bb47X YDV+5hr4JOCf0VNgvK86vyv6GdMHiyxghz14NYs6l2sDDxmD4Kq+EF0yiemM3Sm8jst8 5cdhuipMPF/vxt1RPLF9j+gLL2/1ocspU25v5pNd9Bg7psAmS7U0N3CNtbATcY4jGMsV suTyFQ1znlz99pHTKYqkU0VqSvgEwvuOmLw/+fG6RhOKBZIQGvzSj1Y9Gdeix4pu6ySB 1JBkOLr5bifnyo79tyQfzsk/9aNJMf9wWBbRLJK2t05HWGg9TcgXbUljHj3pIAKV1kRb ztEQ== X-Gm-Message-State: AOAM532pIn8q5m6E5kYMGQvUponxGbrgHz7SiJI431lu4kobZzRDQLdT aIsuSvIImaYKJKMwJXrccFAd1Fm2eFGPSg== X-Google-Smtp-Source: ABdhPJyVwtz7XjX5t6JEBfo/cmo9pz31EuyAAmzkCgP+VBQsBsknNLWDEN1f3ng5fpi4XtZ+CHEaYA== X-Received: by 2002:a05:6402:84c:: with SMTP id b12mr16255366edz.323.1636508635023; Tue, 09 Nov 2021 17:43:55 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id qf8sm9369252ejc.8.2021.11.09.17.43.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Nov 2021 17:43:54 -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 v2 1/8] grep.h: remove unused "regex_t regexp" from grep_opt Date: Wed, 10 Nov 2021 02:43:43 +0100 Message-Id: X-Mailer: git-send-email 2.34.0.rc2.791.gdbfcf909579 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 Nov 10 01:43:44 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: 12611255 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B98A6C433EF for ; Wed, 10 Nov 2021 01:44:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9C54961205 for ; Wed, 10 Nov 2021 01:44:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229713AbhKJBqs (ORCPT ); Tue, 9 Nov 2021 20:46:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229638AbhKJBqp (ORCPT ); Tue, 9 Nov 2021 20:46:45 -0500 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7600BC061764 for ; Tue, 9 Nov 2021 17:43:57 -0800 (PST) Received: by mail-ed1-x52b.google.com with SMTP id z21so3970965edb.5 for ; Tue, 09 Nov 2021 17:43:57 -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=m6vNSCYVowYau1Q2FwT6dMSni5gY/1BZW4/8FvrsVvI=; b=XZlc9y/CdyUcmQr+KRHQQx85zo9bVG2nX56iflP/U9olonlGTui1Mzfdb4tCKeDjN+ AUBMKjWkJhDcpRQacosvXQibhMWUFc18RpmC/oXYfvAeck4hquIBb9oYuvWaPXhn33SU i98Q84LxyqgSFWXL2rn65L+SctjUyhxCHg2kGkBc07qab4YeQ1jdD+k6fa3zJSpct4uK LNTENP9v/jAvW9DCMuLxLC9/0/wHWlu6CzZ3KPuMn+5gnXmKos9oJtBR5RTiEbWR7Ov6 0SJQkApUugv1ShTVeJtTtjlrhPBlqotJx6+9dsDyg0necdre6gBJ/v9wuysPDgMv3vIV Sj+Q== 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=m6vNSCYVowYau1Q2FwT6dMSni5gY/1BZW4/8FvrsVvI=; b=xo+ZFgUlN/PsiFGWT/D46fAvl9aLHPyRP2kLfp6sIHr3wA0bQyQvAWUzL3ib9c45uQ aN2Ov33qg2zaMrIuFOeiyNF8KzHW2HVY2lPl8meOFNIIfk468Xfn2iI+AXKaXVpQb/+A uADXQhewxc2ua6+rPXT80zYrwS//+h60mtuo0rJACD0+rzQxFN+SjpMwv+4ojN64uC78 sXyj4ayOWCIqx+O97Pqf+sxBFQo72CgXY0bbmIMnL5GQxuM+P3uz/O1hoF0RvCp1oUdB U6YCmS15LQ3DRuusbW3ubEIHDQpAatcqh2xzRPRCE+8Q/uKrnvTEStSE78ItDH2pTIQw vMIw== X-Gm-Message-State: AOAM532HVNXgUoCEsPogcY2kPFSmuUq688pVknavbl7RFUt11hBF15ZD SjXvzU2nO7ZaLhw3OfiHaOaWA7AartNtXg== X-Google-Smtp-Source: ABdhPJxOgkS6t5bM8Q97XJN7IWYtI7cx9nmcCZyLfLL6vTTR2oPB/3Ff461f237pGYoiRNz0sv5lkg== X-Received: by 2002:a50:d88a:: with SMTP id p10mr16890978edj.274.1636508635742; Tue, 09 Nov 2021 17:43:55 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id qf8sm9369252ejc.8.2021.11.09.17.43.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Nov 2021 17:43:55 -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 v2 2/8] built-ins: trust the "prefix" from run_builtin() Date: Wed, 10 Nov 2021 02:43:44 +0100 Message-Id: X-Mailer: git-send-email 2.34.0.rc2.791.gdbfcf909579 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 | 9 ++++----- git.c | 4 ++-- grep.c | 4 +--- grep.h | 4 +--- revision.c | 2 +- 6 files changed, 17 insertions(+), 19 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..84bed6d5612 100644 --- a/builtin/ls-tree.c +++ b/builtin/ls-tree.c @@ -147,16 +147,15 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix) OPT__ABBREV(&abbrev), OPT_END() }; - - git_config(git_default_config, NULL); ls_tree_prefix = prefix; - if (prefix && *prefix) + if (prefix) chomp_prefix = strlen(prefix); + git_config(git_default_config, NULL); argc = parse_options(argc, argv, prefix, ls_tree_options, ls_tree_usage, 0); if (full_tree) { - ls_tree_prefix = prefix = NULL; + ls_tree_prefix = NULL; chomp_prefix = 0; } /* -d -r should imply -t, but -d by itself should not have to. */ @@ -178,7 +177,7 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix) parse_pathspec(&pathspec, PATHSPEC_ALL_MAGIC & ~(PATHSPEC_FROMTOP | PATHSPEC_LITERAL), PATHSPEC_PREFER_CWD, - prefix, argv + 1); + ls_tree_prefix, argv + 1); for (i = 0; i < pathspec.nr; i++) pathspec.items[i].nowildcard_len = pathspec.items[i].len; pathspec.has_wildcard = 0; diff --git a/git.c b/git.c index 5ff21be21f3..611bf2f63eb 100644 --- a/git.c +++ b/git.c @@ -420,9 +420,8 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv) { int status, help; struct stat st; - const char *prefix; + const char *prefix = NULL; - prefix = NULL; help = argc == 2 && !strcmp(argv[1], "-h"); if (!help) { if (p->option & RUN_SETUP) @@ -431,6 +430,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv) int nongit_ok; prefix = setup_git_directory_gently(&nongit_ok); } + assert(!prefix || *prefix); precompose_argv_prefix(argc, argv, NULL); if (use_pager == -1 && p->option & (RUN_SETUP | RUN_SETUP_GENTLY) && !(p->option & DELAY_PAGER_CONFIG)) diff --git a/grep.c b/grep.c index f6e113e9f0f..c9065254aeb 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 ab7c1358042..9f9b0d2429e 100644 --- a/revision.c +++ b/revision.c @@ -1833,7 +1833,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 Nov 10 01:43:45 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: 12611253 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5769DC433FE for ; Wed, 10 Nov 2021 01:44:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2E127611F2 for ; Wed, 10 Nov 2021 01:44:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229652AbhKJBqt (ORCPT ); Tue, 9 Nov 2021 20:46:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229644AbhKJBqp (ORCPT ); Tue, 9 Nov 2021 20:46:45 -0500 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F1BAC061766 for ; Tue, 9 Nov 2021 17:43:58 -0800 (PST) Received: by mail-ed1-x536.google.com with SMTP id x15so4062588edv.1 for ; Tue, 09 Nov 2021 17:43:58 -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=mqRMt6KaGEScXIBjp+/xKo1c8g5Yjh+NMPSRiI+phhw=; b=AWgvMKIOPx+3cs8/yenz+1r1n5hTyoN3/N9eaH55HMwpudDc7cTrgAyknf2gRyH2Od kjPH3DQuMihXoKaoSYKCYNGCRV/+0brAbN3Mvurz3LiTXjziLHbduqqGFqjvYdMhrXix Si5rvIkCYZR3V/ihHapnUxrZfkEA0n6nD4JKPppzhYz+f3ohudZdMhcL6cD0w3FbmFkq /AHzNyD/GfAQPvU6xvu80AWZQqygulxa5Mmk23w3pvcmOog4jtwSdtkvhuGFwLMJWJ4H vepOG64R2UinXn0BQD2fJQPu16qMjV+i+nSjiZ3f5qTgCL+tkE5+OkB9ZlVCpVal4FHV duEA== 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=mqRMt6KaGEScXIBjp+/xKo1c8g5Yjh+NMPSRiI+phhw=; b=eGLTMbn1GvY5jTAsWxK7dPtpH6JEipyryo0PXS8J1poZSX628tqogOSYl4sAQX9TSo +ITWbqAzkL/9SFE4fon3WuYR7kyHhVQl994NuscnAdkhzFGQHOHYPX01jlF+PKcoTIIn P9uA3uvwdhWx/mJXRzcSKGSoa4jIi6M4xEvupxcyUMej1uRuMZQSFEUH89qacWYAYZBk i69M3Bpm1WQDLPirMFVTdVBZ1qHwW7xPlDikQqt0btvNwORwRuJUSKhW2qpwSPwGbzM9 frvhUsN8KM41SZ58pHmr9KYuK8994wD81qqVcy++2UfKMl34WscaE9BHZnpCWb/xbmqH fVRg== X-Gm-Message-State: AOAM531g+ZvOVzt2Tu4gdvB0RRbYYtMIfWut9TgzpTHyO9Hh4BeGYaBu MRlxqsSGhIqeGOel5jheB1+jw7lahbcQQg== X-Google-Smtp-Source: ABdhPJwDC1VprpJiL/1CFvE121eWDC1kOsj+19y7fjrNcKHZg0P1Lfzee6DpE+IpYZSWU4Yn2ldJdg== X-Received: by 2002:a17:907:8a1a:: with SMTP id sc26mr15824519ejc.402.1636508636605; Tue, 09 Nov 2021 17:43:56 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id qf8sm9369252ejc.8.2021.11.09.17.43.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Nov 2021 17:43:55 -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 v2 3/8] log tests: check if grep_config() is called by "log"-like cmds Date: Wed, 10 Nov 2021 02:43:45 +0100 Message-Id: X-Mailer: git-send-email 2.34.0.rc2.791.gdbfcf909579 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 a PCRE regex matches for the purposes of this test, we otherwise assume that it's running the same code as "git log", whose behavior is tested more exhaustively by test added in 9df46763ef1e. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t4202-log.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/t/t4202-log.sh b/t/t4202-log.sh index 7884e3d46b3..a114c49ef27 100755 --- a/t/t4202-log.sh +++ b/t/t4202-log.sh @@ -449,6 +449,22 @@ test_expect_success !FAIL_PREREQS 'log with various grep.patternType configurati ) ' +for cmd in show whatchanged reflog format-patch +do + myarg= + if test "$cmd" = "format-patch" + then + myarg="HEAD~.." + fi + + test_expect_success PCRE "$cmd: understands grep.patternType=perl, like 'log'" ' + git -c grep.patternType=fixed -C pattern-type $cmd --grep="1(?=\|2)" $myarg >actual && + test_must_be_empty actual && + git -c grep.patternType=perl -C pattern-type $cmd --grep="1(?=\|2)" $myarg >actual && + test_file_not_empty actual + ' +done + test_expect_success 'log --author' ' cat >expect <<-\EOF && Author: A U Thor From patchwork Wed Nov 10 01:43:46 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: 12611257 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7E389C433F5 for ; Wed, 10 Nov 2021 01:44:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 682E261207 for ; Wed, 10 Nov 2021 01:44:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229697AbhKJBqt (ORCPT ); Tue, 9 Nov 2021 20:46:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229470AbhKJBqq (ORCPT ); Tue, 9 Nov 2021 20:46:46 -0500 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EEBBAC061767 for ; Tue, 9 Nov 2021 17:43:58 -0800 (PST) Received: by mail-ed1-x532.google.com with SMTP id z21so3971137edb.5 for ; Tue, 09 Nov 2021 17:43:58 -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=dKJDejMguoKuLBK9KEjikGOmBRA+WOPweKJVsbkw2A8=; b=XCgmKHQrp2yOP/GZxFYI0Yo0VGym8eIwuieiqs/BfsKKBcN8PoA63jcSVCjt48/lCH V6G+NiugWq0dj8k0fYMrw49gKkP/thkWWNKcRxhsKOVf3IItFOQPZXCFMHHuj5wUmf9F NvPBYCK64jqpg6AWVuRwoxhDYTcdAfHtIYgZJ1QAk5lXOv61B8gV43zhBQ0Jc1fyIqeo KiB4hbJ1KV/oWcd0hcWIR2rrzLutmJTDAgKpKH+bYDMv6kHL63+T2b9qbI/R1xSXxUIv FuwQkaP9FEfSKV7fKxMZURFDkzkGwfQ/CoCfUvNzPsD3ZgpYobxGZuImNEXN369rXj90 xNDA== 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=dKJDejMguoKuLBK9KEjikGOmBRA+WOPweKJVsbkw2A8=; b=5eBMejPYoNEJ0pgZTo/RAGLK824aMenpd/rieVFme+dquNhMnwI/v5OXZhn9tzhe93 6HpXUNmvepOd6MyQjUtehEEvkdW9IASg7y4YmmwOJTYV1RwbKsME9yjDsuyi/1hGgA/W 7DrQnpQwChGsx+iDKjbI0nqOxZh4PAx3nOPjpyxdLXqoJJST72AK2jzsUfiUI5edqsmW 53KzImAJrgx9Mx2VzyJgbYEg/yoyJEXrybvuOoDDSPJTKuTgzvPlEGkCqU8+bd5ZdEAy woypbYVzbJ8X1ivu34DhU+DWqQLYtoLDmracKeSJ9s3SmgkuakXfMATblGlx38L+7JwR I66g== X-Gm-Message-State: AOAM530tYbP6PFAcTIJput11H8r89SPo58MK7ar2Vv4jxzkgfUP/e5Cp hrMp6n0SY79lUDVVkjyVHiHPVsrvfJRDGg== X-Google-Smtp-Source: ABdhPJw7zton/ya+JYlGzbLvJQYqMCwKFukA8CdHSG9jgctNxsBkayRtE82g6nE//kks7zw7bV+UoQ== X-Received: by 2002:a05:6402:144f:: with SMTP id d15mr16549595edx.43.1636508637336; Tue, 09 Nov 2021 17:43:57 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id qf8sm9369252ejc.8.2021.11.09.17.43.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Nov 2021 17:43:57 -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 v2 4/8] grep docs: de-duplicate configuration sections Date: Wed, 10 Nov 2021 02:43:46 +0100 Message-Id: X-Mailer: git-send-email 2.34.0.rc2.791.gdbfcf909579 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Include the "config/grep.txt" file in "git-grep.txt", instead of repeating an almost identical description of the "grep" configuration variables in two places. In a subsequent commit we'll amend this documentation, and can now do so in one place instead of two. Let's also add a short blurb at the top indicating that this is included documentation, so users won't think that they need to read the two versions and compare them. That wording is copy/pasted from the change I made in b6a8d09f6d8 (gc docs: include the "gc.*" section from "config" in "gc", 2019-04-07), eventually we'll want to include this via template, and indeed this change is extracted from a WIP series that fixes all these "CONFIGURATION" includes which does that. But doing that would require build system changes, so let's punt on it for now. There is no loss of information here that isn't shown in the addition to "grep.txt". This change was made by copying the contents of "git-grep.txt"'s version over the "grep.txt" version. Aside from the change "grep.txt" being made here the two were identical. This documentation started being copy/pasted around in b22520a37c8 (grep: allow -E and -n to be turned on by default via configuration, 2011-03-30). After that in e.g. 6453f7b3486 (grep: add grep.fullName config variable, 2014-03-17) they started drifting apart, with only grep.fullName being described in the command documentation. In 434e6e753fe (config.txt: move grep.* to a separate file, 2018-10-27) we gained the include, but didn't do this next step, let's do it now. Signed-off-by: Ævar Arnfjörð Bjarmason --- Documentation/config/grep.txt | 7 +++++-- Documentation/git-grep.txt | 30 +++--------------------------- 2 files changed, 8 insertions(+), 29 deletions(-) diff --git a/Documentation/config/grep.txt b/Documentation/config/grep.txt index 44abe45a7ca..ae51f2d91c8 100644 --- a/Documentation/config/grep.txt +++ b/Documentation/config/grep.txt @@ -16,8 +16,11 @@ grep.extendedRegexp:: other than 'default'. grep.threads:: - Number of grep worker threads to use. - See `grep.threads` in linkgit:git-grep[1] for more information. + Number of grep worker threads to use. If unset (or set to 0), Git will + use as many threads as the number of logical cores available. + +grep.fullName:: + If set to true, enable `--full-name` option by default. grep.fallbackToNoIndex:: If set to true, fall back to git grep --no-index if git grep diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt index 3d393fbac1b..29d5ce04f5a 100644 --- a/Documentation/git-grep.txt +++ b/Documentation/git-grep.txt @@ -334,34 +334,10 @@ performance in this case, it might be desirable to use `--threads=1`. CONFIGURATION ------------- -grep.lineNumber:: - If set to true, enable `-n` option by default. - -grep.column:: - If set to true, enable the `--column` option by default. - -grep.patternType:: - Set the default matching behavior. Using a value of 'basic', 'extended', - 'fixed', or 'perl' will enable the `--basic-regexp`, `--extended-regexp`, - `--fixed-strings`, or `--perl-regexp` option accordingly, while the - value 'default' will return to the default matching behavior. - -grep.extendedRegexp:: - If set to true, enable `--extended-regexp` option by default. This - option is ignored when the `grep.patternType` option is set to a value - other than 'default'. - -grep.threads:: - Number of grep worker threads to use. If unset (or set to 0), Git will - use as many threads as the number of logical cores available. - -grep.fullName:: - If set to true, enable `--full-name` option by default. - -grep.fallbackToNoIndex:: - If set to true, fall back to git grep --no-index if git grep - is executed outside of a git repository. Defaults to false. +The below documentation is the same as what's found in +linkgit:git-config[1]: +include::config/grep.txt[] GIT --- From patchwork Wed Nov 10 01:43:47 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: 12611259 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CFBEFC433EF for ; Wed, 10 Nov 2021 01:44:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B516B61205 for ; Wed, 10 Nov 2021 01:44:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229694AbhKJBqv (ORCPT ); Tue, 9 Nov 2021 20:46:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229648AbhKJBqq (ORCPT ); Tue, 9 Nov 2021 20:46:46 -0500 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A653EC0613F5 for ; Tue, 9 Nov 2021 17:43:59 -0800 (PST) Received: by mail-ed1-x52f.google.com with SMTP id f4so3827290edx.12 for ; Tue, 09 Nov 2021 17:43:59 -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=JYTVApSzvo6rij7Ku21eXe2bY2z0lyyjIwpnjfawSeI=; b=jeQ5BLSRJYWMVoLetTHHQBJMwNhljyfjEfPLSxB3qXbQgds1wDFtwM7Golc4xlhskE NbIKZOkvPpCaixBu+ZVYapDMoeVqL3FF4CeGK8gXqTG8vvX+iIYCaajBYmxpDdT3/2Ij oeUfg46h+1EYf5QY1b2o3N6n2tX9igQ0sssZSkefh4WX/HTa1vnUZeTtCpHGYqjaXDno bw0joH9Su/qfg+Uk6QCrA2Z9ryrwo2bz6L4A2pzoLGN6zk2ms/8DuGcna1VGThwbnmG/ //yuTtT0LkzeO9uTj8JkY7YuVVZ4Vn9e+Frvco1ONcEdZZbOOQUx8npME5UwW3QBxE1x nXBQ== 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=JYTVApSzvo6rij7Ku21eXe2bY2z0lyyjIwpnjfawSeI=; b=ThcyQO6zaWAuvs64pDGL4lMvas+QTLy0KcT4YuA3Z6ObkubBy73Nib5wurcVjee97M ELSz9HPjQcN4tYPOotSu7BDHI1owy89ex8KN42aeBOsQpD6joCxkuncUniTSdG7/snv9 I/y2XcHsgb4T6putagqH7NBYzde4JWbQFHmYP02MVlXpGWtG06/cj3qDrxq9sArA4N3o WzUhvLXbe8uUB7EO6+yttzTVCt+xFbG4xlD6KOozhaZGD9F9pMkkJcnuvsVLZ1IQIZ79 xK2vtGV46R2CGEO0xKQ5Di22ZXbAjokUUasCn5UJxzZOJ7QxaIVfkBgg+CfX7vYc+3Wg xRIA== X-Gm-Message-State: AOAM5335aFfAHkq+wwub+fc+DnuiSNKWK2xDTvxeL8lGr6678h0oSGtD QAUsBWJB87E2CRBXYQ61oAg4bIsVZE0fVQ== X-Google-Smtp-Source: ABdhPJyWx0MV1DEh3Jcbv0ebNpJhrWxjNLf5njU+Mc4nQi+XQWBF10g7/gTort9foDzgKkm2O0TiuA== X-Received: by 2002:a05:6402:438f:: with SMTP id o15mr16500228edc.235.1636508638067; Tue, 09 Nov 2021 17:43:58 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id qf8sm9369252ejc.8.2021.11.09.17.43.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Nov 2021 17:43:57 -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 v2 5/8] grep.c: don't pass along NULL callback value Date: Wed, 10 Nov 2021 02:43:47 +0100 Message-Id: X-Mailer: git-send-email 2.34.0.rc2.791.gdbfcf909579 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change grep_cmd_config() top 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 Nov 10 01:43:48 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: 12611261 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 10EB5C433F5 for ; Wed, 10 Nov 2021 01:44:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ED936611F2 for ; Wed, 10 Nov 2021 01:44:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229720AbhKJBqw (ORCPT ); Tue, 9 Nov 2021 20:46:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229630AbhKJBqr (ORCPT ); Tue, 9 Nov 2021 20:46:47 -0500 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CC5FC061205 for ; Tue, 9 Nov 2021 17:44:00 -0800 (PST) Received: by mail-ed1-x52c.google.com with SMTP id g14so4031398edz.2 for ; Tue, 09 Nov 2021 17:44:00 -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=5SKKVY9LuT10gaGb7Mt2kpy8VFnyLVUTXcYA4jwMWFs=; b=EhN9EcCpPqbBobipiLOjep/069gf5ERDhVv5b88Ns6/k74Jw4rcsYwUsRMCu9/F0O/ bE46M7Lo5WY6dYcja+qWY1Saqj6vaEnB9Nc+jGvyyH75F04KKso450fzVAq9rMLi+AnY TEwGnMIRn/uKqGOCjBzAeflPgmDSmJfLXzP+wy8wTSCvI4AOPlrvw7FugM4lNV1C5Mnd Tk+Hw1K++jUBzSV06fEkaosL5PluMTkFB1FN2iqRXHPnM6VbthqNN38IOLRXEEbFYsRU puygFPcRsJLugCs8cPrOCqWsboVjywAEUWNShPhRhfxECMkdwUGmpgriVgy2USM0G9RA O9tA== 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=5SKKVY9LuT10gaGb7Mt2kpy8VFnyLVUTXcYA4jwMWFs=; b=1CG3F/WmARe5eNXxp9ZgdBsUm7uSqh8G/UW6pAXoOgoamTIIESths/TCQowm5kijXv ojec9Ju/+zz4SPs6TH0gOrJ43Cl+ntOzvhASY1awYL27uifkGfAL99FLJpgLudJBKFQV YuAFQMD5V1EZHJw09k9M91ImtGPteAPxzE9qZG2UEZKoeZ7b0aWT5dq9OrzLFAZQVghn JBQnm+fSrdjvDNk87/+LAkrKKi/07wiS9ShC5UQGHJUi2lcoy8T4u/XZYLmyhfJFXGwK tf6hUL6EgbmsDJ/TPGOYxs/m+hNHN+G6YY71OG1ztgMNNRdSXo0VBsSMMAUTSyyZd1V1 BLCQ== X-Gm-Message-State: AOAM530KjxJSsz7EwtmRtokjA94ocMQ99vecInqbqmzaEk4m2bLJHhFw TK4BG4pFIJ2ExyD3419zhmYHzdK1bdTf6g== X-Google-Smtp-Source: ABdhPJwb+U5F7Ms1soGKDNszD1h/k4si3XpVqk6OZQFSB5ntcSQLSR7xnd7YufGit6+WF2ckRb5enA== X-Received: by 2002:a17:906:1558:: with SMTP id c24mr15829910ejd.553.1636508638773; Tue, 09 Nov 2021 17:43:58 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id qf8sm9369252ejc.8.2021.11.09.17.43.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Nov 2021 17:43:58 -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 v2 6/8] grep API: call grep_config() after grep_init() Date: Wed, 10 Nov 2021 02:43:48 +0100 Message-Id: X-Mailer: git-send-email 2.34.0.rc2.791.gdbfcf909579 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 | 22 ++++++++++++++++++++++ 4 files changed, 38 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 f75d87e8d7f..bfddacdfa6c 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -505,8 +505,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); @@ -521,6 +519,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)); @@ -635,6 +635,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; @@ -718,6 +720,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"; @@ -751,6 +755,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"; @@ -1833,10 +1839,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 c9065254aeb..fb3f63c63ef 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..30a7dfd3294 100644 --- a/grep.h +++ b/grep.h @@ -171,12 +171,34 @@ struct grep_opt { int show_hunk_mark; int file_break; int heading; + void *caller_priv; void *priv; void (*output)(struct grep_opt *opt, const void *data, size_t size); 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 Nov 10 01:43:49 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: 12611263 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EDDB6C433EF for ; Wed, 10 Nov 2021 01:44:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D1ED261205 for ; Wed, 10 Nov 2021 01:44:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229749AbhKJBqx (ORCPT ); Tue, 9 Nov 2021 20:46:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229634AbhKJBqs (ORCPT ); Tue, 9 Nov 2021 20:46:48 -0500 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 541C8C06120A for ; Tue, 9 Nov 2021 17:44:01 -0800 (PST) Received: by mail-ed1-x536.google.com with SMTP id f8so4012714edy.4 for ; Tue, 09 Nov 2021 17:44:01 -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=ggYW2GgU/k+PHsk75HjDs6UVuLcn2sQQh+4AjAKaSUU=; b=FEURCVYCNuXjNLuDEiSnxL9bowto6KqTWAbF3FCY53xK4Zn65Glh08YmCULzM8lpyR 6h4fFKnne6meq3Mevveb/Be1wbTnsXyt3AnItrqnGLFQ/yEB0YC+pUAI2j6oL8frVQia XDUn0yq0+z+iy20IV880f0Yu3VqhisOhwIJUCfnMJlGStnDswGzBVNck9nQEtUL4Wt7C tfG6giABoZ4+5fvR+FXaA7DTMkrVnLJUbu8rYPIDAXVPRQfhPspTT5aSOLWahVAfis3J aQWVSLqToMMKUbbqzRGnS+Q21CqwFurqu68+nGW+8z9sRoOVb1D2MQZ1Jhj0N+8vR/C8 FaAw== 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=ggYW2GgU/k+PHsk75HjDs6UVuLcn2sQQh+4AjAKaSUU=; b=VDGhVAM8VENWWj6+bMXqnyNPKN3p1DnNboNJKJKWoHbyUe2ZMyHqW93bilvZCQM42G 7M6mCuiphLPLy5fxXlfpioiGi5sKGT+gIqX2CqFSBaGPtr7A5TSaRl+BnchHSZI7uLKA ZUaT0tfii6oi0mK2LRa7pw3Hj6nfJOqXr7CJ+7QmdFBIi80eeiN0b+R8SX73I2G795Nf hx+slpzV//OlSkU4P7U5aJwnLNNdBOaTRfIXBwJ3PFPt9eXS/4cCZkpg5E6ui60QOg7I InyF1uA69iuX78wdhGBSWN+XykIiJgs4w2LWV3ybua4Qrj8ufhqyFyx6hAGcUX/Pk3jR 0ntg== X-Gm-Message-State: AOAM532RqPCQgiBIcFwdJR+0PLmoQx/9SfcMmMACKSLlk//myAkj1CwA KOfnjCUJqjCl74XUCdVN5Ca/Fw4IrHvYYA== X-Google-Smtp-Source: ABdhPJyP9VAB+V3pl67QjNbHqVi8NrAtywj9CVHScruMkv/yq1cLkx/ngUXnWyrluImIOuNeK2B2MQ== X-Received: by 2002:a05:6402:4404:: with SMTP id y4mr16513562eda.354.1636508639480; Tue, 09 Nov 2021 17:43:59 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id qf8sm9369252ejc.8.2021.11.09.17.43.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Nov 2021 17:43:58 -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 v2 7/8] grep: simplify config parsing, change grep. interaction Date: Wed, 10 Nov 2021 02:43:49 +0100 Message-Id: X-Mailer: git-send-email 2.34.0.rc2.791.gdbfcf909579 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change the interaction between "grep.patternType=default" and "grep.extendedRegexp=true" to make setting "grep.extendedRegexp=true" synonymous with setting "grep.patternType=extended". This changes our existing config parsing behavior as detailed below, but in a way that's consistent with how we parse other configuration. We are breaking past promises here, but I doubt that this will impact anyone in practice. The reduction in complexity and resulting consistency with other default config behavior is worth it. When "grep.patternType" was introduced in 84befcd0a4a (grep: add a grep.patternType configuration setting, 2012-08-03) we made two seemingly contradictory promises: 1. You can set "grep.patternType", and "[setting it to] 'default' will return to the default matching behavior". 2. Support the existing "grep.extendedRegexp" option, but ignore it when the new "grep.patternType" is set, *except* "when the `grep.patternType` option is set. to a value other than 'default'". I think that 84befcd0a4a probably didn't intend this behavior, but instead ended up conflating our internal "unspecified" state with a user's explicit desire to set the configuration back to the default. I.e. a user would correctly expect this to keep working: # ERE grep git -c grep.extendedRegexp=true grep And likewise for "grep.patternType=default" to take precedence over the disfavored "grep.extendedRegexp" option, i.e. the usual "last set wins" semantics. # BRE grep git -c grep.extendedRegexp=true -c grep.patternType=basic grep But probably not for this to ignore the favored "grep.patternType" option entirely, say if /etc/gitconfig was still setting "grep.extendedRegexp", but "~/.gitconfig" used the new "grep.patternType" (and wanted to use the "default" value): # Was ERE, now BRE git -c grep.extendedRegexp=true grep.patternType=default grep I think that in practice nobody or almost nobody is going to be relying on this obscure interaction, and as shown here it makes the config parsing much simpler. We no longer have to carry a complex state machine in "grep_commit_pattern_type()" and "grep_set_pattern_type_option()". We can also do away with the "int fixed" and "int pcre2" members in favor of using "pattern_type_option" directly in "grep.c", as well as dropping the "pattern_type_arg" variable in "builtin/grep.c" in favor of using the "pattern_type_option" member directly. 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 --- Documentation/config/grep.txt | 3 +- builtin/grep.c | 10 ++--- grep.c | 71 +++++------------------------------ grep.h | 6 +-- revision.c | 2 - t/t7810-grep.sh | 2 +- 6 files changed, 16 insertions(+), 78 deletions(-) diff --git a/Documentation/config/grep.txt b/Documentation/config/grep.txt index ae51f2d91c8..f4b7d3041fb 100644 --- a/Documentation/config/grep.txt +++ b/Documentation/config/grep.txt @@ -12,8 +12,7 @@ grep.patternType:: grep.extendedRegexp:: If set to true, enable `--extended-regexp` option by default. This - option is ignored when the `grep.patternType` option is set to a value - other than 'default'. + option is ignored when the `grep.patternType` option is set. grep.threads:: Number of grep worker threads to use. If unset (or set to 0), Git will 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 fb3f63c63ef..dda8e536fe3 100644 --- a/grep.c +++ b/grep.c @@ -60,8 +60,10 @@ int grep_config(const char *var, const char *value, void *cb) if (userdiff_config(var, value) < 0) return -1; - if (!strcmp(var, "grep.extendedregexp")) { - opt->extended_regexp_option = git_config_bool(var, value); + if (opt->pattern_type_option == GREP_PATTERN_TYPE_UNSPECIFIED && + !strcmp(var, "grep.extendedregexp") && + git_config_bool(var, value)) { + opt->pattern_type_option = GREP_PATTERN_TYPE_ERE; return 0; } @@ -115,62 +117,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, @@ -492,9 +438,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); @@ -545,14 +492,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 30a7dfd3294..e4e548aed90 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; #define GREP_BINARY_DEFAULT 0 #define GREP_BINARY_NOMATCH 1 @@ -152,7 +151,6 @@ struct grep_opt { int allow_textconv; int extended; int use_reflog_filter; - int pcre2; int relative; int pathname; int null_following_name; @@ -161,8 +159,7 @@ struct grep_opt { int max_depth; 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; @@ -201,7 +198,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 9f9b0d2429e..ed29d245c89 100644 --- a/revision.c +++ b/revision.c @@ -2864,8 +2864,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); diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh index 6b6423a07c3..a59a9726357 100755 --- a/t/t7810-grep.sh +++ b/t/t7810-grep.sh @@ -443,7 +443,7 @@ do ' test_expect_success "grep $L with grep.extendedRegexp=true and grep.patternType=default" ' - echo "${HC}ab:abc" >expected && + echo "${HC}ab:a+bc" >expected && git \ -c grep.extendedRegexp=true \ -c grep.patternType=default \ From patchwork Wed Nov 10 01:43:50 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: 12611265 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 244BCC433F5 for ; Wed, 10 Nov 2021 01:44:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0E9D061207 for ; Wed, 10 Nov 2021 01:44:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229756AbhKJBqy (ORCPT ); Tue, 9 Nov 2021 20:46:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229712AbhKJBqs (ORCPT ); Tue, 9 Nov 2021 20:46:48 -0500 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC4A3C061764 for ; Tue, 9 Nov 2021 17:44:01 -0800 (PST) Received: by mail-ed1-x533.google.com with SMTP id o8so4012300edc.3 for ; Tue, 09 Nov 2021 17:44:01 -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=GHVpC2dlokfOuvR2KzJbRif1JbqDDdAra5IGKMFnbDw=; b=ANLvTU85O7kB+1YkRZ7FttuCNSqwOdUzPWRMd4ZC5rxylLVHEf6MmL28lGLOz4QJlz qtI0siJWgMZ78Ov6bv+pPwPK2NbmYqpQ1trOPkZzUVxOS2+0r6umi2h4spU64fl84Ksk DzaY/EDV8Io7rIqgHsMWwRKdeWO3O70z4vLkka5lupdZvkXz+GcVBs6vDkw7VrXtfYEq dhOge8WKKSrPhQz8Lmohy+3xrZeEKHL9mEvEM31LRDLBpfQeUP6njonFLGq/dC3BNUmT dCjWnhH3wRFHpLRfdwtbffqvpoNpy5f7a5fluXpOuWPFcrPaOolU4E135Y95P+mCgk+1 wkJg== 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=GHVpC2dlokfOuvR2KzJbRif1JbqDDdAra5IGKMFnbDw=; b=xCTMbargMEUVEtzkTHlxHgzUcoShX+DvupBAMRhkMofQiOLRmZVLZplRueydJheJfi s0OBJmPQCt8X3mN3mHBGcrop3HXw9cnsV5nq5dTcOHnBXQA+/WioYUW+HwT0dYK1gawG E8ibrVX2L4gCIlvL1JK0ORKzaA/hnegCP6VhBpRgXuAZ5nTFaFs3R9l7/UEbQihh9Eq1 XD8zCgIeKPjugaGp4jGb94SHNVkmPjHTWJqkAnz+2D1eawgwWL62fsyPa5FdoOkooVUJ GGnSDfypmhnzTbAr77LvT6nsRjceoRThwSw01Nsq8PtfEIecYdmyCbcsOY4smwmQYURA 6SeA== X-Gm-Message-State: AOAM530YHqeDh8lGOX72kvrLWEJ8bzvtSnjLpapGB6f9vHYH+Qu4oUF4 8p0TjR9ZSZphTgc6vQ+qT83md88qHe4I5g== X-Google-Smtp-Source: ABdhPJx3BHB7XvsS4u/1hlY2rwFY4CssfVC+S0iB+r4XMayZWF1cUx9UAETneDJOqCNlSsSaxEJH9Q== X-Received: by 2002:a17:906:15d0:: with SMTP id l16mr15692957ejd.462.1636508639990; Tue, 09 Nov 2021 17:43:59 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id qf8sm9369252ejc.8.2021.11.09.17.43.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Nov 2021 17:43:59 -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 v2 8/8] grep: make "extendedRegexp=true" the same as "patternType=extended" Date: Wed, 10 Nov 2021 02:43:50 +0100 Message-Id: X-Mailer: git-send-email 2.34.0.rc2.791.gdbfcf909579 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In the preceding commit we changed how a "grep.patternType=default" set after "grep.extendedRegexp=true" would be handled so that the last set would win, but a "grep.extendedRegexp=true" would only be used if "grep.patternType" was set to a value other than "default". Thus a user who had old config and set "grep.extendedRegexp=true" in their ~/.gitconfig expecting ERE behavior would be opted-in to say "perl" regexes if a system "/etc/gitconfig" started setting "grep.patternType=perl". These funny semantics of only paying attention to a set if another key is not set to a given value aren't how we treat other config keys, so let's do away with this caveat for consistency. The new semantics are simple, a "grep.extendedRegexp=true" is an exact synonym for specifying "grep.patternType=extended" in the config. We'll keep ignoring ""grep.extendedRegexp=false", although arguably we could treat it as a "grep.patternType=basic". As argued in the preceding commit I think this behavior came about because we were conflating the state of our code's own internal "default" value with what we found in explicit user config. See 84befcd0a4a (grep: add a grep.patternType configuration setting, 2012-08-03) for that past behavior. Let's further change the documentation to note that "grep.extendedRegexp" is a deprecated synonym, perhaps we'll be able to remove it at some point in the future and do away with this special-case entirely. Signed-off-by: Ævar Arnfjörð Bjarmason --- Documentation/config/grep.txt | 3 +-- grep.c | 8 +++----- grep.h | 4 +--- t/t7810-grep.sh | 2 +- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/Documentation/config/grep.txt b/Documentation/config/grep.txt index f4b7d3041fb..33e5f3827bc 100644 --- a/Documentation/config/grep.txt +++ b/Documentation/config/grep.txt @@ -11,8 +11,7 @@ grep.patternType:: value 'default' will return to the default matching behavior. grep.extendedRegexp:: - If set to true, enable `--extended-regexp` option by default. This - option is ignored when the `grep.patternType` option is set. + Deprecated synonym for 'grep.patternType=extended`. grep.threads:: Number of grep worker threads to use. If unset (or set to 0), Git will diff --git a/grep.c b/grep.c index dda8e536fe3..ef8746d85f0 100644 --- a/grep.c +++ b/grep.c @@ -33,9 +33,8 @@ 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") || + !strcmp(arg, "default")) return GREP_PATTERN_TYPE_BRE; else if (!strcmp(arg, "extended")) return GREP_PATTERN_TYPE_ERE; @@ -60,8 +59,7 @@ int grep_config(const char *var, const char *value, void *cb) if (userdiff_config(var, value) < 0) return -1; - if (opt->pattern_type_option == GREP_PATTERN_TYPE_UNSPECIFIED && - !strcmp(var, "grep.extendedregexp") && + if (!strcmp(var, "grep.extendedregexp") && git_config_bool(var, value)) { opt->pattern_type_option = GREP_PATTERN_TYPE_ERE; return 0; diff --git a/grep.h b/grep.h index e4e548aed90..8ef70d125ff 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 @@ -179,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] = "", \ diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh index a59a9726357..afca938a4d0 100755 --- a/t/t7810-grep.sh +++ b/t/t7810-grep.sh @@ -461,7 +461,7 @@ do ' test_expect_success "grep $L with grep.patternType=basic and grep.extendedRegexp=true" ' - echo "${HC}ab:a+bc" >expected && + echo "${HC}ab:abc" >expected && git \ -c grep.patternType=basic \ -c grep.extendedRegexp=true \