{"thread":{"id":"61108","subject":"[PATCH 0/1] log: make the --oneline option work with -L","startedAt":"2024-03-13T09:08:54Z","lastAt":"2024-03-13T22:47:24Z","messageCount":7,"participants":["James Liu","Junio C Hamano","Beat Bolli"],"isPatch":true,"patchVersion":1,"patchTotal":1},"messages":[{"id":"490533","messageId":"20240313090841.36717-1-james@jamesliu.io","threadId":"61108","inReplyTo":null,"subject":"[PATCH 0/1] log: make the --oneline option work with -L","fromName":"James Liu","fromEmail":"james@jamesliu.io","sentAt":"2024-03-13T09:08:40Z","receivedAt":"2024-03-13T09:08:54Z","isPatch":true,"sender":{"key":"james@jamesliu.io","avatar":"https://avatars.githubusercontent.com/u/4476568?v=4"},"body":"Hey folks,\n\nThis is a small patch to fix an issue I've experienced with git-log(1)\nwhen certain combinations of flags are provided. This is also my very\nfirst patch submission, so I've tried to limit the blast radius as much\nas possible. I'm also unsure if this is the best place to implement the\nchange, so any feedback is welcome!\n\nI'd like to ideally add a test as well, but I'm unsure where this should\nslot in.\n\ngit-log accepts the --oneline option to display the short commit SHA and\ntitle only. This is a convenient option when searching through Git\nhistory, as it gives a rough idea of the changes introduced in each\ncommit. git-log also accepts the -L flag, which lets us provide a line\nrange for a given file. This is handy for limiting the search to a given\narea of interest.\n\nHowever, when --oneline is used in combination with -L, Git actually\noutputs the single line commit information _as well_ as the full diff.\nFor example:\n\n        git log --oneline -L 660:Documentation/MyFirstObjectWalk.txt\n\nwill incorrectly display the diffs too.\n\nThis patch aims to fix this behaviour by respecting the --oneline option\nwhen used in conjunction with -L.\n\nJames Liu (1):\n  log: ensure diffs are omitted with --oneline\n\n builtin/log.c | 4 ++++\n 1 file changed, 4 insertions(+)\n\n-- \n2.43.2\n\n"},{"id":"490534","messageId":"20240313090841.36717-2-james@jamesliu.io","threadId":"61108","inReplyTo":"20240313090841.36717-1-james@jamesliu.io","subject":"[PATCH 1/1] log: ensure diffs are omitted with --oneline","fromName":"James Liu","fromEmail":"james@jamesliu.io","sentAt":"2024-03-13T09:08:41Z","receivedAt":"2024-03-13T09:09:00Z","isPatch":true,"sender":{"key":"james@jamesliu.io","avatar":"https://avatars.githubusercontent.com/u/4476568?v=4"},"body":"Currently when `git log --oneline` is invoked with the -L flag, the\nfull diffs are displayed along with the single line commit message.\nIt appears that within the log_tree_commit() function, the special\ncase that executes when opt->line_level_traverse is enabled (as in\nthe case when -L is provided) doesn't respect the --oneline option.\n\nEnsure the --oneline option is respected by explicitly setting\nDIFF_FORMAT_NO_OUTPUT if required.\n\nSigned-off-by: James Liu <james@jamesliu.io>\n---\n builtin/log.c | 4 ++++\n 1 file changed, 4 insertions(+)\n\ndiff --git a/builtin/log.c b/builtin/log.c\nindex e5da0d1043..dd77ede00c 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -279,6 +279,10 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,\n \t\trev->diffopt.output_format |= DIFF_FORMAT_NO_OUTPUT;\n \targc = setup_revisions(argc, argv, rev, opt);\n \n+\t/* Ensure that we don't output diffs if the --oneline flag is provided */\n+\tif (rev->commit_format == CMIT_FMT_ONELINE)\n+\t\trev->diffopt.output_format |= DIFF_FORMAT_NO_OUTPUT;\n+\n \t/* Any arguments at this point are not recognized */\n \tif (argc > 1)\n \t\tdie(_(\"unrecognized argument: %s\"), argv[1]);\n-- \n2.43.2\n\n"},{"id":"490555","messageId":"xmqqr0geca36.fsf@gitster.g","threadId":"61108","inReplyTo":"20240313090841.36717-1-james@jamesliu.io","subject":"Re: [PATCH 0/1] log: make the --oneline option work with -L","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-03-13T17:31:25Z","receivedAt":"2024-03-13T17:31:28Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"James Liu <james@jamesliu.io> writes:\n\n> git-log accepts the --oneline option to display the short commit SHA and\n> title only. This is a convenient option when searching through Git\n> history, as it gives a rough idea of the changes introduced in each\n> commit. git-log also accepts the -L flag, which lets us provide a line\n> range for a given file. This is handy for limiting the search to a given\n> area of interest.\n>\n> However, when --oneline is used in combination with -L, Git actually\n> outputs the single line commit information _as well_ as the full diff.\n> For example:\n>\n>         git log --oneline -L 660:Documentation/MyFirstObjectWalk.txt\n>\n> will incorrectly display the diffs too.\n\nWhy is it incorrect?\n\n * \"git log\" takes options to tweak formatting of the commit log,\n   options to tweak what commits are chosen, and options to tweak\n   how the diff are shown.\n\n * \"--oneline\" tweaks how the log message gets shown.  Others in the\n   family are --pretty=fuller, --format='%h %s', etc.\n\n * \"-L\" tweaks how the diff gets shown (e.g. limits which part of\n   the diff is shown) and what commits are shown (e.g. limits to\n   commits that touch the specified area).\n\nSo, just like \"git log -L <range>:<file>\" shows the commit log for\neach commit that touches the specified area of the file, followed by\nthe diff that shows how the commit modified the range, it is natural\nto expect \"git log --oneline -L <range>:<file>\" to show the same diff\nafter showing the commit log for these commits in the specified format,\nnamely, with just a one-line description.\n\nIt is not limited to \"-L\"; \"git log --oneline -p\" is expected to\nshow the patch after a one-line description for the commit.\n\n"},{"id":"490565","messageId":"a675ab4d-7dde-4630-9de6-970f05225271@drbeat.li","threadId":"61108","inReplyTo":"xmqqr0geca36.fsf@gitster.g","subject":"Re: [PATCH 0/1] log: make the --oneline option work with -L","fromName":"Beat Bolli","fromEmail":"dev+git@drbeat.li","sentAt":"2024-03-13T18:08:18Z","receivedAt":"2024-03-13T18:08:22Z","isPatch":true,"sender":{"key":"dev+git@drbeat.li","avatar":"https://avatars.githubusercontent.com/u/21444?v=4"},"body":"On 13.03.24 18:31, Junio C Hamano wrote:\n> James Liu <james@jamesliu.io> writes:\n> \n>> git-log accepts the --oneline option to display the short commit SHA and\n>> title only. This is a convenient option when searching through Git\n>> history, as it gives a rough idea of the changes introduced in each\n>> commit. git-log also accepts the -L flag, which lets us provide a line\n>> range for a given file. This is handy for limiting the search to a given\n>> area of interest.\n>>\n>> However, when --oneline is used in combination with -L, Git actually\n>> outputs the single line commit information _as well_ as the full diff.\n>> For example:\n>>\n>>          git log --oneline -L 660:Documentation/MyFirstObjectWalk.txt\n>>\n>> will incorrectly display the diffs too.\n> \n> Why is it incorrect?\n> \n>   * \"git log\" takes options to tweak formatting of the commit log,\n>     options to tweak what commits are chosen, and options to tweak\n>     how the diff are shown.\n> \n>   * \"--oneline\" tweaks how the log message gets shown.  Others in the\n>     family are --pretty=fuller, --format='%h %s', etc.\n> \n>   * \"-L\" tweaks how the diff gets shown (e.g. limits which part of\n>     the diff is shown) and what commits are shown (e.g. limits to\n>     commits that touch the specified area).\n> \n> So, just like \"git log -L <range>:<file>\" shows the commit log for\n> each commit that touches the specified area of the file, followed by\n> the diff that shows how the commit modified the range, it is natural\n> to expect \"git log --oneline -L <range>:<file>\" to show the same diff\n> after showing the commit log for these commits in the specified format,\n> namely, with just a one-line description.\n> \n> It is not limited to \"-L\"; \"git log --oneline -p\" is expected to\n> show the patch after a one-line description for the commit.\n> \n\nThere's also \"--no-patch\" to suppress the patch. It combines well with \n\"--oneline\".\n\n-- \nCheers, Beat\n\n"},{"id":"490586","messageId":"CZSZ38DTWF14.3BNXFKTGVPLZQ@jamesliu.io","threadId":"61108","inReplyTo":"xmqqr0geca36.fsf@gitster.g","subject":"Re: [PATCH 0/1] log: make the --oneline option work with -L","fromName":"James Liu","fromEmail":"james@jamesliu.io","sentAt":"2024-03-13T22:24:22Z","receivedAt":"2024-03-13T22:24:28Z","isPatch":true,"sender":{"key":"james@jamesliu.io","avatar":"https://avatars.githubusercontent.com/u/4476568?v=4"},"body":"On Thu Mar 14, 2024 at 4:31 AM AEDT, Junio C Hamano wrote:\n> James Liu <james@jamesliu.io> writes:\n>\n> > However, when --oneline is used in combination with -L, Git actually\n> > outputs the single line commit information _as well_ as the full diff.\n> > For example:\n> >\n> >         git log --oneline -L 660:Documentation/MyFirstObjectWalk.txt\n> >\n> > will incorrectly display the diffs too.\n>\n> Why is it incorrect?\n>\n>  * \"git log\" takes options to tweak formatting of the commit log,\n>    options to tweak what commits are chosen, and options to tweak\n>    how the diff are shown.\n>\n>  * \"--oneline\" tweaks how the log message gets shown.  Others in the\n>    family are --pretty=fuller, --format='%h %s', etc.\n>\n>  * \"-L\" tweaks how the diff gets shown (e.g. limits which part of\n>    the diff is shown) and what commits are shown (e.g. limits to\n>    commits that touch the specified area).\n\nI suppose it isn't intuitive to me which options affect how the commits\nare presented, and which affect the diffs. The help entry for -L states\nthat it will \"Trace the evolution of the line range\", which doesn't\nimmediately suggest that it tweaks how the log message is shown. As a\nuser of this option, I'm more interested in using it as a filter for how\ncommits are chosen.\n\n-S feels like a similar option to -L, but will omit the diff when used\nwith --oneline. I think I was probably experimenting with \"--oneline -S\"\nand then was surprised to see diffs after trying \"--oneline -L\".\n\n"},{"id":"490587","messageId":"CZSZ4481T8CO.1QJYPPDQ24TS7@jamesliu.io","threadId":"61108","inReplyTo":"a675ab4d-7dde-4630-9de6-970f05225271@drbeat.li","subject":"Re: [PATCH 0/1] log: make the --oneline option work with -L","fromName":"James Liu","fromEmail":"james@jamesliu.io","sentAt":"2024-03-13T22:25:31Z","receivedAt":"2024-03-13T22:25:36Z","isPatch":true,"sender":{"key":"james@jamesliu.io","avatar":"https://avatars.githubusercontent.com/u/4476568?v=4"},"body":"On Thu Mar 14, 2024 at 5:08 AM AEDT, Beat Bolli wrote:\n\n> There's also \"--no-patch\" to suppress the patch. It combines well with \n> \"--oneline\".\n\nThanks! That's a good one to keep handy.\n"},{"id":"490591","messageId":"xmqqfrwt696y.fsf@gitster.g","threadId":"61108","inReplyTo":"CZSZ38DTWF14.3BNXFKTGVPLZQ@jamesliu.io","subject":"Re: [PATCH 0/1] log: make the --oneline option work with -L","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-03-13T22:47:17Z","receivedAt":"2024-03-13T22:47:24Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"James Liu\" <james@jamesliu.io> writes:\n\n> I suppose it isn't intuitive to me which options affect how the commits\n> are presented, and which affect the diffs. The help entry for -L states\n> that it will \"Trace the evolution of the line range\", which doesn't\n> immediately suggest that it tweaks how the log message is shown.\n\nSorry, but you lost me.  I do not understand this remark.\n\nThe documentation for \"-L\" does not talk about tweaking how the\nmessage is shown at all, because \"-L\" does not have a say in how the\nlog message gets shown at all.  And the documentation for\n\"--oneline\", \"--format\", \"--pretty\" all should talk about how the\nlog message gets shown.\n\nAnyway, if you are happy with \"--no-patch\", that's good.\n"}]}