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

Re: [PATCHv2 5/8] submodule: use parse_config_key when parsing config

From
Jens Lehmann <jens.lehmann@web.de>
Date
Jan 23, 2013, 20:45 UTC
Message-ID
<51004BDF.6040606@web.de>
In-Reply-To
<20130123062522.GE5036@sigill.intra.peff.net>
Am 23.01.2013 07:25, schrieb Jeff King:
Show 13 quoted lines
> This makes the code a lot simpler to read by dropping a
> whole bunch of constant offsets.
> 
> As a bonus, it means we also feed the whole config variable
> name to our error functions:
> 
>   [before]
>   $ git -c submodule.foo.fetchrecursesubmodules=bogus checkout
>   fatal: bad foo.fetchrecursesubmodules argument: bogus
> 
>   [after]
>   $ git -c submodule.foo.fetchrecursesubmodules=bogus checkout
>   fatal: bad submodule.foo.fetchrecursesubmodules argument: bogus
Thanks, that makes lots of sense!
Acked-by: Jens Lehmann <Jens.Lehmann@web.de>
Show 59 quoted lines
> Signed-off-by: Jeff King <peff@peff.net>
> ---
>  submodule.c | 19 ++++++++++---------
>  1 file changed, 10 insertions(+), 9 deletions(-)
> 
> diff --git a/submodule.c b/submodule.c
> index 2f55436..25413de 100644
> --- a/submodule.c
> +++ b/submodule.c
> @@ -126,15 +126,16 @@ int parse_submodule_config_option(const char *var, const char *value)
>  
>  int parse_submodule_config_option(const char *var, const char *value)
>  {
> -	int len;
>  	struct string_list_item *config;
>  	struct strbuf submodname = STRBUF_INIT;
> +	const char *name, *key;
> +	int namelen;
>  
> -	var += 10;		/* Skip "submodule." */
> +	if (parse_config_key(var, "submodule", &name, &namelen, &key) < 0 || !name)
> +		return 0;
>  
> -	len = strlen(var);
> -	if ((len > 5) && !strcmp(var + len - 5, ".path")) {
> -		strbuf_add(&submodname, var, len - 5);
> +	if (!strcmp(key, "path")) {
> +		strbuf_add(&submodname, name, namelen);
>  		config = unsorted_string_list_lookup(&config_name_for_path, value);
>  		if (config)
>  			free(config->util);
> @@ -142,22 +143,22 @@ int parse_submodule_config_option(const char *var, const char *value)
>  			config = string_list_append(&config_name_for_path, xstrdup(value));
>  		config->util = strbuf_detach(&submodname, NULL);
>  		strbuf_release(&submodname);
> -	} else if ((len > 23) && !strcmp(var + len - 23, ".fetchrecursesubmodules")) {
> -		strbuf_add(&submodname, var, len - 23);
> +	} else if (!strcmp(key, "fetchrecursesubmodules")) {
> +		strbuf_add(&submodname, name, namelen);
>  		config = unsorted_string_list_lookup(&config_fetch_recurse_submodules_for_name, submodname.buf);
>  		if (!config)
>  			config = string_list_append(&config_fetch_recurse_submodules_for_name,
>  						    strbuf_detach(&submodname, NULL));
>  		config->util = (void *)(intptr_t)parse_fetch_recurse_submodules_arg(var, value);
>  		strbuf_release(&submodname);
> -	} else if ((len > 7) && !strcmp(var + len - 7, ".ignore")) {
> +	} else if (!strcmp(key, "ignore")) {
>  		if (strcmp(value, "untracked") && strcmp(value, "dirty") &&
>  		    strcmp(value, "all") && strcmp(value, "none")) {
>  			warning("Invalid parameter \"%s\" for config option \"submodule.%s.ignore\"", value, var);
>  			return 0;
>  		}
>  
> -		strbuf_add(&submodname, var, len - 7);
> +		strbuf_add(&submodname, name, namelen);
>  		config = unsorted_string_list_lookup(&config_ignore_for_name, submodname.buf);
>  		if (config)
>  			free(config->util);
> 
Previous: Jeff KingNext: Jeff King
Message 17 of 31 in “archive-tar: fix sanity check in config parsing”
  1. archive-tar: fix sanity check in config parsingRené Scharfe, Jan 13, 2013
  2. Jeff KingJan 13, 2013
  3. Joachim SchmitzJan 14, 2013
  4. Jeff KingJan 14, 2013
  5. Jeff KingJan 14, 2013
  6. 1/6 config: add helper function for parsing key namesJeff King, Jan 14, 2013
  7. Junio C HamanoJan 14, 2013
  8. Jeff KingJan 15, 2013
  9. Junio C HamanoJan 15, 2013
  10. Junio C HamanoJan 18, 2013
  11. 0/8 config key-parsing cleanupsJeff King, Jan 23, 2013
  12. 1/8 config: add helper function for parsing key namesJeff King, Jan 23, 2013
  13. 2/8 archive-tar: use parse_config_key when parsing configJeff King, Jan 23, 2013
  14. 3/8 convert some config callbacks to parse_config_keyJeff King, Jan 23, 2013
  15. 4/8 userdiff: drop parse_driver functionJeff King, Jan 23, 2013
  16. 5/8 submodule: use parse_config_key when parsing configJeff King, Jan 23, 2013
  17. Jens LehmannJan 23, 2013
  18. 6/8 submodule: simplify memory handling in config parsingJeff King, Jan 23, 2013
  19. Jens LehmannJan 23, 2013
  20. 7/8 help: use parse_config_key for man configJeff King, Jan 23, 2013
  21. 8/8 reflog: use parse_config_key in config callbackJeff King, Jan 23, 2013
  22. Junio C HamanoJan 23, 2013
  23. Jonathan NiederJan 23, 2013
  24. 2/6 archive-tar: use match_config_key when parsing configJeff King, Jan 14, 2013
  25. 3/6 convert some config callbacks to match_config_keyJeff King, Jan 14, 2013
  26. Jonathan NiederJan 14, 2013
  27. Jeff KingJan 14, 2013
  28. Jeff KingJan 14, 2013
  29. 4/6 userdiff: drop parse_driver functionJeff King, Jan 14, 2013
  30. 5/6 submodule: use match_config_key when parsing configJeff King, Jan 14, 2013
  31. 6/6 submodule: simplify memory handling in config parsingJeff King, Jan 14, 2013

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.