git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / Atom feed
* [BUG?] "git config --replace-all key value value_regex" ignores value_regex?
@ 2020-11-18 18:07 Derrick Stolee
  2020-11-18 18:54 ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Derrick Stolee @ 2020-11-18 18:07 UTC (permalink / raw)
  To: Git List; +Cc: Johannes Schindelin, Jeff King, Junio C Hamano, Emily Shaffer

As discussed [1], I am working on relaxing the "regex" part of the
value_regex parameter in the "git config" command.

[1] https://lore.kernel.org/git/xmqqlfez6alb.fsf@gitster.c.googlers.com/

As I am working to solidify how this command works, I'm adding tests
for all of the compatible options that could use a "--literal-value"
modifier. One that seemed helpful to use was "--replace-all". The
docs have this line in the SYNOPSIS:

'git config' [<file-option>] [--type=<type>] [--literal-value] --replace-all name value [value_regex]

and this in the OPTIONS:

--replace-all::
	Default behavior is to replace at most one line. This replaces
	all lines matching the key (and optionally the value_regex).

However, this test fails:

test_expect_success '--replace-all and value_regex' '
	q_to_tab >.git/config <<-\EOF &&
	[abc]
	Qkey = one
	Qkey = two
	Qkey = three
	EOF
	q_to_tab >expect <<-\EOF &&
	[abc]
	Qkey = four
	Qkey = two
	Qkey = three
	EOF
	git config --replace-all abc.key four "o*" &&
	test_cmp expect .git/config
'

The end result is that _all_ existing values are removed in
favor of one final result of abc.key=four.

Is this the intended behavior? It seems like value_regex is completely
ignored instead of actually performing a function here. The only
mailing list reference I can find include a doc update [2] and the original
implementation from 2005 [3].

[2] https://lore.kernel.org/git/alpine.LFD.2.21.1805300733440.10096@localhost.localdomain/
[3] https://lore.kernel.org/git/Pine.LNX.4.63.0511200650130.12832@wbgn013.biozentrum.uni-wuerzburg.de/

If it is _not_ the intended behavior, then would a fix to make my test
pass be appropriate? If anyone is currently specifying a value_regex
to this command, then the behavior would change in surprising ways.
However, it seems that they would get the same behavior without using
value_regex.

Thanks,
-Stolee

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [BUG?] "git config --replace-all key value value_regex" ignores value_regex?
  2020-11-18 18:07 [BUG?] "git config --replace-all key value value_regex" ignores value_regex? Derrick Stolee
@ 2020-11-18 18:54 ` Junio C Hamano
  2020-11-18 19:42   ` Derrick Stolee
  0 siblings, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2020-11-18 18:54 UTC (permalink / raw)
  To: Derrick Stolee; +Cc: Git List, Johannes Schindelin, Jeff King, Emily Shaffer

Derrick Stolee <stolee@gmail.com> writes:

> --replace-all::
> 	Default behavior is to replace at most one line. This replaces
> 	all lines matching the key (and optionally the value_regex).
>
> However, this test fails:
>
> test_expect_success '--replace-all and value_regex' '
> 	q_to_tab >.git/config <<-\EOF &&
> 	[abc]
> 	Qkey = one
> 	Qkey = two
> 	Qkey = three
> 	EOF
> 	q_to_tab >expect <<-\EOF &&
> 	[abc]
> 	Qkey = four
> 	Qkey = two
> 	Qkey = three
> 	EOF
> 	git config --replace-all abc.key four "o*" &&
> 	test_cmp expect .git/config
> '

I do not know or try to guess the original intention (I thought this
is Dscho's thing, no?), but if there are one/two/three and I were
asked to replace all of those that have zero or more 'o' in it with
'four' I would expect that

 (1) all three be removed, because they all have zero or more 'o',
     and then

 (2) one instance of 'four' be added,

resulting in a single 'four' left.

If the value_regex were "o+" (since it takes ERE) to mean one or
more, then my expectation would be

 (1) one and two be removed, because 'three' does not match, and
     then

 (2) one instance of 'four' be added,

resulting in two items, 'three' and 'four'.

An alternative interpretation would be that each of the removed
entries is replaced with a new one, resulting in three entries
(i.e. with "o*", it would leave three identical entries 'four',
with "o+", it would leave 'four', 'four' and 'three'), but that
may be less useful in practice.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [BUG?] "git config --replace-all key value value_regex" ignores value_regex?
  2020-11-18 18:54 ` Junio C Hamano
@ 2020-11-18 19:42   ` Derrick Stolee
  2020-11-18 20:28     ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Derrick Stolee @ 2020-11-18 19:42 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git List, Johannes Schindelin, Jeff King, Emily Shaffer

On 11/18/2020 1:54 PM, Junio C Hamano wrote:
> Derrick Stolee <stolee@gmail.com> writes:
> 
>> --replace-all::
>> 	Default behavior is to replace at most one line. This replaces
>> 	all lines matching the key (and optionally the value_regex).
>>
>> However, this test fails:
>>
>> test_expect_success '--replace-all and value_regex' '
>> 	q_to_tab >.git/config <<-\EOF &&
>> 	[abc]
>> 	Qkey = one
>> 	Qkey = two
>> 	Qkey = three
>> 	EOF
>> 	q_to_tab >expect <<-\EOF &&
>> 	[abc]
>> 	Qkey = four
>> 	Qkey = two
>> 	Qkey = three
>> 	EOF
>> 	git config --replace-all abc.key four "o*" &&
>> 	test_cmp expect .git/config
>> '
> 
> I do not know or try to guess the original intention (I thought this
> is Dscho's thing, no?), but if there are one/two/three and I were
> asked to replace all of those that have zero or more 'o' in it with
> 'four' I would expect that
> 
>  (1) all three be removed, because they all have zero or more 'o',
>      and then
> 
>  (2) one instance of 'four' be added,
> 
> resulting in a single 'four' left.
>
> If the value_regex were "o+" (since it takes ERE) to mean one or
> more, then my expectation would be
> 
>  (1) one and two be removed, because 'three' does not match, and
>      then
> 
>  (2) one instance of 'four' be added,
> 
> resulting in two items, 'three' and 'four'.
> 
> An alternative interpretation would be that each of the removed
> entries is replaced with a new one, resulting in three entries
> (i.e. with "o*", it would leave three identical entries 'four',
> with "o+", it would leave 'four', 'four' and 'three'), but that
> may be less useful in practice.

Thank you. Naturally, PEBKAC and my lack of understanding the
regex I was using in my own test. Clearly this is behaving
correctly. Modifying as suggested shows this works properly.

Thanks,
-Stolee

 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [BUG?] "git config --replace-all key value value_regex" ignores value_regex?
  2020-11-18 19:42   ` Derrick Stolee
@ 2020-11-18 20:28     ` Junio C Hamano
  0 siblings, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2020-11-18 20:28 UTC (permalink / raw)
  To: Derrick Stolee; +Cc: Git List, Johannes Schindelin, Jeff King, Emily Shaffer

Derrick Stolee <stolee@gmail.com> writes:

>>> test_expect_success '--replace-all and value_regex' '
>>> 	q_to_tab >.git/config <<-\EOF &&
>>> 	[abc]
>>> 	Qkey = one
>>> 	Qkey = two
>>> 	Qkey = three
>>> 	EOF
>>> 	q_to_tab >expect <<-\EOF &&
>>> 	[abc]
>>> 	Qkey = four
>>> 	Qkey = two
>>> 	Qkey = three
>>> 	EOF
>>> 	git config --replace-all abc.key four "o*" &&
>>> 	test_cmp expect .git/config
>>> '
>> ...
> Thank you. Naturally, PEBKAC and my lack of understanding the
> regex I was using in my own test. Clearly this is behaving
> correctly. Modifying as suggested shows this works properly.

It is an easy confusion.

When I see a pattern, especially a single letter followed by an
asterisk like "o*", my eyes take it as a glob pattern that is left
anchored, i.e. "any string that begins with an 'o'", and if that
were the matching rule, what you expected is totally the natural
outcome.  But here we unfortunately are looking at ERE.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-11-18 20:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-18 18:07 [BUG?] "git config --replace-all key value value_regex" ignores value_regex? Derrick Stolee
2020-11-18 18:54 ` Junio C Hamano
2020-11-18 19:42   ` Derrick Stolee
2020-11-18 20:28     ` Junio C Hamano

git@vger.kernel.org list mirror (unofficial, one of many)

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 git git/ https://public-inbox.org/git \
		git@vger.kernel.org
	public-inbox-index git

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.io/gmane.comp.version-control.git
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for the project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git