From: Jeff King <peff@peff.net>
To: larsxschneider@gmail.com
Cc: git@vger.kernel.org, sschuberth@gmail.com,
ramsay@ramsayjones.plus.com, sunshine@sunshineco.com,
hvoigt@hvoigt.net, sbeller@google.com
Subject: Re: [PATCH v3 3/3] config: add '--show-origin' option to print the origin of a config value
Date: Sat, 13 Feb 2016 12:44:50 -0500 [thread overview]
Message-ID: <20160213174449.GH30144@sigill.intra.peff.net> (raw)
In-Reply-To: <1455373456-64691-4-git-send-email-larsxschneider@gmail.com>
On Sat, Feb 13, 2016 at 03:24:16PM +0100, larsxschneider@gmail.com wrote:
> From: Lars Schneider <larsxschneider@gmail.com>
>
> If config values are queried using 'git config' (e.g. via --get,
> --get-all, --get-regexp, or --list flag) then it is sometimes hard to
> find the configuration file where the values were defined.
>
> Teach 'git config' the '--show-origin' option to print the source
> configuration file for every printed value.
Thanks, I think this version fixes the correctness issues I mentioned
earlier. I do still have nits to pick (of course :) ), that we may or
may not want to deal with.
> +static void show_config_origin(struct strbuf *buf)
> +{
> + const char term = end_null ? '\0' : '\t';
> + const char *type;
> + const char *name;
> +
> + current_config_type_name(&type, &name);
This double out-parameter feels like a clunky interface.
I was tempted to suggest that we simply make the "struct config_source"
available to builtin/config.c (which is already pretty intimate with the
rest of the config code), and then it can pick out what it wants. But
there _is_ some logic in the function to convert the NULL "cf" into
"cmdline".
Perhaps it would be simpler to just have two accessor functions, and do:
strbuf_addstr(buf, current_config_type());
...
strbuf_addstr(buf, current_config_name());
I admit it is a pretty minor point, though.
> static int show_all_config(const char *key_, const char *value_, void *cb)
> {
> + if (show_origin) {
> + struct strbuf buf = STRBUF_INIT;
> + show_config_origin(&buf);
> + fwrite(buf.buf, 1, buf.len, stdout);
> + strbuf_release(&buf);
> + }
The indentation is funky here.
The use of fwrite() to catch the embedded NULs is subtle enough that it
might be worth a comment.
It also made me wonder how format_config() handles this. It looks like
we send the result eventually to fwrite() there, so it all works (and it
does _not_ have the comment I mentioned :) ).
> +test_expect_success '--show-origin' '
> + >.git/config &&
> + >"$HOME"/.gitconfig &&
> + INCLUDE_DIR="$HOME/include" &&
> + mkdir -p "$INCLUDE_DIR" &&
> + cat >"$INCLUDE_DIR"/absolute.include <<-EOF &&
> + [user]
> + absolute = include
> + EOF
> + cat >"$INCLUDE_DIR"/relative.include <<-EOF &&
> + [user]
> + relative = include
> + EOF
> + test_config_global user.global "true" &&
> + test_config_global user.override "global" &&
> + test_config_global include.path "$INCLUDE_DIR"/absolute.include &&
> + test_config include.path ../include/relative.include &&
> + test_config user.local "true" &&
> + test_config user.override "local" &&
> +
> + cat >expect <<-EOF &&
> + file:$HOME/.gitconfig user.global=true
> + file:$HOME/.gitconfig user.override=global
> + file:$HOME/.gitconfig include.path=$INCLUDE_DIR/absolute.include
> + file:$INCLUDE_DIR/absolute.include user.absolute=include
> + file:.git/config include.path=../include/relative.include
> + file:.git/../include/relative.include user.relative=include
> + file:.git/config user.local=true
> + file:.git/config user.override=local
> + cmdline: user.cmdline=true
> + EOF
> + git -c user.cmdline=true config --list --show-origin >output &&
> + test_cmp expect output &&
> +
> + cat >expect <<-EOF &&
> + file:$HOME/.gitconfigQuser.global
> + trueQfile:$HOME/.gitconfigQuser.override
> + globalQfile:$HOME/.gitconfigQinclude.path
> + $INCLUDE_DIR/absolute.includeQfile:$INCLUDE_DIR/absolute.includeQuser.absolute
> + includeQfile:.git/configQinclude.path
> + ../include/relative.includeQfile:.git/../include/relative.includeQuser.relative
> + includeQfile:.git/configQuser.local
> + trueQfile:.git/configQuser.override
> + localQcmdline:Quser.cmdline
> + trueQ
> + EOF
I see you split this up more, but there's still quite a bit going on in
this one block. IMHO, it would be more customary in our tests to put the
setup into one test_expect_success block, then each of these
expect-run-cmp blocks into their own test_expect_success.
It does mean that the setup mutates the global test state for further
tests (and you should stop using test_config_*, which clean up at the
end of the block), but I think that's the right thing here. The point of
test_config is "flip on this switch just for a moment, so we can test
its effect without hurting further tests". But these are config tests in
the first place, and it is OK for them to show a progression of
mutations of the config (you'll note that like the other tests in this
script, you are clearing out .git/config in the first place).
-Peff
next prev parent reply other threads:[~2016-02-13 17:45 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-13 14:24 [PATCH v3 0/3] config: add '--sources' option to print the source of a config value larsxschneider
2016-02-13 14:24 ` [PATCH v3 1/3] git-config.txt: describe '--includes' default behavior larsxschneider
2016-02-13 17:17 ` Jeff King
2016-02-13 21:00 ` Junio C Hamano
2016-02-14 0:34 ` Jeff King
2016-02-14 12:17 ` Lars Schneider
2016-02-14 16:05 ` Jeff King
2016-02-13 14:24 ` [PATCH v3 2/3] config: add 'type' to config_source struct that identifies config type larsxschneider
2016-02-13 17:24 ` Jeff King
2016-02-13 21:04 ` Junio C Hamano
2016-02-14 12:26 ` Lars Schneider
2016-02-14 12:24 ` Lars Schneider
2016-02-14 16:07 ` Jeff King
2016-02-13 14:24 ` [PATCH v3 3/3] config: add '--show-origin' option to print the origin of a config value larsxschneider
2016-02-13 17:44 ` Jeff King [this message]
2016-02-13 18:04 ` Jeff King
2016-02-13 18:15 ` Jeff King
2016-02-15 9:41 ` Lars Schneider
2016-02-14 12:48 ` Lars Schneider
2016-02-14 16:18 ` Jeff King
2016-02-15 7:53 ` Johannes Schindelin
2016-02-13 14:43 ` [PATCH v3 0/3] config: add '--sources' option to print the source " Mike Rappazzo
2016-02-13 17:26 ` Sebastian Schuberth
2016-02-13 18:19 ` Jeff King
2016-02-13 21:05 ` Junio C Hamano
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=20160213174449.GH30144@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=hvoigt@hvoigt.net \
--cc=larsxschneider@gmail.com \
--cc=ramsay@ramsayjones.plus.com \
--cc=sbeller@google.com \
--cc=sschuberth@gmail.com \
--cc=sunshine@sunshineco.com \
/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).