{"thread":{"id":"58708","subject":"Potential bug in --color-words output","startedAt":"2022-10-28T21:09:10Z","lastAt":"2022-11-10T13:51:54Z","messageCount":4,"participants":["Simeon Krastnikov","Stefan Beller","Johannes Sixt","Johannes Schindelin"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"465982","messageId":"e2164b04-98de-6f19-6c33-6979c1a328ff@gmail.com","threadId":"58708","inReplyTo":null,"subject":"Potential bug in --color-words output","fromName":"Simeon Krastnikov","fromEmail":"skrastnikov@gmail.com","sentAt":"2022-10-28T21:08:09Z","receivedAt":"2022-10-28T21:09:10Z","isPatch":false,"sender":{"key":"skrastnikov@gmail.com","avatar":null},"body":"Hello,\n\nGiven an initial file with the contents \"not to be\", which I then change \nto \"to be\", the output of 'git diff --color-words', is\n\n   notto be\n\nwith the first three letters colored red. To me this seems incorrect as \nit implies, or at least misleadingly suggests, that there was no space \nbetween \"not\" and \"to\" in the original file. (Even though in that case \nthe output is actually \"nottoto be\" with the \"notto\" in red and \"to\" in \ngreen.)\n\nIf instead I start with a file with contents \"to be\", which I then \nchange to \"not to be\", then the output is as expected:\n\n   not to be\n\n(First three letters colored green.)\n\nAm I correct in seeing this as a bug? If so, any tips on what parts of \ndiff.c to look at when starting a patch?\n\nThanks,\n\nSimeon\n\n"},{"id":"466768","messageId":"CALbm-EagU-kDg5wDO2z1canSifq0fo+hOqf8Xz1gAzbUO4COrQ@mail.gmail.com","threadId":"58708","inReplyTo":"198be0ca-4768-d3ce-caf3-bce4b1bb1e49@gmail.com","subject":"Re: Potential bug in --color-words output","fromName":"Stefan Beller","fromEmail":"stefanbeller@gmail.com","sentAt":"2022-11-07T23:23:00Z","receivedAt":"2022-11-07T23:23:15Z","isPatch":false,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Hi,\n\nin my copy of git there is:\n\n----\ngit % git grep --line-number --no-color  color-words\n\nDocumentation/RelNotes/1.5.4.txt:377: * \"git diff --color-words\"\ncolored context lines in a wrong color.\n\nDocumentation/RelNotes/1.6.2.txt:100:* The definition of what\nconstitutes a word for \"git diff --color-words\"\n\nDocumentation/RelNotes/1.6.5.3.txt:23: * \"git diff --color-words -U0\"\ndidn't work correctly.\n\nDocumentation/RelNotes/1.7.2.txt:64: * \"git diff --word-diff=<mode>\"\nextends the existing \"--color-words\"\n\nDocumentation/RelNotes/1.7.2.txt:141: * \"git diff --graph\" works\nbetter with \"--color-words\" and other options\n\nDocumentation/diff-options.txt:475:--color-words[=<regex>]::\n\ncontrib/completion/git-completion.bash:1718:\n--no-color --color-words --no-renames --check\n\ncontrib/diff-highlight/README:9:You can use \"--color-words\" to\nhighlight only the changed portions of\n\ndiff.c:1914: * '--color-words' algorithm can be described as:\n\ndiff.c:1929: * For '--graph' to work with '--color-words', we need to\noutput the graph prefix\n\ndiff.c:2138:/* In \"color-words\" mode, show word-diff of words\naccumulated in the buffer */\n\ndiff.c:5566:            OPT_CALLBACK_F(0, \"color-words\", options, N_(\"<regex>\"),\n\ngitk-git/gitk:207:            \"--color-words*\" - \"--word-diff=color\" {\n\nt/t4034-diff-words.sh:70:               word_diff --color-words\n\nt/t4034-diff-words.sh:100:      word_diff --color-words &&\n\nt/t4034-diff-words.sh:180:      word_diff --color-words --unified=0\n\nt/t4034-diff-words.sh:185:      word_diff --color-words=\"[a-z]+\"\n\nt/t4034-diff-words.sh:190:      word_diff --color-words=\"[a-z${LF}]*\"\n\nt/t4034-diff-words.sh:203:      word_diff --color-words=\"[a-z]+\"\n\nt/t4034-diff-words.sh:208:      word_diff --color-words\n\nt/t4034-diff-words.sh:217:      word_diff --color-words=\"[a-z]+\"\n\nt/t4034-diff-words.sh:240:      word_diff --color-words\n\nt/t4034-diff-words.sh:262:      word_diff --color-words\n\nt/t4034-diff-words.sh:278:      word_diff --color-words=\"a+\"\n\nt/t4034-diff-words.sh:294:      word_diff --color-words=.\n----\n\n\nSo there are tests in t/t4034-diff-words.sh and probably around\ndiff.c:1914- diff.c:2138\n\nBest,\nStefan\n\n\nAm Mo., 7. Nov. 2022 um 12:43 Uhr schrieb Simeon Krastnikov\n<skrastnikov@gmail.com>:\n>\n> Hi Junio, Phillip, and Stefan,\n>\n> I apologize for forwarding this to you personally, but based on the recent commit history, I figured that you would be the right persons to ask about this.\n>\n> Sorry again, if you consider this to be spam.\n>\n> Best,\n>\n> Simeon\n>\n>\n>\n> -------- Forwarded Message --------\n> Subject: Potential bug in --color-words output\n> Date: Fri, 28 Oct 2022 23:08:09 +0200\n> From: Simeon Krastnikov <skrastnikov@gmail.com>\n> To: git@vger.kernel.org\n>\n>\n> Hello,\n>\n> Given an initial file with the contents \"not to be\", which I then change to \"to be\", the output of 'git diff --color-words', is\n>\n>   notto be\n>\n> with the first three letters colored red. To me this seems incorrect as it implies, or at least misleadingly suggests, that there was no space between \"not\" and \"to\" in the original file. (Even though in that case the output is actually \"nottoto be\" with the \"notto\" in red and \"to\" in green.)\n>\n> If instead I start with a file with contents \"to be\", which I then change to \"not to be\", then the output is as expected:\n>\n>   not to be\n>\n> (First three letters colored green.)\n>\n> Am I correct in seeing this as a bug? If so, any tips on what parts of diff.c to look at when starting a patch?\n>\n> Thanks,\n>\n> Simeon\n>\n"},{"id":"466791","messageId":"628833cf-3537-bf8a-0a1a-9ade1bec39a1@kdbg.org","threadId":"58708","inReplyTo":"e2164b04-98de-6f19-6c33-6979c1a328ff@gmail.com","subject":"Re: Potential bug in --color-words output","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2022-11-08T07:27:38Z","receivedAt":"2022-11-08T07:27:46Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 28.10.22 um 23:08 schrieb Simeon Krastnikov:\n> Hello,\n> \n> Given an initial file with the contents \"not to be\", which I then change\n> to \"to be\", the output of 'git diff --color-words', is\n> \n>   notto be\n> \n> with the first three letters colored red. To me this seems incorrect as\n> it implies, or at least misleadingly suggests, that there was no space\n> between \"not\" and \"to\" in the original file. (Even though in that case\n> the output is actually \"nottoto be\" with the \"notto\" in red and \"to\" in\n> green.)\n> \n> If instead I start with a file with contents \"to be\", which I then\n> change to \"not to be\", then the output is as expected:\n> \n>   not to be\n> \n> (First three letters colored green.)\n> \n> Am I correct in seeing this as a bug? If so, any tips on what parts of\n> diff.c to look at when starting a patch?\n\nWell, not really. When you have a file with\n\n   Line one.\n   Line two.\n\nthen change it to\n\n   Line ONE.\n   Line TWO.\n\nthen --color-words currently prints it as\n\n   Line one.ONE.\n   Line two.TWO.\n\nbecause it does not print the whitespace after[*] a sequence of deleted\nwords. But if it were printed, we would see\n\n   Line one.\n   ONE.\n   Line two.\n   TWO.\n\nThat is considered inferior; hence, it isn't printed.\n\nThe current algorithm produces sensible output in the vast majority of\ncases while also being fairly straight-forward. To make it work \"better\"\n(for some definition of that word) in the borderline cases, the\nalgorithm would have to be made considerably more sophisticated.\n\n[*] It might be whitespace before a sequence of words, but that does not\nchange the gist of the argument.\n\n-- Hannes\n\n"},{"id":"467044","messageId":"39so8720-p05o-9qns-1o8o-q783271n40os@tzk.qr","threadId":"58708","inReplyTo":"e2164b04-98de-6f19-6c33-6979c1a328ff@gmail.com","subject":"Re: Potential bug in --color-words output","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2022-11-10T13:51:45Z","receivedAt":"2022-11-10T13:51:54Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Simeon,\n\nOn Fri, 28 Oct 2022, Simeon Krastnikov wrote:\n\n> Given an initial file with the contents \"not to be\", which I then change to\n> \"to be\", the output of 'git diff --color-words', is\n>\n>   notto be\n>\n> with the first three letters colored red.\n\nThis seems to be a limitation of the original `--color-words` design.\n\nFWIW I find myself using these three aliases all the time now, i.e. using\na different word-coloring mode that works much better for me:\n\n\t[alias]\n\t\tcwdiff = diff --color-words=\\\"[A-Za-z0-9_]+|.\\\"\n\t        cwlog = log --color-words=\\\"[A-Za-z0-9_]+|.\\\"\n\t\tcwshow = show --color-words=\\\"[A-Za-z0-9_]+|.\\\"\n\nExplanation: the regex `[A-Za-z0-9_]+|.` treats runs of alphanumerical\ncharacters (including the underscore) as words, and also treats any\nindividual characters that do not fall into that category as \"words\".\n\nThe only downside of this is that the coloring does not help identifying\nwhite-space differences because only the foreground color is changed\n(which does not result in any visible difference for white-space\ncharacters).\n\nMaybe these aliases help you, too?\n\nCiao,\nJohannes\n"}]}