From mboxrd@z Thu Jan 1 00:00:00 1970 From: Heiko Voigt Subject: [PATCH v4 1/5] config: factor out config file stack management Date: Sat, 11 May 2013 15:18:52 +0200 Message-ID: <20130511131852.GB17991@book-mint> References: <20130511131721.GA17991@book-mint> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: git@vger.kernel.org, Junio C Hamano , Jens Lehmann , Ramsay Jones To: Jeff King X-From: git-owner@vger.kernel.org Sat May 11 15:19:08 2013 Return-path: Envelope-to: gcvg-git-2@plane.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Ub9hb-0002Uf-Jz for gcvg-git-2@plane.gmane.org; Sat, 11 May 2013 15:19:07 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752620Ab3EKNTD (ORCPT ); Sat, 11 May 2013 09:19:03 -0400 Received: from smtprelay02.ispgateway.de ([80.67.31.29]:45613 "EHLO smtprelay02.ispgateway.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752003Ab3EKNTA (ORCPT ); Sat, 11 May 2013 09:19:00 -0400 Received: from [213.221.117.228] (helo=book-mint) by smtprelay02.ispgateway.de with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.68) (envelope-from ) id 1Ub9hO-0004qU-L1; Sat, 11 May 2013 15:18:54 +0200 Content-Disposition: inline In-Reply-To: <20130511131721.GA17991@book-mint> User-Agent: Mutt/1.5.21 (2010-09-15) X-Df-Sender: aHZvaWd0QGh2b2lndC5uZXQ= Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: 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 --- config.c | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/config.c b/config.c index aefd80b..f0494f3 100644 --- a/config.c +++ b/config.c @@ -896,6 +896,32 @@ int git_default_config(const char *var, const char *value, void *dummy) return 0; } +/* + * The fields f and name of top need to be initialized before calling + * this function. + */ +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 +931,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.3.rc1.53.g0126843