From: Duy Nguyen <pclouds@gmail.com>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>,
bert.wesarg@googlemail.com
Subject: Re: [PATCH 2/2] config: handle conditional include when $GIT_DIR is not set up
Date: Mon, 17 Apr 2017 09:13:35 +0700 [thread overview]
Message-ID: <20170417021335.GB8987@duynguyen.vn.dektech.internal> (raw)
In-Reply-To: <20170416155131.ppp5iakohiiphzmk@sigill.intra.peff.net>
On Sun, Apr 16, 2017 at 11:51:32AM -0400, Jeff King wrote:
> > diff --git a/cache.h b/cache.h
> > index e29a093839..27b7286f99 100644
> > --- a/cache.h
> > +++ b/cache.h
> > @@ -1884,6 +1884,8 @@ enum config_origin_type {
> >
> > struct config_options {
> > unsigned int respect_includes : 1;
> > + unsigned int early_config : 1;
> > + const char *git_dir; /* only valid when early_config is true */
> > };
>
> Why do we need both the flag and the string? Later, you do:
>
> > -static int include_by_gitdir(const char *cond, size_t cond_len, int icase)
> > +static int include_by_gitdir(const struct config_options *opts,
> > + const char *cond, size_t cond_len, int icase)
> > {
> > struct strbuf text = STRBUF_INIT;
> > struct strbuf pattern = STRBUF_INIT;
> > int ret = 0, prefix;
> >
> > - strbuf_add_absolute_path(&text, get_git_dir());
> > + if (!opts->early_config)
> > + strbuf_add_absolute_path(&text, get_git_dir());
> > + else if (opts->git_dir)
> > + strbuf_add_absolute_path(&text, opts->git_dir);
> > + else
> > + goto done;
>
> So we call get_git_dir() always when we're not in early config. Even if
> we don't have a git dir! Doesn't this mean that programs operating
> outside of a repo will still hit the BUG? I.e.:
>
> git config --global includeif.gitdir:/whatever.path foo
> cd /not/a/git/dir
> git diff --no-index foo bar
>
> ?
>
> I think instead the logic should be:
>
> if (opts->git_dir)
> strbuf_add_absolute_path(&text, opts->git_dir);
> else if (have_git_dir())
> strbuf_add_absolute_path(&text, get_git_dir());
> else
> goto done;
Do we care about the case when the override instruction is "we don't
have $GIT_DIR, act as if it does not exist, even though have_git_dir()
returns true"?
I'm guessing no, we won't run into that situation (and am inclined to
restructure the code as you suggested). Just throwing it out there if
I'm mistaken.
--
Duy
next prev parent reply other threads:[~2017-04-17 2:13 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 [this message]
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
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170417021335.GB8987@duynguyen.vn.dektech.internal \
--to=pclouds@gmail.com \
--cc=bert.wesarg@googlemail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).