{"thread":{"id":"61275","subject":"[PATCH] feat(log): add option to search for header or body to `git log`","startedAt":"2024-04-05T21:48:11Z","lastAt":"2024-04-07T14:00:30Z","messageCount":5,"participants":["Max Coplan via GitGitGadget","Phillip Wood","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"492324","messageId":"pull.1710.git.1712353687464.gitgitgadget@gmail.com","threadId":"61275","inReplyTo":null,"subject":"[PATCH] feat(log): add option to search for header or body to `git log`","fromName":"Max Coplan via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2024-04-05T21:48:07Z","receivedAt":"2024-04-05T21:48:11Z","isPatch":true,"sender":{"key":"name:Max Coplan","avatar":null},"body":"From: =?UTF-8?q?Max=20=F0=9F=91=A8=F0=9F=8F=BD=E2=80=8D=F0=9F=92=BB=20Copl?=\n =?UTF-8?q?an?= <mchcopl@gmail.com>\n\nNote to reviewer: I hate the name `--header-or`!  Please help me come up\nwith a better name.\n\nSummary:\nThis change adds a new option to `git log` that allows users to search\nfor commits that match either the author or the commit message. This is\nuseful for finding commits that were either authored or co-authored by a\nspecific person.\n\nCurrently, the best way to find a commit either authored or co-authored\nby a specific person is to use\n\n```sh\necho \\\n    $(git log --author=Torvalds --pretty=\"%cd,%H\\n\" --date=iso-strict) \\\n    $(git log --grep=\"Co-authored-by: .*Torvalds\" --pretty=\"%cd,%H\\n\" --date=iso-strict) \\\n| sort -n --reverse \\\n| awk -F, '{print $2}' \\\n| tr '\\n' '\\t' \\\n| xargs git show --stat --stdin\n```\n\nThis is a bit of a pain, so this change adds a new option to `git log`.\nNow finding either authors or co-authors is as simple as\n\n```sh\ngit log --author=Torvalds --grep=Torvalds --header-or\n```\n\nTest plan:\n1. create commit authored by A and co-authored-by B\n2. create commit authored by B\n3. run `git log --author=B --grep=\"Co-authored-by: B\" --header-or`\n4. expect to see both commits\n\nSigned-off-by: Max 👨🏽‍💻 Coplan <mchcopl@gmail.com>\n---\n    feat(log): add option to search for header or body to git log\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-1710%2Fvegerot%2Fheader-or-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1710/vegerot/header-or-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/1710\n\n grep.c          |  2 +-\n grep.h          |  1 +\n revision.c      |  3 +++\n t/t7810-grep.sh | 11 +++++++++++\n 4 files changed, 16 insertions(+), 1 deletion(-)\n\ndiff --git a/grep.c b/grep.c\nindex ac34bfeafb3..79ba4810b83 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -797,7 +797,7 @@ void compile_grep_patterns(struct grep_opt *opt)\n \tif (opt->no_body_match && opt->pattern_expression)\n \t\topt->pattern_expression = grep_not_expr(opt->pattern_expression);\n \n-\tif (!header_expr)\n+\tif (!header_expr || opt->header_or)\n \t\treturn;\n \n \tif (!opt->pattern_expression)\ndiff --git a/grep.h b/grep.h\nindex 926c0875c42..8cbc4a46194 100644\n--- a/grep.h\n+++ b/grep.h\n@@ -147,6 +147,7 @@ struct grep_opt {\n \tint count;\n \tint word_regexp;\n \tint all_match;\n+\tint header_or;\n \tint no_body_match;\n \tint body_hit;\n #define GREP_BINARY_DEFAULT\t0\ndiff --git a/revision.c b/revision.c\nindex 7e45f765d9f..0858050ece3 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -2646,6 +2646,9 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg\n \t\trevs->grep_filter.pattern_type_option = GREP_PATTERN_TYPE_PCRE;\n \t} else if (!strcmp(arg, \"--all-match\")) {\n \t\trevs->grep_filter.all_match = 1;\n+\t// @@@ must-fix: find a better name\n+\t} else if (!strcmp(arg, \"--header-or\")) {\n+\t\trevs->grep_filter.header_or = 1;\n \t} else if (!strcmp(arg, \"--invert-grep\")) {\n \t\trevs->grep_filter.no_body_match = 1;\n \t} else if ((argcount = parse_long_opt(\"encoding\", argv, &optarg))) {\ndiff --git a/t/t7810-grep.sh b/t/t7810-grep.sh\nindex 875dcfd98f3..d539b5e88f5 100755\n--- a/t/t7810-grep.sh\n+++ b/t/t7810-grep.sh\n@@ -961,6 +961,17 @@ test_expect_success 'log --grep --author uses intersection' '\n \ttest_cmp expect actual\n '\n \n+test_expect_success 'log --grep --author --header-or uses union' '\n+\t# grep matches only third and fourth\n+\t# author matches only initial and third\n+\tgit log --author=\"A U Thor\" --grep=r --header-or --format=%s >actual &&\n+\t{\n+\t    echo fourth && echo third\n+\t} >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+\n test_expect_success 'log --grep --grep --author takes union of greps and intersects with author' '\n \t# grep matches initial and second but not third\n \t# author matches only initial and third\n\nbase-commit: 7774cfed6261ce2900c84e55906da708c711d601\n-- \ngitgitgadget\n"},{"id":"492384","messageId":"c93817ba-5945-4ec0-9775-5621481b972c@gmail.com","threadId":"61275","inReplyTo":"pull.1710.git.1712353687464.gitgitgadget@gmail.com","subject":"Re: [PATCH] feat(log): add option to search for header or body to `git log`","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2024-04-06T14:04:37Z","receivedAt":"2024-04-06T14:04:40Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"Hi Max\n\nOn 05/04/2024 22:48, Max Coplan via GitGitGadget wrote:\n> From: =?UTF-8?q?Max=20=F0=9F=91=A8=F0=9F=8F=BD=E2=80=8D=F0=9F=92=BB=20Copl?=\n>   =?UTF-8?q?an?= <mchcopl@gmail.com>\n> \n> Note to reviewer: I hate the name `--header-or`!  Please help me come up\n> with a better name.\n> \n> Summary:\n> This change adds a new option to `git log` that allows users to search\n> for commits that match either the author or the commit message. This is\n> useful for finding commits that were either authored or co-authored by a\n> specific person.\n\nI think that having a way to find all the commits that are authored by, \nor have a specific trailer naming someone is a good idea. I'm not sure \nabout combining \"--author\" with \"--grep\" to do it though. Perhaps we \ncould design a new option (tentatively called \"--indent\") that allows \nthe user to specify a name and which trailers and commit headers (author \nand/or committer) to match.\n\nA couple of house keeping notes. We do not use the \"feat(...)\" style of \ncommit messages in this project. The subject line should just start with \n\"log: \" the rest of the subject looks fine. I think everything under the \n\"Summary:\" line above does a good job of explaining why the change is \nuseful which is great. We tend to avoid emoji's in peoples names as well.\n\n > [...]\n> +test_expect_success 'log --grep --author --header-or uses union' '\n> +\t# grep matches only third and fourth\n> +\t# author matches only initial and third\n\nI'm a bit confused by this comment as we seem to only expect \"third\" and \n\"fourth\" below - what happened to \"initial\"?\n\n> +\tgit log --author=\"A U Thor\" --grep=r --header-or --format=%s >actual &&\n> +\t{\n> +\t    echo fourth && echo third\n> +\t} >expect &&\n\nWe have a test helper to help with this\n\n     test_write_lines fourth third >expect\n\nBest Wishes\n\nPhillip\n"},{"id":"492436","messageId":"pull.1710.v2.git.1712460247516.gitgitgadget@gmail.com","threadId":"61275","inReplyTo":"pull.1710.git.1712353687464.gitgitgadget@gmail.com","subject":"[PATCH v2] log: add option to search for header or body","fromName":"Max Coplan via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2024-04-07T03:24:07Z","receivedAt":"2024-04-07T03:24:11Z","isPatch":true,"sender":{"key":"name:Max Coplan","avatar":null},"body":"From: =?UTF-8?q?Max=20=F0=9F=91=A8=F0=9F=8F=BD=E2=80=8D=F0=9F=92=BB=20Copl?=\n =?UTF-8?q?an?= <mchcopl@gmail.com>\n\nSummary:\nThis change adds a new option to `git log` that allows users to search\nfor commits that match either the author or the commit message. This is\nuseful for finding commits that were either authored or co-authored by a\nspecific person.\n\nCurrently, the best way to find a commit either authored or co-authored\nby a specific person is to use\n\n```sh\n$ echo \\\n    $(git log --author=Torvalds --pretty=\"%cd,%H\\n\" --date=iso-strict) \\\n    $(git log --grep=\"Co-authored-by: .*Torvalds\" --pretty=\"%cd,%H\\n\" --date=iso-strict) \\\n| sort -n --reverse \\\n| awk -F, '{print $2}' \\\n| tr '\\n' '\\t' \\\n| xargs git show --stat --stdin\n```\n\nThis is a bit of a pain, so this change adds a new option to `git log`.\nNow finding either authors or co-authors is as simple as\n\n```sh\n$ git log --author=Torvalds --grep=Torvalds --match-header-or-grep\n```\n\nTest plan:\n1. create commit authored by A and co-authored-by B\n2. create commit authored by B\n3. run\n```sh\n$ git log --author=B --grep=\"Co-authored-by: B\" --match-header-or-grep\n```\n4. expect to see both commits\n\nSigned-off-by: Max 👨🏽‍💻 Coplan <mchcopl@gmail.com>\n---\n    log: add option to search for header or body\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-1710%2Fvegerot%2Fheader-or-v2\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1710/vegerot/header-or-v2\nPull-Request: https://github.com/gitgitgadget/git/pull/1710\n\nRange-diff vs v1:\n\n 1:  dc6b5664159 ! 1:  c7f14e59b4f feat(log): add option to search for header or body to `git log`\n     @@ Metadata\n      Author: Max 👨🏽‍💻 Coplan <mchcopl@gmail.com>\n      \n       ## Commit message ##\n     -    feat(log): add option to search for header or body to `git log`\n     -\n     -    Note to reviewer: I hate the name `--header-or`!  Please help me come up\n     -    with a better name.\n     +    log: add option to search for header or body\n      \n          Summary:\n          This change adds a new option to `git log` that allows users to search\n     @@ Commit message\n          by a specific person is to use\n      \n          ```sh\n     -    echo \\\n     +    $ echo \\\n              $(git log --author=Torvalds --pretty=\"%cd,%H\\n\" --date=iso-strict) \\\n              $(git log --grep=\"Co-authored-by: .*Torvalds\" --pretty=\"%cd,%H\\n\" --date=iso-strict) \\\n          | sort -n --reverse \\\n     @@ Commit message\n          Now finding either authors or co-authors is as simple as\n      \n          ```sh\n     -    git log --author=Torvalds --grep=Torvalds --header-or\n     +    $ git log --author=Torvalds --grep=Torvalds --match-header-or-grep\n          ```\n      \n          Test plan:\n          1. create commit authored by A and co-authored-by B\n          2. create commit authored by B\n     -    3. run `git log --author=B --grep=\"Co-authored-by: B\" --header-or`\n     +    3. run\n     +    ```sh\n     +    $ git log --author=B --grep=\"Co-authored-by: B\" --match-header-or-grep\n     +    ```\n          4. expect to see both commits\n      \n          Signed-off-by: Max 👨🏽‍💻 Coplan <mchcopl@gmail.com>\n      \n     + ## Documentation/rev-list-options.txt ##\n     +@@ Documentation/rev-list-options.txt: endif::git-rev-list[]\n     + \tLimit the commits output to ones that match all given `--grep`,\n     + \tinstead of ones that match at least one.\n     + \n     ++--match-header-or-grep::\n     ++\tLimit the commits output to ones that match either header patterns\n     ++\t(`--author`, `--committer`, or `--grep-reflog`) or `--grep`, instead\n     ++\tof ones that match both the header and grep patterns\n     +++\n     ++For example, `--author=me --grep=Co-authored-by: me` limits to commits either\n     ++authored or co-authored by me.\n     ++\n     + --invert-grep::\n     + \tLimit the commits output to ones with a log message that do not\n     + \tmatch the pattern specified with `--grep=<pattern>`.\n     +\n     + ## contrib/completion/git-completion.bash ##\n     +@@ contrib/completion/git-completion.bash: __git_log_gitk_options=\"\n     + # Options that go well for log and shortlog (not gitk)\n     + __git_log_shortlog_options=\"\n     + \t--author= --committer= --grep=\n     +-\t--all-match --invert-grep\n     ++\t--all-match --invert-grep --match-header-or-grep\n     + \"\n     + # Options accepted by log and show\n     + __git_log_show_options=\"\n     +\n       ## grep.c ##\n      @@ grep.c: void compile_grep_patterns(struct grep_opt *opt)\n     - \tif (opt->no_body_match && opt->pattern_expression)\n     - \t\topt->pattern_expression = grep_not_expr(opt->pattern_expression);\n     - \n     --\tif (!header_expr)\n     -+\tif (!header_expr || opt->header_or)\n     - \t\treturn;\n       \n       \tif (!opt->pattern_expression)\n     + \t\topt->pattern_expression = header_expr;\n     +-\telse if (opt->all_match)\n     ++\telse if (opt->all_match || opt->match_header_or_grep)\n     + \t\topt->pattern_expression = grep_splice_or(header_expr,\n     + \t\t\t\t\t\t\t opt->pattern_expression);\n     + \telse\n     +@@ grep.c: int grep_source(struct grep_opt *opt, struct grep_source *gs)\n     + \topt->body_hit = 0;\n     + \tgrep_source_1(opt, gs, 1);\n     + \n     +-\tif (opt->all_match && !chk_hit_marker(opt->pattern_expression))\n     ++\tif (!opt->match_header_or_grep && opt->all_match && !chk_hit_marker(opt->pattern_expression))\n     + \t\treturn 0;\n     + \tif (opt->no_body_match && opt->body_hit)\n     + \t\treturn 0;\n      \n       ## grep.h ##\n      @@ grep.h: struct grep_opt {\n       \tint count;\n       \tint word_regexp;\n       \tint all_match;\n     -+\tint header_or;\n     ++\tint match_header_or_grep;\n       \tint no_body_match;\n       \tint body_hit;\n       #define GREP_BINARY_DEFAULT\t0\n     @@ revision.c: static int handle_revision_opt(struct rev_info *revs, int argc, cons\n       \t\trevs->grep_filter.pattern_type_option = GREP_PATTERN_TYPE_PCRE;\n       \t} else if (!strcmp(arg, \"--all-match\")) {\n       \t\trevs->grep_filter.all_match = 1;\n     -+\t// @@@ must-fix: find a better name\n     -+\t} else if (!strcmp(arg, \"--header-or\")) {\n     -+\t\trevs->grep_filter.header_or = 1;\n     ++\t} else if (!strcmp(arg, \"--match-header-or-grep\")) {\n     ++\t\trevs->grep_filter.match_header_or_grep = 1;\n       \t} else if (!strcmp(arg, \"--invert-grep\")) {\n       \t\trevs->grep_filter.no_body_match = 1;\n       \t} else if ((argcount = parse_long_opt(\"encoding\", argv, &optarg))) {\n     @@ t/t7810-grep.sh: test_expect_success 'log --grep --author uses intersection' '\n       \ttest_cmp expect actual\n       '\n       \n     -+test_expect_success 'log --grep --author --header-or uses union' '\n     ++test_expect_success 'log --grep --author --match-header-or-grep uses union' '\n      +\t# grep matches only third and fourth\n      +\t# author matches only initial and third\n     -+\tgit log --author=\"A U Thor\" --grep=r --header-or --format=%s >actual &&\n     -+\t{\n     -+\t    echo fourth && echo third\n     -+\t} >expect &&\n     ++\tgit log --author=\"A U Thor\" --grep=r --match-header-or-grep --format=%s >actual &&\n     ++\ttest_write_lines fourth third initial >expect &&\n      +\ttest_cmp expect actual\n      +'\n     -+\n      +\n       test_expect_success 'log --grep --grep --author takes union of greps and intersects with author' '\n       \t# grep matches initial and second but not third\n       \t# author matches only initial and third\n     +@@ t/t7810-grep.sh: test_expect_success 'log --grep --grep --author takes union of greps and interse\n     + \ttest_cmp expect actual\n     + '\n     + \n     +-test_expect_success 'log ---all-match -grep --author --author still takes union of authors and intersects with grep' '\n     ++test_expect_success 'log --author --grep --grep --match-header-or-grep takes union of greps and author' '\n     ++\t# grep matches initial and second but not third\n     ++\t# author matches only initial and third\n     ++\tgit log --author=\"A U Thor\" --grep=second --grep=initial --match-header-or-grep --format=%s >actual &&\n     ++\ttest_write_lines third second initial >expect &&\n     ++\ttest_cmp expect actual\n     ++'\n     ++\n     ++test_expect_success 'log --author --grep --grep --all-match --match-header-or-grep still takes union of greps and author' '\n     ++\t# grep matches initial and second but not third\n     ++\t# author matches only initial and third\n     ++\tgit log --author=\"A U Thor\" --grep=second --grep=initial --all-match --match-header-or-grep --format=%s >actual &&\n     ++\ttest_write_lines third second initial >expect &&\n     ++\ttest_cmp expect actual\n     ++'\n     ++\n     ++test_expect_success 'log --all-match --grep --author --author still takes union of authors and intersects with grep' '\n     + \t# grep matches only initial and third\n     + \t# author matches all but second\n     + \tgit log --all-match --author=\"Thor\" --author=\"Night\" --grep=i --format=%s >actual &&\n\n\n Documentation/rev-list-options.txt     |  8 ++++++++\n contrib/completion/git-completion.bash |  2 +-\n grep.c                                 |  4 ++--\n grep.h                                 |  1 +\n revision.c                             |  2 ++\n t/t7810-grep.sh                        | 26 +++++++++++++++++++++++++-\n 6 files changed, 39 insertions(+), 4 deletions(-)\n\ndiff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt\nindex 00ccf687441..db0979ac498 100644\n--- a/Documentation/rev-list-options.txt\n+++ b/Documentation/rev-list-options.txt\n@@ -71,6 +71,14 @@ endif::git-rev-list[]\n \tLimit the commits output to ones that match all given `--grep`,\n \tinstead of ones that match at least one.\n \n+--match-header-or-grep::\n+\tLimit the commits output to ones that match either header patterns\n+\t(`--author`, `--committer`, or `--grep-reflog`) or `--grep`, instead\n+\tof ones that match both the header and grep patterns\n++\n+For example, `--author=me --grep=Co-authored-by: me` limits to commits either\n+authored or co-authored by me.\n+\n --invert-grep::\n \tLimit the commits output to ones with a log message that do not\n \tmatch the pattern specified with `--grep=<pattern>`.\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 75193ded4bd..30fc6ed08bd 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -2170,7 +2170,7 @@ __git_log_gitk_options=\"\n # Options that go well for log and shortlog (not gitk)\n __git_log_shortlog_options=\"\n \t--author= --committer= --grep=\n-\t--all-match --invert-grep\n+\t--all-match --invert-grep --match-header-or-grep\n \"\n # Options accepted by log and show\n __git_log_show_options=\"\ndiff --git a/grep.c b/grep.c\nindex ac34bfeafb3..72cf599660a 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -802,7 +802,7 @@ void compile_grep_patterns(struct grep_opt *opt)\n \n \tif (!opt->pattern_expression)\n \t\topt->pattern_expression = header_expr;\n-\telse if (opt->all_match)\n+\telse if (opt->all_match || opt->match_header_or_grep)\n \t\topt->pattern_expression = grep_splice_or(header_expr,\n \t\t\t\t\t\t\t opt->pattern_expression);\n \telse\n@@ -1829,7 +1829,7 @@ int grep_source(struct grep_opt *opt, struct grep_source *gs)\n \topt->body_hit = 0;\n \tgrep_source_1(opt, gs, 1);\n \n-\tif (opt->all_match && !chk_hit_marker(opt->pattern_expression))\n+\tif (!opt->match_header_or_grep && opt->all_match && !chk_hit_marker(opt->pattern_expression))\n \t\treturn 0;\n \tif (opt->no_body_match && opt->body_hit)\n \t\treturn 0;\ndiff --git a/grep.h b/grep.h\nindex 926c0875c42..861584dba98 100644\n--- a/grep.h\n+++ b/grep.h\n@@ -147,6 +147,7 @@ struct grep_opt {\n \tint count;\n \tint word_regexp;\n \tint all_match;\n+\tint match_header_or_grep;\n \tint no_body_match;\n \tint body_hit;\n #define GREP_BINARY_DEFAULT\t0\ndiff --git a/revision.c b/revision.c\nindex 7e45f765d9f..786c229f56d 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -2646,6 +2646,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg\n \t\trevs->grep_filter.pattern_type_option = GREP_PATTERN_TYPE_PCRE;\n \t} else if (!strcmp(arg, \"--all-match\")) {\n \t\trevs->grep_filter.all_match = 1;\n+\t} else if (!strcmp(arg, \"--match-header-or-grep\")) {\n+\t\trevs->grep_filter.match_header_or_grep = 1;\n \t} else if (!strcmp(arg, \"--invert-grep\")) {\n \t\trevs->grep_filter.no_body_match = 1;\n \t} else if ((argcount = parse_long_opt(\"encoding\", argv, &optarg))) {\ndiff --git a/t/t7810-grep.sh b/t/t7810-grep.sh\nindex 875dcfd98f3..c78ce150f4d 100755\n--- a/t/t7810-grep.sh\n+++ b/t/t7810-grep.sh\n@@ -961,6 +961,14 @@ test_expect_success 'log --grep --author uses intersection' '\n \ttest_cmp expect actual\n '\n \n+test_expect_success 'log --grep --author --match-header-or-grep uses union' '\n+\t# grep matches only third and fourth\n+\t# author matches only initial and third\n+\tgit log --author=\"A U Thor\" --grep=r --match-header-or-grep --format=%s >actual &&\n+\ttest_write_lines fourth third initial >expect &&\n+\ttest_cmp expect actual\n+'\n+\n test_expect_success 'log --grep --grep --author takes union of greps and intersects with author' '\n \t# grep matches initial and second but not third\n \t# author matches only initial and third\n@@ -971,7 +979,23 @@ test_expect_success 'log --grep --grep --author takes union of greps and interse\n \ttest_cmp expect actual\n '\n \n-test_expect_success 'log ---all-match -grep --author --author still takes union of authors and intersects with grep' '\n+test_expect_success 'log --author --grep --grep --match-header-or-grep takes union of greps and author' '\n+\t# grep matches initial and second but not third\n+\t# author matches only initial and third\n+\tgit log --author=\"A U Thor\" --grep=second --grep=initial --match-header-or-grep --format=%s >actual &&\n+\ttest_write_lines third second initial >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'log --author --grep --grep --all-match --match-header-or-grep still takes union of greps and author' '\n+\t# grep matches initial and second but not third\n+\t# author matches only initial and third\n+\tgit log --author=\"A U Thor\" --grep=second --grep=initial --all-match --match-header-or-grep --format=%s >actual &&\n+\ttest_write_lines third second initial >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'log --all-match --grep --author --author still takes union of authors and intersects with grep' '\n \t# grep matches only initial and third\n \t# author matches all but second\n \tgit log --all-match --author=\"Thor\" --author=\"Night\" --grep=i --format=%s >actual &&\n\nbase-commit: 7774cfed6261ce2900c84e55906da708c711d601\n-- \ngitgitgadget\n"},{"id":"492445","messageId":"xmqq4jcdhfht.fsf@gitster.g","threadId":"61275","inReplyTo":"pull.1710.v2.git.1712460247516.gitgitgadget@gmail.com","subject":"Re: [PATCH v2] log: add option to search for header or body","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-04-07T06:08:14Z","receivedAt":"2024-04-07T06:08:22Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Max Coplan via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n> This change adds a new option to `git log` that allows users to search\n> for commits that match either the author or the commit message. This is\n> useful for finding commits that were either authored or co-authored by a\n> specific person.\n\nI have this feeling that the \"solution\" presented is not quite\naddressing the use case in a more useful and direct way than it\ncould be.  When I designed how the --author/--committer restriction\nand --grep in the body of the message interact, I made a concious\ndecision that \"among those commits that were authored by person X,\nfind the ones that mention Y\" is far more useful than \"done by X, or\ndone by anybody that mention Y\", especially when Y is just a text\nsearch in the free form.  There was nothing that limits the mention\nof Y to those specifically involved in the commit---the mention could\njust have been part of text, like \"earlier Max Coplan sent a patch,\nbut this commit is not related to it\".\n\nBut these days, we have a more established \"convention\" that lists\npeople at the end in the form of \"trailers\", and that changes the\npicture quite a lot from how the world order was back then.\n\nIn other words, if the true objective is to find commits that\ninvolved person X, Y or Z (which is very common and would be a lot\nmore useful than finding those that involve all of them), shouldn't\nwe be limiting the --grep side even further so that a random mention\nof person Y is excluded and hit is counted only when person Y is\nmentioned on a trailer (while loosening the --author side so that it\nis OR'ed instead of AND'ed)?\n\nI am imagining a pair of new options to name people (all OR'ed) and\nto name places the names of these people should appear (again, all\nOR'ed).  I am not good at naming, so the option names in the example\nis not more than illustration of an idea and not my recommendation,\nbut a command:\n\n    git log --by=\"Max Coplan\" --by=\"Junio C Hamano\" \\\n\t    --by-where=author,Signed-off-by,Co-authored-by\n\nwould find a commit that has one (or more) of the given names\nin one (or more) of the places that are specified, where the places\ncan be either \"author\", \"committer\" to specify these headers in the\ncommit object, or random other string to specify trailer lines with\ngiven keys.\n\nHmm?\n"},{"id":"492462","messageId":"0bad6e79-42c6-4149-92f0-58c4726080b1@gmail.com","threadId":"61275","inReplyTo":"xmqq4jcdhfht.fsf@gitster.g","subject":"Re: [PATCH v2] log: add option to search for header or body","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2024-04-07T14:00:27Z","receivedAt":"2024-04-07T14:00:30Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"On 07/04/2024 07:08, Junio C Hamano wrote:\n> \"Max Coplan via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n> I am imagining a pair of new options to name people (all OR'ed) and\n> to name places the names of these people should appear (again, all\n> OR'ed).  I am not good at naming, so the option names in the example\n> is not more than illustration of an idea and not my recommendation,\n> but a command:\n> \n>      git log --by=\"Max Coplan\" --by=\"Junio C Hamano\" \\\n> \t    --by-where=author,Signed-off-by,Co-authored-by\n> \n> would find a commit that has one (or more) of the given names\n> in one (or more) of the places that are specified, where the places\n> can be either \"author\", \"committer\" to specify these headers in the\n> commit object, or random other string to specify trailer lines with\n> given keys.\n\nI like this, yesterday[1] I didn't have a clear idea in my head of how \nsuch an option should work but I think passing the names and the fields \nto match those names against as two separate options is a good idea.\n\nBest Wishes\n\nPhillip\n\n[1] \nhttps://lore.kernel.org/git/c93817ba-5945-4ec0-9775-5621481b972c@gmail.com/\n"}]}