git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Michael Haggerty <mhagger@alum.mit.edu>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 0/2] config includes, take 2
Date: Mon, 6 Feb 2012 05:06:22 -0500	[thread overview]
Message-ID: <20120206100622.GC4300@sigill.intra.peff.net> (raw)
In-Reply-To: <4F2FA330.7020803@alum.mit.edu>

On Mon, Feb 06, 2012 at 10:53:52AM +0100, Michael Haggerty wrote:

> ISTM that the main goal was to prevent infinite recursion, not avoid a
> little bit of redundant reading.

It was both, actually. There was a sense that we should not end up with
duplicate entries by reading the same file twice. However, entries which
actually create lists (and could therefore create duplicates) are by far
the minority compared to entries which overwrite. And it is the
overwrite-style entries which are harmed by suppressing duplicates.

> If that is the goal, all you have to record is the "include stack"
> context that caused the currently-being-included file to be read and
> make sure that the currently-being-included file didn't appear earlier
> on the stack.  The fact that the same file was included earlier (but
> not as part of the same include chain) needn't be considered an error.

I considered this, but decided the complexity wasn't worth it,
especially because getting it accurate means cooperation from
git_config_from_file, which otherwise doesn't know or care about this
mechanism. Instead I keep a simple depth counter and barf at a
reasonable maximum, printing the "from" and "to" files. Yes, it's not
nearly as elegant as keeping the whole stack, but I really don't expect
people to have complex super-deep includes, nor for it to be difficult
to hunt down the cause of a cycle.

Maybe that is short-sighted or lazy of me, but I'd just really be
surprised if people ever went more than 1 or 2 layers deep, or if they
actually ended up with a cycle at all.

There is a stack kept already by git_config_from_file, but it doesn't
respect the call-chain (so if I start a new git_config() call from
inside a callback, it is still part of the same stack).

We could possibly put a marker in the stack for that situation, and then
it would be usable for include cycle-detection.

> However, one could even imagine a command like
> 
>     $ git config --where-defined user.email
>     user.email defined by /home/me/myfile2 line 75
>         which was included from /home/me/myfile1 line 13
>         which was included from /home/me/.gitconfig line 22
>     user.email redefined by /home/me/project/.git/companyconfig line 8
>         which was included from /home/me/project/.git/config line 20

You can already implement this with the existing stack by providing a
suitable callback (since its your callback, you'd know that there was no
recursion of git_config, and therefore the stack refers only to a single
set of includes).

-Peff

  reply	other threads:[~2012-02-06 10:06 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-06  6:27 [PATCH 0/2] config includes, take 2 Jeff King
2012-02-06  6:29 ` [PATCH 1/2] imap-send: remove dead code Jeff King
2012-02-06  6:31 ` [PATCH 2/2] config: add include directive Jeff King
2012-02-06  7:41 ` [PATCH 0/2] config includes, take 2 Junio C Hamano
2012-02-06  9:53 ` Michael Haggerty
2012-02-06 10:06   ` Jeff King [this message]
2012-02-06 10:16     ` Jeff King
2012-02-07  5:01 ` David Aguilar
2012-02-07  5:17   ` Jeff King
2012-02-07 10:05     ` David Aguilar
2012-02-07 17:30       ` Jeff King
2012-02-07 18:03         ` Junio C Hamano
2012-02-07 18:29           ` Jeff King
2012-02-07 19:16         ` Jakub Narebski
2012-02-07 19:21           ` Jeff King
2012-02-07 20:15           ` David Aguilar
2012-02-09  3:30           ` Jeff King
2012-02-09 19:24             ` Jakub Narebski
2012-02-09 19:33               ` Jeff King

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=20120206100622.GC4300@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=mhagger@alum.mit.edu \
    /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 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 NNTP newsgroup(s).