All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Cc: git@vger.kernel.org, Jeff King <peff@peff.net>,
	bert.wesarg@googlemail.com
Subject: Re: [PATCH v2 2/3] config: handle conditional include when $GIT_DIR is not set up
Date: Mon, 17 Apr 2017 19:49:30 -0700	[thread overview]
Message-ID: <xmqq7f2ih1l1.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <20170417101002.18272-2-pclouds@gmail.com> (=?utf-8?B?Ik5n?= =?utf-8?B?dXnhu4VuIFRow6FpIE5n4buNYw==?= Duy"'s message of "Mon, 17 Apr 2017 17:10:01 +0700")

Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:

> @@ -1603,10 +1613,12 @@ void read_early_config(config_fn_t cb, void *data)
>  {
>  	struct config_options opts = {0};
>  	struct strbuf buf = STRBUF_INIT;
> +	char *to_free = NULL;
>  
>  	opts.respect_includes = 1;
> -	git_config_with_options(cb, data, NULL, &opts);
>  
> +	if (have_git_dir())
> +		opts.git_dir = get_git_dir();
>  	/*
>  	 * When setup_git_directory() was not yet asked to discover the
>  	 * GIT_DIR, we ask discover_git_directory() to figure out whether there
> @@ -1615,7 +1627,12 @@ void read_early_config(config_fn_t cb, void *data)
>  	 * notably, the current working directory is still the same after the
>  	 * call).
>  	 */
> -	if (!have_git_dir() && discover_git_directory(&buf)) {
> +	else if (discover_git_directory(&buf))
> +		opts.git_dir = to_free = xstrdup(buf.buf);
> +
> +	git_config_with_options(cb, data, NULL, &opts);

This one I can understand.  By having NULL for config_source, this
does the usual do_git_config_sequence() dance, which knows to treat
opts.git_dir is the "repository config" without necessarily being
able to do git_pathdup("config").

> +	if (!have_git_dir() && opts.git_dir) {
>  		struct git_config_source repo_config;
>  
>  		memset(&repo_config, 0, sizeof(repo_config));

But this one I do not quite understand.  When have_git_dir() was
false and asked discover_git_directory() to set opts.git_dir, we
enter the body of this block and then end up doing

	git_config_with_options(cb, data &repo_config, &opts);

with repo_config set to the discovered git directory plus "/config";
we'd read the repository configuration twice, in other words.


  reply	other threads:[~2017-04-18  2:49 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-14 17:04 includeIf breaks calling dashed externals Bert Wesarg
2017-04-14 17:43 ` Jeff King
2017-04-15 11:49   ` Duy Nguyen
2017-04-16  4:50     ` Jeff King
2017-04-16 10:41       ` [PATCH 1/2] config: prepare to pass more info in git_config_with_options() Nguyễn Thái Ngọc Duy
2017-04-16 10:41         ` [PATCH 2/2] config: handle conditional include when $GIT_DIR is not set up Nguyễn Thái Ngọc Duy
2017-04-16 15:51           ` Jeff King
2017-04-17  2:13             ` Duy Nguyen
2017-04-18  3:56               ` Jeff King
2017-04-17 10:07             ` Duy Nguyen
2017-04-17 10:10               ` [PATCH v2 1/3] config: prepare to pass more info in git_config_with_options() Nguyễn Thái Ngọc Duy
2017-04-17 10:10                 ` [PATCH v2 2/3] config: handle conditional include when $GIT_DIR is not set up Nguyễn Thái Ngọc Duy
2017-04-18  2:49                   ` Junio C Hamano [this message]
2017-04-18  2:56                     ` Junio C Hamano
2017-04-18  3:46                       ` Jeff King
2017-04-17 10:10                 ` [PATCH v2 3/3] config: correct file reading order in read_early_config() Nguyễn Thái Ngọc Duy
2017-04-18  3:53                   ` Jeff King
2017-04-18  2:27                 ` [PATCH v2 1/3] config: prepare to pass more info in git_config_with_options() Junio C Hamano
2017-04-18  3:55                   ` Jeff King
2017-04-18  4:51                     ` Junio C Hamano
2017-04-18  3:17               ` [PATCH 2/2] config: handle conditional include when $GIT_DIR is not set up Junio C Hamano
2017-04-18  4:03               ` Jeff King
2017-04-16 15:31         ` [PATCH 1/2] config: prepare to pass more info in git_config_with_options() Jeff King
2017-04-17  1:42           ` Duy Nguyen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqq7f2ih1l1.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox.com \
    --cc=bert.wesarg@googlemail.com \
    --cc=git@vger.kernel.org \
    --cc=pclouds@gmail.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.