From: Heiko Voigt <hvoigt@hvoigt.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Jens Lehmann <jens.lehmann@web.de>,
Jeff King <peff@peff.net>
Subject: [PATCH 1/4] config: factor out config file stack management
Date: Tue, 26 Feb 2013 20:38:50 +0100 [thread overview]
Message-ID: <20130226193850.GB22756@sandbox-ub> (raw)
In-Reply-To: <20130226193050.GA22756@sandbox-ub>
Because a config callback may start parsing a new file, the
global context regarding the current config file is stored
as a stack. Currently we only need to manage that stack from
git_config_from_file. Let's factor it out to allow new
sources of config data.
Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net>
---
Peff, I hope you do not mind that I totally copied your commit message
here. The patch takes a different approach though. If you like we can
add a
Commit-Message-by: Jeff King <peff@peff.net>
here :-)
Cheers Heiko
config.c | 38 ++++++++++++++++++++++++--------------
1 file changed, 24 insertions(+), 14 deletions(-)
diff --git a/config.c b/config.c
index aefd80b..2c299dc 100644
--- a/config.c
+++ b/config.c
@@ -896,6 +896,28 @@ int git_default_config(const char *var, const char *value, void *dummy)
return 0;
}
+static int do_config_from(struct config_file *top, config_fn_t fn, void *data)
+{
+ int ret;
+
+ /* push config-file parsing state stack */
+ top->prev = cf;
+ top->linenr = 1;
+ top->eof = 0;
+ strbuf_init(&top->value, 1024);
+ strbuf_init(&top->var, 1024);
+ cf = top;
+
+ ret = git_parse_file(fn, data);
+
+ /* pop config-file parsing state stack */
+ strbuf_release(&top->value);
+ strbuf_release(&top->var);
+ cf = top->prev;
+
+ return ret;
+}
+
int git_config_from_file(config_fn_t fn, const char *filename, void *data)
{
int ret;
@@ -905,22 +927,10 @@ int git_config_from_file(config_fn_t fn, const char *filename, void *data)
if (f) {
config_file top;
- /* push config-file parsing state stack */
- top.prev = cf;
top.f = f;
top.name = filename;
- top.linenr = 1;
- top.eof = 0;
- strbuf_init(&top.value, 1024);
- strbuf_init(&top.var, 1024);
- cf = ⊤
-
- ret = git_parse_file(fn, data);
-
- /* pop config-file parsing state stack */
- strbuf_release(&top.value);
- strbuf_release(&top.var);
- cf = top.prev;
+
+ ret = do_config_from(&top, fn, data);
fclose(f);
}
--
1.8.2.rc0.26.gf7384c5
next prev parent reply other threads:[~2013-02-26 19:39 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-25 1:02 [RFC/WIP PATCH 0/3] fetch moved submodules on-demand Heiko Voigt
2013-02-25 1:04 ` [RFC/WIP PATCH 1/3] teach config parsing to read from strbuf Heiko Voigt
2013-02-25 5:54 ` Junio C Hamano
2013-02-25 17:29 ` Heiko Voigt
2013-02-26 19:30 ` [PATCH 0/4] allow more sources for config values Heiko Voigt
2013-02-26 19:38 ` Heiko Voigt [this message]
2013-02-26 19:54 ` [PATCH 1/4] config: factor out config file stack management Jeff King
2013-02-26 20:09 ` Heiko Voigt
2013-02-26 20:15 ` Jeff King
2013-02-26 22:10 ` Junio C Hamano
2013-02-27 7:51 ` Heiko Voigt
2013-02-26 22:12 ` Junio C Hamano
2013-02-27 7:56 ` Heiko Voigt
2013-02-26 19:40 ` [PATCH 2/4] config: drop file pointer validity check in get_next_char() Heiko Voigt
2013-02-26 20:05 ` Jeff King
2013-02-27 7:52 ` Heiko Voigt
2013-02-28 0:42 ` Heiko Voigt
2013-02-28 0:54 ` Heiko Voigt
2013-02-26 19:42 ` [PATCH 3/4] config: make parsing stack struct independent from actual data source Heiko Voigt
2013-02-26 19:43 ` [PATCH 4/4] teach config parsing to read from strbuf Heiko Voigt
2013-03-07 18:42 ` Ramsay Jones
2013-03-10 16:39 ` Heiko Voigt
2013-02-26 4:55 ` [RFC/WIP PATCH 1/3] " Jeff King
2013-02-25 1:05 ` [RFC/WIP PATCH 2/3] implement fetching of moved submodules Heiko Voigt
2013-02-25 1:06 ` [RFC/WIP PATCH 3/3] submodule: simplify decision tree whether to or not to fetch Heiko Voigt
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=20130226193850.GB22756@sandbox-ub \
--to=hvoigt@hvoigt.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jens.lehmann@web.de \
--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).