{"thread":{"id":"54668","subject":"[BUG?] \"git config --replace-all key value value_regex\" ignores value_regex?","startedAt":"2020-11-18T18:07:34Z","lastAt":"2020-11-18T20:28:38Z","messageCount":4,"participants":["Derrick Stolee","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"410250","messageId":"466ee1d8-efaa-fc91-f3d9-230672289ffb@gmail.com","threadId":"54668","inReplyTo":null,"subject":"[BUG?] \"git config --replace-all key value value_regex\" ignores value_regex?","fromName":"Derrick Stolee","fromEmail":"stolee@gmail.com","sentAt":"2020-11-18T18:07:29Z","receivedAt":"2020-11-18T18:07:34Z","isPatch":false,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"As discussed [1], I am working on relaxing the \"regex\" part of the\nvalue_regex parameter in the \"git config\" command.\n\n[1] https://lore.kernel.org/git/xmqqlfez6alb.fsf@gitster.c.googlers.com/\n\nAs I am working to solidify how this command works, I'm adding tests\nfor all of the compatible options that could use a \"--literal-value\"\nmodifier. One that seemed helpful to use was \"--replace-all\". The\ndocs have this line in the SYNOPSIS:\n\n'git config' [<file-option>] [--type=<type>] [--literal-value] --replace-all name value [value_regex]\n\nand this in the OPTIONS:\n\n--replace-all::\n\tDefault behavior is to replace at most one line. This replaces\n\tall lines matching the key (and optionally the value_regex).\n\nHowever, this test fails:\n\ntest_expect_success '--replace-all and value_regex' '\n\tq_to_tab >.git/config <<-\\EOF &&\n\t[abc]\n\tQkey = one\n\tQkey = two\n\tQkey = three\n\tEOF\n\tq_to_tab >expect <<-\\EOF &&\n\t[abc]\n\tQkey = four\n\tQkey = two\n\tQkey = three\n\tEOF\n\tgit config --replace-all abc.key four \"o*\" &&\n\ttest_cmp expect .git/config\n'\n\nThe end result is that _all_ existing values are removed in\nfavor of one final result of abc.key=four.\n\nIs this the intended behavior? It seems like value_regex is completely\nignored instead of actually performing a function here. The only\nmailing list reference I can find include a doc update [2] and the original\nimplementation from 2005 [3].\n\n[2] https://lore.kernel.org/git/alpine.LFD.2.21.1805300733440.10096@localhost.localdomain/\n[3] https://lore.kernel.org/git/Pine.LNX.4.63.0511200650130.12832@wbgn013.biozentrum.uni-wuerzburg.de/\n\nIf it is _not_ the intended behavior, then would a fix to make my test\npass be appropriate? If anyone is currently specifying a value_regex\nto this command, then the behavior would change in surprising ways.\nHowever, it seems that they would get the same behavior without using\nvalue_regex.\n\nThanks,\n-Stolee\n"},{"id":"410260","messageId":"xmqqo8ju1ooc.fsf@gitster.c.googlers.com","threadId":"54668","inReplyTo":"466ee1d8-efaa-fc91-f3d9-230672289ffb@gmail.com","subject":"Re: [BUG?] \"git config --replace-all key value value_regex\" ignores value_regex?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-11-18T18:54:11Z","receivedAt":"2020-11-18T18:54:40Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Derrick Stolee <stolee@gmail.com> writes:\n\n> --replace-all::\n> \tDefault behavior is to replace at most one line. This replaces\n> \tall lines matching the key (and optionally the value_regex).\n>\n> However, this test fails:\n>\n> test_expect_success '--replace-all and value_regex' '\n> \tq_to_tab >.git/config <<-\\EOF &&\n> \t[abc]\n> \tQkey = one\n> \tQkey = two\n> \tQkey = three\n> \tEOF\n> \tq_to_tab >expect <<-\\EOF &&\n> \t[abc]\n> \tQkey = four\n> \tQkey = two\n> \tQkey = three\n> \tEOF\n> \tgit config --replace-all abc.key four \"o*\" &&\n> \ttest_cmp expect .git/config\n> '\n\nI do not know or try to guess the original intention (I thought this\nis Dscho's thing, no?), but if there are one/two/three and I were\nasked to replace all of those that have zero or more 'o' in it with\n'four' I would expect that\n\n (1) all three be removed, because they all have zero or more 'o',\n     and then\n\n (2) one instance of 'four' be added,\n\nresulting in a single 'four' left.\n\nIf the value_regex were \"o+\" (since it takes ERE) to mean one or\nmore, then my expectation would be\n\n (1) one and two be removed, because 'three' does not match, and\n     then\n\n (2) one instance of 'four' be added,\n\nresulting in two items, 'three' and 'four'.\n\nAn alternative interpretation would be that each of the removed\nentries is replaced with a new one, resulting in three entries\n(i.e. with \"o*\", it would leave three identical entries 'four',\nwith \"o+\", it would leave 'four', 'four' and 'three'), but that\nmay be less useful in practice.\n\n"},{"id":"410267","messageId":"c7dfbd1b-44bc-d074-5ec9-1011738c1522@gmail.com","threadId":"54668","inReplyTo":"xmqqo8ju1ooc.fsf@gitster.c.googlers.com","subject":"Re: [BUG?] \"git config --replace-all key value value_regex\" ignores value_regex?","fromName":"Derrick Stolee","fromEmail":"stolee@gmail.com","sentAt":"2020-11-18T19:42:37Z","receivedAt":"2020-11-18T19:42:42Z","isPatch":false,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"On 11/18/2020 1:54 PM, Junio C Hamano wrote:\n> Derrick Stolee <stolee@gmail.com> writes:\n> \n>> --replace-all::\n>> \tDefault behavior is to replace at most one line. This replaces\n>> \tall lines matching the key (and optionally the value_regex).\n>>\n>> However, this test fails:\n>>\n>> test_expect_success '--replace-all and value_regex' '\n>> \tq_to_tab >.git/config <<-\\EOF &&\n>> \t[abc]\n>> \tQkey = one\n>> \tQkey = two\n>> \tQkey = three\n>> \tEOF\n>> \tq_to_tab >expect <<-\\EOF &&\n>> \t[abc]\n>> \tQkey = four\n>> \tQkey = two\n>> \tQkey = three\n>> \tEOF\n>> \tgit config --replace-all abc.key four \"o*\" &&\n>> \ttest_cmp expect .git/config\n>> '\n> \n> I do not know or try to guess the original intention (I thought this\n> is Dscho's thing, no?), but if there are one/two/three and I were\n> asked to replace all of those that have zero or more 'o' in it with\n> 'four' I would expect that\n> \n>  (1) all three be removed, because they all have zero or more 'o',\n>      and then\n> \n>  (2) one instance of 'four' be added,\n> \n> resulting in a single 'four' left.\n>\n> If the value_regex were \"o+\" (since it takes ERE) to mean one or\n> more, then my expectation would be\n> \n>  (1) one and two be removed, because 'three' does not match, and\n>      then\n> \n>  (2) one instance of 'four' be added,\n> \n> resulting in two items, 'three' and 'four'.\n> \n> An alternative interpretation would be that each of the removed\n> entries is replaced with a new one, resulting in three entries\n> (i.e. with \"o*\", it would leave three identical entries 'four',\n> with \"o+\", it would leave 'four', 'four' and 'three'), but that\n> may be less useful in practice.\n\nThank you. Naturally, PEBKAC and my lack of understanding the\nregex I was using in my own test. Clearly this is behaving\ncorrectly. Modifying as suggested shows this works properly.\n\nThanks,\n-Stolee\n\n \n\n"},{"id":"410271","messageId":"xmqq8say1kbq.fsf@gitster.c.googlers.com","threadId":"54668","inReplyTo":"c7dfbd1b-44bc-d074-5ec9-1011738c1522@gmail.com","subject":"Re: [BUG?] \"git config --replace-all key value value_regex\" ignores value_regex?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-11-18T20:28:09Z","receivedAt":"2020-11-18T20:28:38Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Derrick Stolee <stolee@gmail.com> writes:\n\n>>> test_expect_success '--replace-all and value_regex' '\n>>> \tq_to_tab >.git/config <<-\\EOF &&\n>>> \t[abc]\n>>> \tQkey = one\n>>> \tQkey = two\n>>> \tQkey = three\n>>> \tEOF\n>>> \tq_to_tab >expect <<-\\EOF &&\n>>> \t[abc]\n>>> \tQkey = four\n>>> \tQkey = two\n>>> \tQkey = three\n>>> \tEOF\n>>> \tgit config --replace-all abc.key four \"o*\" &&\n>>> \ttest_cmp expect .git/config\n>>> '\n>> ...\n> Thank you. Naturally, PEBKAC and my lack of understanding the\n> regex I was using in my own test. Clearly this is behaving\n> correctly. Modifying as suggested shows this works properly.\n\nIt is an easy confusion.\n\nWhen I see a pattern, especially a single letter followed by an\nasterisk like \"o*\", my eyes take it as a glob pattern that is left\nanchored, i.e. \"any string that begins with an 'o'\", and if that\nwere the matching rule, what you expected is totally the natural\noutcome.  But here we unfortunately are looking at ERE.\n\n"}]}