{"thread":{"id":"59518","subject":"macOS git grep change in required character classes","startedAt":"2023-04-01T15:50:44Z","lastAt":"2023-04-01T17:56:15Z","messageCount":4,"participants":["Matt Gardner","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"474629","messageId":"CA+MNPvgceR3s30LaCS716NGw+8S47CQZTqFno=vE2XAuiBA7Kw@mail.gmail.com","threadId":"59518","inReplyTo":null,"subject":"macOS git grep change in required character classes","fromName":"Matt Gardner","fromEmail":"four712@gmail.com","sentAt":"2023-04-01T15:50:28Z","receivedAt":"2023-04-01T15:50:44Z","isPatch":false,"sender":{"key":"four712@gmail.com","avatar":null},"body":"Thank you for filling out a Git bug report!\n\nPlease answer the following questions to help us understand your issue.\n\nWhat did you do before the bug happened? (Steps to reproduce your issue)\n\n$ mkdir git-grep-test\n$ cd git-grep-test\n$ git init\n$ echo \"sub test { return; }\" > test.pl\n$ git grep --untracked -E \\\\btest\\\\b\n\nWhat did you expect to happen? (Expected behavior)\n\nIt should find the results like the following:\n\ntest.pl:sub test { return; }\n\nWhat happened instead? (Actual behavior)\n\nNo results found\n\nWhat's different between what you expected and what actually happened?\n\nTo get results, you have to use BSD style character classes:\n\n$ git grep --untracked -E \\[\\[:\\<:\\]\\]test\\[\\[:\\>:\\]\\]\n\ntest.pl:sub test { return; }\n\nAnything else you want to add:\n\nTesting in both git 2.24 and 2.34 (the only other version I have\naccess to at the moment), \\\\b and other GNU style character classes\nreturn results.\n\nMy best guess is that\nhttps://github.com/git/git/commit/1819ad327b7a1f19540a819813b70a0e8a7f798f\nis causing git grep -E to require BSD style regular expression\ncharacter classes.  I don't know if this is a bug or an unadvertised\nchange in behavior.  In either case, it is frustrating.  Any person or\ntool would have to know which version of git they have and which\noperating system they are on to get results.\n\nPlease review the rest of the bug report below.\n\nYou can delete any lines you don't wish to share.\n[System Info]\ngit version:\ngit version 2.40.0\ncpu: x86_64\nno commit associated with this build\nsizeof-long: 8\nsizeof-size_t: 8\nshell-path: /bin/sh\nfeature: fsmonitor--daemon\nuname: Darwin 19.6.0 Darwin Kernel Version 19.6.0: Tue Jun 21 21:18:39\nPDT 2022; root:xnu-6153.141.66~1/RELEASE_X86_64 x86_64\ncompiler info: clang: 12.0.0 (clang-1200.0.32.29)\nlibc info: no libc information available\n$SHELL (typically, interactive shell): /bin/bash\n\n\n[Enabled Hooks]\n"},{"id":"474631","messageId":"xmqqa5zrbmap.fsf@gitster.g","threadId":"59518","inReplyTo":"CA+MNPvgceR3s30LaCS716NGw+8S47CQZTqFno=vE2XAuiBA7Kw@mail.gmail.com","subject":"Re: macOS git grep change in required character classes","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-04-01T16:27:10Z","receivedAt":"2023-04-01T16:27:21Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Matt Gardner <four712@gmail.com> writes:\n\n> My best guess is that\n> https://github.com/git/git/commit/1819ad327b7a1f19540a819813b70a0e8a7f798f\n> is causing git grep -E to require BSD style regular expression\n> character classes.  I don't know if this is a bug or an unadvertised\n> change in behavior.\n\nI think you diagnosed it correctly.  The story is \"Once upon a time,\nwe declared that the regex library of macOS is so broken and\nunusable.  We used a fallback definition to work it around, but\nunfortunately the fallback library did not support multi-byte\nmatching correctly, which made some folks on macOS unhappy.  So we\nlet Git built with the regex library shipped with macOS starting\nthat commit, with one side effect that patterns you would feed Git\non that platform would behave more like patterns you give to other\ntools on the platform.\"\n\nSo, it is not a bug in Git, it is a deliberate change in behaviour\nwith unintended consequences X-<.\n\n"},{"id":"474632","messageId":"CA+MNPvg9JX8S2fOcH9NEq=d04BcCgbf5Qwc070WWwjXpUsd3Sw@mail.gmail.com","threadId":"59518","inReplyTo":"xmqqa5zrbmap.fsf@gitster.g","subject":"Re: macOS git grep change in required character classes","fromName":"Matt Gardner","fromEmail":"four712@gmail.com","sentAt":"2023-04-01T17:17:03Z","receivedAt":"2023-04-01T17:17:18Z","isPatch":false,"sender":{"key":"four712@gmail.com","avatar":null},"body":"Even though the grep that ships with macOS is GNU compatible?\n\n$ which grep\n/usr/bin/grep\n$ grep -V\ngrep (BSD grep) 2.5.1-FreeBSD\n$ grep -E \\\\btest\\\\b test.pl\nsub test { return; }\n\nSo, it isn't quite true that it makes it like other tools, especially\nthe most analogous tool, grep itself.\n\nI think it would be a reasonable expectation that git grep and system\ngrep behave in the same manner.\n\nOn Sat, Apr 1, 2023 at 12:27 PM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Matt Gardner <four712@gmail.com> writes:\n>\n> > My best guess is that\n> > https://github.com/git/git/commit/1819ad327b7a1f19540a819813b70a0e8a7f798f\n> > is causing git grep -E to require BSD style regular expression\n> > character classes.  I don't know if this is a bug or an unadvertised\n> > change in behavior.\n>\n> I think you diagnosed it correctly.  The story is \"Once upon a time,\n> we declared that the regex library of macOS is so broken and\n> unusable.  We used a fallback definition to work it around, but\n> unfortunately the fallback library did not support multi-byte\n> matching correctly, which made some folks on macOS unhappy.  So we\n> let Git built with the regex library shipped with macOS starting\n> that commit, with one side effect that patterns you would feed Git\n> on that platform would behave more like patterns you give to other\n> tools on the platform.\"\n>\n> So, it is not a bug in Git, it is a deliberate change in behaviour\n> with unintended consequences X-<.\n>\n"},{"id":"474633","messageId":"xmqq355jbi6d.fsf@gitster.g","threadId":"59518","inReplyTo":"CA+MNPvg9JX8S2fOcH9NEq=d04BcCgbf5Qwc070WWwjXpUsd3Sw@mail.gmail.com","subject":"Re: macOS git grep change in required character classes","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-04-01T17:56:10Z","receivedAt":"2023-04-01T17:56:15Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Matt Gardner <four712@gmail.com> writes:\n\n> Even though the grep that ships with macOS is GNU compatible?\n>\n> $ which grep\n> /usr/bin/grep\n> $ grep -V\n> grep (BSD grep) 2.5.1-FreeBSD\n> $ grep -E \\\\btest\\\\b test.pl\n> sub test { return; }\n\nIt seems that use of REG_ENHANCED bit (which gives some GNUism\nenhancement to regex engine of BSD origin) is inconsistent even\namong tools shipped by Apple,\n\ncf. https://lore.kernel.org/git/4e03ea47-b0aa-d69e-6c54-fcbadb3b0641@web.de/\n\nwhich may even contribute to the confusion.\n\nI think we recently (of course this is after we stopped doing\nNO_REGEX and switched to macOS native regex library) started using\nthe ENHANCED bit only for BRE and we do not use ENHANCED bit for\nERE, and the cited thread (which has \"pcre\" on the subject, but it\nturns out that the symptom had nothing to do with pcre) discussed\npossible use of the same enhanced bit for ERE by us.\n"}]}