diff mbox series

[1/2] remote: add camel-cased *.tagOpt key, like clone

Message ID 20210225012117.17331-1-avarab@gmail.com (mailing list archive)
State Accepted
Commit bfa9148ff7df2ee5213c6467e3410ba134591178
Headers show
Series [1/2] remote: add camel-cased *.tagOpt key, like clone | expand

Commit Message

Ævar Arnfjörð Bjarmason Feb. 25, 2021, 1:21 a.m. UTC
Change "git remote add" so that it adds a *.tagOpt key, and not the
lower-cased *.tagopt on "git remote add --no-tags", just as "git clone
--no-tags" would do.

This doesn't matter for anything that reads the config. It's just
prettier if we write config keys in their documented camelCase form to
user-readable config files.

When I added support for "clone -no-tags" in 0dab2468ee5 (clone: add a
--no-tags option to clone without tags, 2017-04-26) I made it use
the *.tagOpt form, but the older "git remote add" added in
111fb858654 (remote add: add a --[no-]tags option, 2010-04-20) has
been using *.tagopt all this time.

It's easy enough to add a test for this, so let's do that. We can't
use "git config -l" there, because it'll normalize the keys to their
lower-cased form. Let's add the test for "git clone" too for good
measure, not just to the "git remote" codepath we're fixing.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---

I also noticed that we write e.g. init.objectformat instead of
init.objectFormat, and core.logallrefupdates etc. If anyone's got an
even even worse case of OCD there's an interesting #leftoverbits
project there of scouring the code for more cases of this sort of
thing...

 builtin/remote.c         | 2 +-
 t/t5505-remote.sh        | 1 +
 t/t5612-clone-refspec.sh | 1 +
 3 files changed, 3 insertions(+), 1 deletion(-)

Comments

Junio C Hamano Feb. 25, 2021, 3:02 a.m. UTC | #1
Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:

> Change "git remote add" so that it adds a *.tagOpt key, and not the
> lower-cased *.tagopt on "git remote add --no-tags", just as "git clone
> --no-tags" would do.
>
> This doesn't matter for anything that reads the config. It's just
> prettier if we write config keys in their documented camelCase form to
> user-readable config files.
>
> When I added support for "clone -no-tags" in 0dab2468ee5 (clone: add a
> --no-tags option to clone without tags, 2017-04-26) I made it use
> the *.tagOpt form, but the older "git remote add" added in
> 111fb858654 (remote add: add a --[no-]tags option, 2010-04-20) has
> been using *.tagopt all this time.
>
> It's easy enough to add a test for this, so let's do that. We can't
> use "git config -l" there, because it'll normalize the keys to their
> lower-cased form. Let's add the test for "git clone" too for good
> measure, not just to the "git remote" codepath we're fixing.
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>
> I also noticed that we write e.g. init.objectformat instead of
> init.objectFormat, and core.logallrefupdates etc. If anyone's got an
> even even worse case of OCD there's an interesting #leftoverbits
> project there of scouring the code for more cases of this sort of
> thing...
>
>  builtin/remote.c         | 2 +-
>  t/t5505-remote.sh        | 1 +
>  t/t5612-clone-refspec.sh | 1 +
>  3 files changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/builtin/remote.c b/builtin/remote.c
> index d11a5589e49..f286ae97538 100644
> --- a/builtin/remote.c
> +++ b/builtin/remote.c
> @@ -221,7 +221,7 @@ static int add(int argc, const char **argv)
>  
>  	if (fetch_tags != TAGS_DEFAULT) {
>  		strbuf_reset(&buf);
> -		strbuf_addf(&buf, "remote.%s.tagopt", name);
> +		strbuf_addf(&buf, "remote.%s.tagOpt", name);

Good find.

A general rule for a name used to refer to a configuration variable
the C code ought to be

 - if it is used to match what the system gave us, make sure we use
   all lowercase for the first and the last component and match with
   strcmp(), not with strcasecmp().

 - if it is used to update, make sure we use the canonical spelling,
   if only for the documentation value.

> diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh
> index 045398b94e6..2a7b5cd00a0 100755
> --- a/t/t5505-remote.sh
> +++ b/t/t5505-remote.sh
> @@ -594,6 +594,7 @@ test_expect_success 'add --no-tags' '
>  		cd add-no-tags &&
>  		git init &&
>  		git remote add -f --no-tags origin ../one &&
> +		grep tagOpt .git/config &&
>  		git tag -l some-tag >../test/output &&
>  		git tag -l foobar-tag >../test/output &&
>  		git config remote.origin.tagopt >>../test/output
> diff --git a/t/t5612-clone-refspec.sh b/t/t5612-clone-refspec.sh
> index 6a6af7449ca..3126cfd7e9d 100755
> --- a/t/t5612-clone-refspec.sh
> +++ b/t/t5612-clone-refspec.sh
> @@ -97,6 +97,7 @@ test_expect_success 'by default no tags will be kept updated' '
>  test_expect_success 'clone with --no-tags' '
>  	(
>  		cd dir_all_no_tags &&
> +		grep tagOpt .git/config &&
>  		git fetch &&
>  		git for-each-ref refs/tags >../actual
>  	) &&
Junio C Hamano Feb. 25, 2021, 3:16 a.m. UTC | #2
Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:

> It's easy enough to add a test for this, so let's do that. We can't
> use "git config -l" there, because it'll normalize the keys to their
> lower-cased form.

I wondered if we want "git config -l --preserve-case" or something
like that, but an extra grep for "tagOpt" would be sufficient in a
simple test like these that are unlikely to have unrelated tagOpt
defined in the file.  More importantly, I am starting to doubt if
this should even be tested.

If there were existing "section.varname" variable definition and we
ask

	git_config_set("section.varName", "newvalue");

we may end up with "[section] varname = newvalue", and that is
perfectly OK, I would think, because the first and the last
component of the configuration variable names are defined to be case
insensitive, and here may be "[Section] varname = oldvalue" in the
configuration file before we try to set it, and the implementation
is free to replace "oldvalue" with "newvalue", instead of first
removing "[Section] varname = oldvalue" and then adding a new
"[section] varName = newvalue" (after all, there may be variables
other than "varname" in the section, and the existing "[Section]"
header may need to be kept for the remaining variables while we futz
with the varname or varName).

Which means that while we do want to spell the names in our source
code correctly (i.e. "tagOpt", not "tagopt") when we tell which
variable we want to get modified to the git_config_set() function,
we should not care how exactly git_config_set() chooses to spell the
variable in the resulting configuration file, no?

So, ...

> diff --git a/t/t5612-clone-refspec.sh b/t/t5612-clone-refspec.sh
> index 6a6af7449ca..3126cfd7e9d 100755
> --- a/t/t5612-clone-refspec.sh
> +++ b/t/t5612-clone-refspec.sh
> @@ -97,6 +97,7 @@ test_expect_success 'by default no tags will be kept updated' '
>  test_expect_success 'clone with --no-tags' '
>  	(
>  		cd dir_all_no_tags &&
> +		grep tagOpt .git/config &&
>  		git fetch &&
>  		git for-each-ref refs/tags >../actual

...as long as "git config remote.origin.tagopt" yields what we
expect, we should be OK, I would think.  Insisting that the variable
name is kept by git_config_set() API may be expecting too much.

>  	) &&
Ævar Arnfjörð Bjarmason Feb. 25, 2021, 7:47 p.m. UTC | #3
On Thu, Feb 25 2021, Junio C Hamano wrote:

> Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
>
>> It's easy enough to add a test for this, so let's do that. We can't
>> use "git config -l" there, because it'll normalize the keys to their
>> lower-cased form.
>
> I wondered if we want "git config -l --preserve-case" or something
> like that, but an extra grep for "tagOpt" would be sufficient in a
> simple test like these that are unlikely to have unrelated tagOpt
> defined in the file.  More importantly, I am starting to doubt if
> this should even be tested.
>
> If there were existing "section.varname" variable definition and we
> ask
>
> 	git_config_set("section.varName", "newvalue");
>
> we may end up with "[section] varname = newvalue", and that is
> perfectly OK, I would think, because the first and the last
> component of the configuration variable names are defined to be case
> insensitive, and here may be "[Section] varname = oldvalue" in the
> configuration file before we try to set it, and the implementation
> is free to replace "oldvalue" with "newvalue", instead of first
> removing "[Section] varname = oldvalue" and then adding a new
> "[section] varName = newvalue" (after all, there may be variables
> other than "varname" in the section, and the existing "[Section]"
> header may need to be kept for the remaining variables while we futz
> with the varname or varName).
>
> Which means that while we do want to spell the names in our source
> code correctly (i.e. "tagOpt", not "tagopt") when we tell which
> variable we want to get modified to the git_config_set() function,
> we should not care how exactly git_config_set() chooses to spell the
> variable in the resulting configuration file, no?
>
> So, ...

Yes, in general, but...

>> diff --git a/t/t5612-clone-refspec.sh b/t/t5612-clone-refspec.sh
>> index 6a6af7449ca..3126cfd7e9d 100755
>> --- a/t/t5612-clone-refspec.sh
>> +++ b/t/t5612-clone-refspec.sh
>> @@ -97,6 +97,7 @@ test_expect_success 'by default no tags will be kept updated' '
>>  test_expect_success 'clone with --no-tags' '
>>  	(
>>  		cd dir_all_no_tags &&
>> +		grep tagOpt .git/config &&
>>  		git fetch &&
>>  		git for-each-ref refs/tags >../actual
>
> ...as long as "git config remote.origin.tagopt" yields what we
> expect, we should be OK, I would think.  Insisting that the variable
> name is kept by git_config_set() API may be expecting too much.
>
>>  	) &&

...the cases fixed in this series are not ones where we're possibly
changing an existing variable name, but where we're guaranteed to be
writing new values.

We are renaming a remote or otherwise moving variables around, if there
were existing values to contend with we'd have died earlier.

I'm not quite sure what to make of this feedback in general. That you'd
like the bugfix but we shouldn't bother with a regression test, or that
we shouldn't bother with the fix at all?

I admit this is getting to diminishing returns in testing, we're
unlikely to break this, and if we do it's not such a big deal.

But I don't agree that we should feel free to munge user config files
within the bound of valid config syntax when we edit these files for
users.

We already go out of our way to add values to existing sections, not add
new empty headings etc. (I believe the last major effort on that front
was from Johannes S. a while back).

likewise here, even though cmd.averylongvariablename is perfectly valid,
it's much more user friendly if we write/edit it as
cmd.AVeryLongVariableName.
Junio C Hamano Feb. 25, 2021, 8 p.m. UTC | #4
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:

> I'm not quite sure what to make of this feedback in general. That you'd
> like the bugfix but we shouldn't bother with a regression test, or that
> we shouldn't bother with the fix at all?

I like the style update to make the callers use the canonical case
(even though they do not have to), but the test that inspects the
cases in the resulting configuration file may be too strict.

> But I don't agree that we should feel free to munge user config files
> within the bound of valid config syntax when we edit these files for
> users.

I agree with your sentiment in principle.  I just wanted to make
sure that future test writers agree with the principle, and also
that they understand there are cases where end-user input may not
match the output (e.g. when running "git config Vari.Able value" to
an existing configuration file that has "[vari] ous = true", it may
be less desirable to add "[Vari] Able = value" than to add to the
existing "[Vari] section a new line "Able = value").
diff mbox series

Patch

diff --git a/builtin/remote.c b/builtin/remote.c
index d11a5589e49..f286ae97538 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -221,7 +221,7 @@  static int add(int argc, const char **argv)
 
 	if (fetch_tags != TAGS_DEFAULT) {
 		strbuf_reset(&buf);
-		strbuf_addf(&buf, "remote.%s.tagopt", name);
+		strbuf_addf(&buf, "remote.%s.tagOpt", name);
 		git_config_set(buf.buf,
 			       fetch_tags == TAGS_SET ? "--tags" : "--no-tags");
 	}
diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh
index 045398b94e6..2a7b5cd00a0 100755
--- a/t/t5505-remote.sh
+++ b/t/t5505-remote.sh
@@ -594,6 +594,7 @@  test_expect_success 'add --no-tags' '
 		cd add-no-tags &&
 		git init &&
 		git remote add -f --no-tags origin ../one &&
+		grep tagOpt .git/config &&
 		git tag -l some-tag >../test/output &&
 		git tag -l foobar-tag >../test/output &&
 		git config remote.origin.tagopt >>../test/output
diff --git a/t/t5612-clone-refspec.sh b/t/t5612-clone-refspec.sh
index 6a6af7449ca..3126cfd7e9d 100755
--- a/t/t5612-clone-refspec.sh
+++ b/t/t5612-clone-refspec.sh
@@ -97,6 +97,7 @@  test_expect_success 'by default no tags will be kept updated' '
 test_expect_success 'clone with --no-tags' '
 	(
 		cd dir_all_no_tags &&
+		grep tagOpt .git/config &&
 		git fetch &&
 		git for-each-ref refs/tags >../actual
 	) &&