threads / patch / 55206

patch, 2 partsremote: add camel-cased *.tagOpt key, like clone

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

## tl;dr

8 messages between Feb 25, 2021 and Mar 18, 2021. Diffs are folded; open one to read it.

replies: 7people: 3as markdown or json

Ævar Arnfjörð Bjarmason· Feb 25, 2021, 01:21 UTC · lore

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(-)
Show changes to 3 files +3 −1

builtin/remote.c, t/t5505-remote.sh, t/t5612-clone-refspec.sh

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
 	) &&
-- 
2.30.0.284.gd98b1dd5eaa7
Ævar Arnfjörð Bjarmason· Feb 25, 2021, 01:21 UTC · re: Ævar Arnfjörð Bjarmason · lore

[PATCH 2/2] remote: write camel-cased *.pushRemote on rename

When a remote is renamed don't change the canonical "*.pushRemote" form to "*.pushremote". Fixes and tests for a minor bug in 923d4a5ca4f (remote rename/remove: handle branch.<name>.pushRemote config values, 2020-01-27). See the preceding commit for why this does & doesn't matter.

While we're at it let's also test that we handle the "*.pushDefault" key correctly. The code to handle that was added in b3fd6cbf294 (remote rename/remove: gently handle remote.pushDefault config, 2020-02-01) and does the right thing, but nothing tested that we wrote out the canonical camel-cased form.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 builtin/remote.c  | 2 +-
 t/t5505-remote.sh | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)
Show changes to 2 files +3 −1

builtin/remote.c, t/t5505-remote.sh

diff --git a/builtin/remote.c b/builtin/remote.c
index f286ae97538..717b662d455 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -746,7 +746,7 @@ static int mv(int argc, const char **argv)
 		}
 		if (info->push_remote_name && !strcmp(info->push_remote_name, rename.old_name)) {
 			strbuf_reset(&buf);
-			strbuf_addf(&buf, "branch.%s.pushremote", item->string);
+			strbuf_addf(&buf, "branch.%s.pushRemote", item->string);
 			git_config_set(buf.buf, rename.new_name);
 		}
 	}
diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh
index 2a7b5cd00a0..34fc3fa421f 100755
--- a/t/t5505-remote.sh
+++ b/t/t5505-remote.sh
@@ -757,6 +757,7 @@ test_expect_success 'rename a remote' '
 		cd four &&
 		git config branch.main.pushRemote origin &&
 		git remote rename origin upstream &&
+		grep "pushRemote" .git/config &&
 		test -z "$(git for-each-ref refs/remotes/origin)" &&
 		test "$(git symbolic-ref refs/remotes/upstream/HEAD)" = "refs/remotes/upstream/main" &&
 		test "$(git rev-parse upstream/main)" = "$(git rev-parse main)" &&
@@ -773,6 +774,7 @@ test_expect_success 'rename a remote renames repo remote.pushDefault' '
 		cd four.1 &&
 		git config remote.pushDefault origin &&
 		git remote rename origin upstream &&
+		grep pushDefault .git/config &&
 		test "$(git config --local remote.pushDefault)" = "upstream"
 	)
 '
-- 
2.30.0.284.gd98b1dd5eaa7
Junio C Hamano· Feb 25, 2021, 03:17 UTC · re: Ævar Arnfjörð Bjarmason · lore

Re: [PATCH 2/2] remote: write camel-cased *.pushRemote on rename

Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
Show 51 quoted lines
> When a remote is renamed don't change the canonical "*.pushRemote"
> form to "*.pushremote". Fixes and tests for a minor bug in
> 923d4a5ca4f (remote rename/remove: handle branch.<name>.pushRemote
> config values, 2020-01-27). See the preceding commit for why this does
> & doesn't matter.
>
> While we're at it let's also test that we handle the "*.pushDefault"
> key correctly. The code to handle that was added in
> b3fd6cbf294 (remote rename/remove: gently handle remote.pushDefault
> config, 2020-02-01) and does the right thing, but nothing tested that
> we wrote out the canonical camel-cased form.
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>  builtin/remote.c  | 2 +-
>  t/t5505-remote.sh | 2 ++
>  2 files changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/builtin/remote.c b/builtin/remote.c
> index f286ae97538..717b662d455 100644
> --- a/builtin/remote.c
> +++ b/builtin/remote.c
> @@ -746,7 +746,7 @@ static int mv(int argc, const char **argv)
>  		}
>  		if (info->push_remote_name && !strcmp(info->push_remote_name, rename.old_name)) {
>  			strbuf_reset(&buf);
> -			strbuf_addf(&buf, "branch.%s.pushremote", item->string);
> +			strbuf_addf(&buf, "branch.%s.pushRemote", item->string);
>  			git_config_set(buf.buf, rename.new_name);
>  		}
>  	}
> diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh
> index 2a7b5cd00a0..34fc3fa421f 100755
> --- a/t/t5505-remote.sh
> +++ b/t/t5505-remote.sh
> @@ -757,6 +757,7 @@ test_expect_success 'rename a remote' '
>  		cd four &&
>  		git config branch.main.pushRemote origin &&
>  		git remote rename origin upstream &&
> +		grep "pushRemote" .git/config &&
>  		test -z "$(git for-each-ref refs/remotes/origin)" &&
>  		test "$(git symbolic-ref refs/remotes/upstream/HEAD)" = "refs/remotes/upstream/main" &&
>  		test "$(git rev-parse upstream/main)" = "$(git rev-parse main)" &&
> @@ -773,6 +774,7 @@ test_expect_success 'rename a remote renames repo remote.pushDefault' '
>  		cd four.1 &&
>  		git config remote.pushDefault origin &&
>  		git remote rename origin upstream &&
> +		grep pushDefault .git/config &&
>  		test "$(git config --local remote.pushDefault)" = "upstream"
>  	)
>  '

Again, good find, but I am not sure if we want the test to be so strict. Besides, quoting one and not quoting the other in the same patch looks the test is also being inconsistent ;-).

Thanks.
Bert Wesarg· Mar 18, 2021, 11:22 UTC · re: Ævar Arnfjörð Bjarmason · lore

Re: [PATCH 2/2] remote: write camel-cased *.pushRemote on rename

On Thu, Feb 25, 2021 at 2:21 AM Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:

Show 13 quoted lines
>
> When a remote is renamed don't change the canonical "*.pushRemote"
> form to "*.pushremote". Fixes and tests for a minor bug in
> 923d4a5ca4f (remote rename/remove: handle branch.<name>.pushRemote
> config values, 2020-01-27). See the preceding commit for why this does
> & doesn't matter.
>
> While we're at it let's also test that we handle the "*.pushDefault"
> key correctly. The code to handle that was added in
> b3fd6cbf294 (remote rename/remove: gently handle remote.pushDefault
> config, 2020-02-01) and does the right thing, but nothing tested that
> we wrote out the canonical camel-cased form.
>
Fine with me.
Thanks.
Show 42 quoted lines
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>  builtin/remote.c  | 2 +-
>  t/t5505-remote.sh | 2 ++
>  2 files changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/builtin/remote.c b/builtin/remote.c
> index f286ae97538..717b662d455 100644
> --- a/builtin/remote.c
> +++ b/builtin/remote.c
> @@ -746,7 +746,7 @@ static int mv(int argc, const char **argv)
>                 }
>                 if (info->push_remote_name && !strcmp(info->push_remote_name, rename.old_name)) {
>                         strbuf_reset(&buf);
> -                       strbuf_addf(&buf, "branch.%s.pushremote", item->string);
> +                       strbuf_addf(&buf, "branch.%s.pushRemote", item->string);
>                         git_config_set(buf.buf, rename.new_name);
>                 }
>         }
> diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh
> index 2a7b5cd00a0..34fc3fa421f 100755
> --- a/t/t5505-remote.sh
> +++ b/t/t5505-remote.sh
> @@ -757,6 +757,7 @@ test_expect_success 'rename a remote' '
>                 cd four &&
>                 git config branch.main.pushRemote origin &&
>                 git remote rename origin upstream &&
> +               grep "pushRemote" .git/config &&
>                 test -z "$(git for-each-ref refs/remotes/origin)" &&
>                 test "$(git symbolic-ref refs/remotes/upstream/HEAD)" = "refs/remotes/upstream/main" &&
>                 test "$(git rev-parse upstream/main)" = "$(git rev-parse main)" &&
> @@ -773,6 +774,7 @@ test_expect_success 'rename a remote renames repo remote.pushDefault' '
>                 cd four.1 &&
>                 git config remote.pushDefault origin &&
>                 git remote rename origin upstream &&
> +               grep pushDefault .git/config &&
>                 test "$(git config --local remote.pushDefault)" = "upstream"
>         )
>  '
> --
> 2.30.0.284.gd98b1dd5eaa7
>
Junio C Hamano· Feb 25, 2021, 03:02 UTC · re: Ævar Arnfjörð Bjarmason · lore

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

Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
Show 43 quoted lines
> 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.
Show 24 quoted lines
> 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, 03:16 UTC · re: Ævar Arnfjörð Bjarmason · lore

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

Æ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, ...
Show 11 quoted lines
> 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, 19:47 UTC · re: Junio C Hamano · lore

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

On Thu, Feb 25 2021, Junio C Hamano wrote:
Show 36 quoted lines
> Æ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...
Show 17 quoted lines
>> 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, 20:00 UTC · re: Ævar Arnfjörð Bjarmason · lore

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

Æ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").

← back to recent threads