git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [RFC/PATCH] config.c: Make git_config() work correctly when called recursively

From
Jeff King <peff@peff.net>
Date
Jun 14, 2011, 18:27 UTC
Message-ID
<20110614182726.GA451@sigill.intra.peff.net>
In-Reply-To
<4DF7A627.2080600@ramsay1.demon.co.uk>
On Tue, Jun 14, 2011 at 07:19:19PM +0100, Ramsay Jones wrote:
Show 21 quoted lines
> > Since you've nicely encapsulated all of the global data in this struct,
> > maybe it is worth simply passing a struct pointer down the call-chain
> > instead of relying on a global pointer. Then you can let the language do
> > its job and stop managing the stack yourself.
> 
> The first version of this patch did exactly that! However, that first patch
> failed the test-suite. :(
> 
> The failure was caused by a change to the die_bad_config() function, which
> in the current patch looks like this:
> 
>     @@ -374,8 +381,8 @@ int git_parse_ulong(const char *value, unsigned long *ret)
>  
>      static void die_bad_config(const char *name)
>      {
>     -	if (config_file_name)
>     -		die("bad config value for '%s' in %s", name, config_file_name);
>     +	if (cf && cf->name)
>     +		die("bad config value for '%s' in %s", name, cf->name);
>      	die("bad config value for '%s'", name);
>      }

Ah, right. We want to keep it as globals, because we end up in a callback which does not get the context passed to it.

Show 9 quoted lines
> In order not to change the public interface (note that git_config_int() and
> git_config_ulong() call die_bad_config()), I had to change this function so
> that it only contains the final die() call. Thus, the error message no longer
> included the config filename. This caused the test called 'invalid unit' in
> t1300-repo-config.sh to fail.
> 
> I could, of course, have simply changed the expect file so that it would pass
> the test, but I wanted the change to be self-contained and to pass all existing
> tests (ie. the external interface/behaviour should *not* change).

No, you did the right thing here. The information on which config file we're in is valuable, and taking away the globals is not worth the pain of making all of the callers and callbacks of git_config have to deal with passing around a context struct.

So the patch you posted looks good to me.
-Peff
Previous: Ramsay JonesNext: Ramsay Jones
Message 4 of 5 in “config.c: Make git_config() work correctly when called recursively”
  1. config.c: Make git_config() work correctly when called recursivelyRamsay Jones, Jun 9, 2011
  2. Jeff KingJun 9, 2011
  3. Ramsay JonesJun 14, 2011
  4. Jeff KingJun 14, 2011
  5. Ramsay JonesJun 16, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.