git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Allow built-ins to also use -c var=val via alias

From
Junio C Hamano <gitster@pobox.com>
Date
May 24, 2011, 21:18 UTC
Message-ID
<7vmxib7q79.fsf@alter.siamese.dyndns.org>
In-Reply-To
<7vsjs37qcp.fsf@alter.siamese.dyndns.org>

The previous commit 2b64fc8 (pass "git -c foo=bar" params through environment, 2010-08-23) tried to make all the one-shot configuration setting made via the "-c" option to the "git" wrapper go through an environment variable, so that the value can be propagated to external commands _as well as_ the internal ones, but ended up breaking one of the codepaths that invokes internal commands, because it incorrectly assumed that git_config_from_parmeters() can never be called in a single process after git_config_parse_environment() was called once.

Not so.
When the options came as part of an alias to an internal command, e.g.
  [alias]
    aw = -c apply.whitespace=fix apply

and then run as "git aw P.diff", we have already read the configuration to find out about the alias definition (setting loaded_environment to true), then pushed apply.whitespace=fix to the environment, but not to the in-core list of configuration variables. The implementation of the internal command, e.g. cmd_apply(), will try to read from git_config() but the setting is lost, as the environment is never read in this codepath.

Add the in-core queuing of the parameters back to fix this.

Note that the handling of such an alias is still broken for another reason in this codepath; a separate patch fixes it.

While at it, avoid getting our test confused by GIT_CONFIG_PARAMETERS exported to the tester's environment.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 * And this is the other fix. Applying this on top of 2b64fc8 does not
   make "git aw P.diff" in the test t1300 in the other patch, but this
   is prerequisite for the other fix to work in a more modern codebase.
 config.c      |    1 +
 t/test-lib.sh |    1 +
 2 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/config.c b/config.c
index c2c995f..c803ae8 100644
--- a/config.c
+++ b/config.c
@@ -43,6 +43,7 @@ void git_config_push_parameter(const char *text)
 		strbuf_addstr(&env, old);
 		strbuf_addch(&env, ' ');
 	}
+	git_config_parse_parameter(text);
 	sq_quote_buf(&env, text);
 	setenv(CONFIG_DATA_ENVIRONMENT, env.buf, 1);
 	strbuf_release(&env);
diff --git a/t/test-lib.sh b/t/test-lib.sh
index e5523dd..0b1358e 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -57,6 +57,7 @@ GIT_AUTHOR_NAME='A U Thor'
 unset GIT_COMMITTER_DATE
 GIT_COMMITTER_EMAIL=committer@example.com
 GIT_COMMITTER_NAME='C O Mitter'
+unset GIT_CONFIG_PARAMETERS
 unset GIT_DIFF_OPTS
 unset GIT_DIR
 unset GIT_WORK_TREE
-- 
1.7.5.2.459.g67e41
Previous: Junio C HamanoNext: Jeff King
Message 2 of 10 in “handle_options(): do not miscount how many arguments were used”
  1. handle_options(): do not miscount how many arguments were usedJunio C Hamano, May 24, 2011
  2. Allow built-ins to also use -c var=val via aliasJunio C Hamano, May 24, 2011
  3. Jeff KingMay 24, 2011
  4. Jeff KingMay 24, 2011
  5. Jeff KingMay 24, 2011
  6. Jeff KingMay 24, 2011
  7. 1/4 config: make environment parsing routines staticJeff King, May 24, 2011
  8. 2/4 git_config: don't peek at global config_parametersJeff King, May 24, 2011
  9. 3/4 config: always parse GIT_CONFIG_PARAMETERS during git_configJeff King, May 24, 2011
  10. 4/4 handle_options(): do not miscount how many arguments were usedJeff King, May 24, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.