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

Re: [PATCH v3 2/3] config: add 'type' to config_source struct that identifies config type

From
Jeff King <peff@peff.net>
Date
Feb 13, 2016, 17:24 UTC
Message-ID
<20160213172435.GG30144@sigill.intra.peff.net>
In-Reply-To
<1455373456-64691-3-git-send-email-larsxschneider@gmail.com>
On Sat, Feb 13, 2016 at 03:24:15PM +0100, larsxschneider@gmail.com wrote:
> From: Lars Schneider <larsxschneider@gmail.com>
> 
> Use the config type to print more detailed error messages that inform
> the user about the origin of a config error (file, stdin, blob).
This looks OK overall. A few minor nits...
Show 8 quoted lines
> @@ -1104,6 +1106,7 @@ int git_config_from_buf(config_fn_t fn, const char *name, const char *buf,
>  	top.u.buf.buf = buf;
>  	top.u.buf.len = len;
>  	top.u.buf.pos = 0;
> +	top.type = "blob";
>  	top.name = name;
>  	top.path = NULL;
>  	top.die_on_error = 0;

This function is about reading config from a memory buffer. The only reason we do so _now_ is when reading from a blob, but I think it is laying a trap for somebody who wants to reuse the function later.

Should git_config_from_buf() take a "type" parameter, and git_config_from_blob_sha1() pass in "blob"?

Show 17 quoted lines
> @@ -1066,7 +1067,8 @@ static int do_config_from_file(config_fn_t fn,
>  	struct config_source top;
>  
>  	top.u.file = f;
> -	top.name = name;
> +	top.type = path ? "file" : "stdin";
> +	top.name = name ? name : "";
>  	top.path = path;
>  	top.die_on_error = 1;
>  	top.do_fgetc = config_file_fgetc;
> @@ -1078,7 +1080,7 @@ static int do_config_from_file(config_fn_t fn,
>  
>  static int git_config_from_stdin(config_fn_t fn, void *data)
>  {
> -	return do_config_from_file(fn, "<stdin>", NULL, stdin, data);
> +	return do_config_from_file(fn, NULL, NULL, stdin, data);
>  }

Likewise here, we make assumptions in do_config_from_file() about what the NULL path means. I think this is less likely to be a problem than the other case, but it seems like it would be cleaner for "file" or "stdin" to come from the caller, which knows for sure what we are doing.

Similarly, I think git_config_from_stdin() can simply pass in an empty name rather than NULL to avoid do_config_from_file() having to fix it up.

Show 5 quoted lines
> +test_expect_success 'invalid stdin config' '
> +	echo "fatal: bad config line 1 in stdin " >expect &&
> +	echo "[broken" | test_must_fail git config --list --file - >output 2>&1 &&
> +	test_cmp expect output
> +'

The original would have been "bad config file line 1 in <stdin>"; I think this is an improvement to drop the "file" here.

-Peff
Previous: larsxschneider@gmail.comNext: Junio C Hamano
Message 9 of 25 in “config: add '--sources' option to print the source of a config value”
  1. 0/3 config: add '--sources' option to print the source of a config valuelarsxschneider@gmail.com, Feb 13, 2016
  2. 1/3 git-config.txt: describe '--includes' default behaviorlarsxschneider@gmail.com, Feb 13, 2016
  3. Jeff KingFeb 13, 2016
  4. Junio C HamanoFeb 13, 2016
  5. Jeff KingFeb 14, 2016
  6. Lars SchneiderFeb 14, 2016
  7. Jeff KingFeb 14, 2016
  8. 2/3 config: add 'type' to config_source struct that identifies config typelarsxschneider@gmail.com, Feb 13, 2016
  9. Jeff KingFeb 13, 2016
  10. Junio C HamanoFeb 13, 2016
  11. Lars SchneiderFeb 14, 2016
  12. Lars SchneiderFeb 14, 2016
  13. Jeff KingFeb 14, 2016
  14. 3/3 config: add '--show-origin' option to print the origin of a config valuelarsxschneider@gmail.com, Feb 13, 2016
  15. Jeff KingFeb 13, 2016
  16. Jeff KingFeb 13, 2016
  17. Jeff KingFeb 13, 2016
  18. Lars SchneiderFeb 15, 2016
  19. Lars SchneiderFeb 14, 2016
  20. Jeff KingFeb 14, 2016
  21. Johannes SchindelinFeb 15, 2016
  22. Mike RappazzoFeb 13, 2016
  23. Sebastian SchuberthFeb 13, 2016
  24. Jeff KingFeb 13, 2016
  25. Junio C HamanoFeb 13, 2016

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.