All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] git-remote: load config whenever create_symref() might be called
@ 2020-12-26 13:44 Jérémie Detrey
  2020-12-26 21:52 ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: Jérémie Detrey @ 2020-12-26 13:44 UTC (permalink / raw)
  To: git
  Cc: Shulhan, Brandon Williams, Johannes Schindelin, Junio C Hamano,
	Jérémie Detrey

Currently, the calls to `create_symref()` do not honor the
`core.logAllRefUpdates` nor the `user.{name,email}` configuration
settings, and therefore write reflogs even when explicitly asked not
to, and ignore the configured user identity.

This happens on `git remote add --fetch`, `git remote set-head`, and
`git remote rename`: these are the three commands which may create
a symbolic-ref for the remote's HEAD.

A call to `git_config(git_default_config, NULL);` for these three
commands is enough to load the necessary configuration beforehand.

The call to `git_config()` was inserted right after command-line
processing for these three commands. One might also decide to push
it closer to the actual call to `create_symref()`, as it is not
needed elsewhere, but it made more sense not to have it buried into
nested `if` conditions.

Signed-off-by: Jérémie Detrey <Jeremie.Detrey@altu.fr>
---
 builtin/remote.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/builtin/remote.c b/builtin/remote.c
index 64b4b551eb..f797fc3f65 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -190,6 +190,8 @@ static int add(int argc, const char **argv)
 	name = argv[0];
 	url = argv[1];
 
+	git_config(git_default_config, NULL);
+
 	remote = remote_get(name);
 	if (remote_is_configured(remote, 1))
 		die(_("remote %s already exists."), name);
@@ -685,6 +687,8 @@ static int mv(int argc, const char **argv)
 	rename.new_name = argv[2];
 	rename.remote_branches = &remote_branches;
 
+	git_config(git_default_config, NULL);
+
 	oldremote = remote_get(rename.old_name);
 	if (!remote_is_configured(oldremote, 1))
 		die(_("No such remote: '%s'"), rename.old_name);
@@ -1326,6 +1330,8 @@ static int set_head(int argc, const char **argv)
 	if (argc)
 		strbuf_addf(&buf, "refs/remotes/%s/HEAD", argv[0]);
 
+	git_config(git_default_config, NULL);
+
 	if (!opt_a && !opt_d && argc == 2) {
 		head_name = xstrdup(argv[1]);
 	} else if (opt_a && !opt_d && argc == 1) {
-- 
2.29.2


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

* Re: [PATCH] git-remote: load config whenever create_symref() might be called
  2020-12-26 13:44 [PATCH] git-remote: load config whenever create_symref() might be called Jérémie Detrey
@ 2020-12-26 21:52 ` Junio C Hamano
  2020-12-26 22:28   ` Jérémie Detrey
  0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2020-12-26 21:52 UTC (permalink / raw)
  To: Jérémie Detrey
  Cc: git, Shulhan, Brandon Williams, Johannes Schindelin

Jérémie Detrey <Jeremie.Detrey@altu.fr> writes:

> Currently, the calls to `create_symref()` do not honor the
> `core.logAllRefUpdates` nor the `user.{name,email}` configuration
> settings, and therefore write reflogs even when explicitly asked not
> to, and ignore the configured user identity.
>
> This happens on `git remote add --fetch`, `git remote set-head`, and
> `git remote rename`: these are the three commands which may create
> a symbolic-ref for the remote's HEAD.

Good problem description.

The usual way we structure the program start-up is do things in the
following order:

 - have the hard-coded built-in default in the form of file-scope
   static variable definition with initial values; remote.c::value
   is an example that by default we are not verbose unless anybody
   else (below) says otherwise.

 - call git_config() to read and set configured defaults, which
   would override the hard-coded built-in default values.

 - call parse_options(), or other use some other means, to parse the
   command line options to further override the values that may have
   been set by reading the configuration files.

My gut feeling says that the best place to call git_config() on
git_default_config would actually be in cmd_remote(), immediately
before we call parse_options() to parse the main options shared by
all subcommands of "git remote".  Is there a reason why codepaths
other than the three you singled out should *not* be affected by the
basic set of configuration variables?

Thanks.

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

* Re: [PATCH] git-remote: load config whenever create_symref() might be called
  2020-12-26 21:52 ` Junio C Hamano
@ 2020-12-26 22:28   ` Jérémie Detrey
  2020-12-27  0:34     ` Eric Sunshine
  0 siblings, 1 reply; 5+ messages in thread
From: Jérémie Detrey @ 2020-12-26 22:28 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Shulhan, Brandon Williams, Johannes Schindelin

Hi,

Thanks for the feedback!

Junio C Hamano:
> My gut feeling says that the best place to call git_config() on
> git_default_config would actually be in cmd_remote(), immediately
> before we call parse_options() to parse the main options shared by
> all subcommands of "git remote".  Is there a reason why codepaths
> other than the three you singled out should *not* be affected by the
> basic set of configuration variables?

No, none that I can think of. I'll leave more knowledgeable people
than me confirm this, but if that's the way to go, I'll be happy to
submit a revised patch following your suggestion :)

Cheers,
Jérémie.

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

* Re: [PATCH] git-remote: load config whenever create_symref() might be called
  2020-12-26 22:28   ` Jérémie Detrey
@ 2020-12-27  0:34     ` Eric Sunshine
  2020-12-27  6:22       ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: Eric Sunshine @ 2020-12-27  0:34 UTC (permalink / raw)
  To: Jérémie Detrey
  Cc: Junio C Hamano, Git List, Shulhan, Brandon Williams, Johannes Schindelin

On Sat, Dec 26, 2020 at 5:31 PM Jérémie Detrey <Jeremie.Detrey@altu.fr> wrote:
> Junio C Hamano:
> > My gut feeling says that the best place to call git_config() on
> > git_default_config would actually be in cmd_remote(), immediately
> > before we call parse_options() to parse the main options shared by
> > all subcommands of "git remote".  Is there a reason why codepaths
> > other than the three you singled out should *not* be affected by the
> > basic set of configuration variables?
>
> No, none that I can think of. I'll leave more knowledgeable people
> than me confirm this, but if that's the way to go, I'll be happy to
> submit a revised patch following your suggestion :)

I took a quick look at builtin/remote.c. It appears that several of
the subcommands already make their own calls to git_config(), each
with its own special-purpose `config_fn_t` as argument. Jérémie's
patch, which invokes git_config() for specific cases, therefore, is
consistent with existing practice in that file. Taking the approach of
calling git_config() once before parse_options() should be possible
but would require more surgery. The end result after surgery likely
would be more maintainable going forward, but the localized fixes his
patch makes might be reasonable in the short term. (But I'm not an
area expert, so don't take my word for it.)

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

* Re: [PATCH] git-remote: load config whenever create_symref() might be called
  2020-12-27  0:34     ` Eric Sunshine
@ 2020-12-27  6:22       ` Junio C Hamano
  0 siblings, 0 replies; 5+ messages in thread
From: Junio C Hamano @ 2020-12-27  6:22 UTC (permalink / raw)
  To: Eric Sunshine
  Cc: Jérémie Detrey, Git List, Shulhan, Brandon Williams,
	Johannes Schindelin

Eric Sunshine <sunshine@sunshineco.com> writes:

> ... The end result after surgery likely
> would be more maintainable going forward, but the localized fixes his
> patch makes might be reasonable in the short term.

OK, I guess.

Thanks.

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

end of thread, other threads:[~2020-12-27  6:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-26 13:44 [PATCH] git-remote: load config whenever create_symref() might be called Jérémie Detrey
2020-12-26 21:52 ` Junio C Hamano
2020-12-26 22:28   ` Jérémie Detrey
2020-12-27  0:34     ` Eric Sunshine
2020-12-27  6:22       ` Junio C Hamano

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.