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

[PATCH] Make git config fail on variables with no section, as documented

From
Alex Vandiver <alex@chmrr.net>
Date
Jul 26, 2009, 16:18 UTC
Message-ID
<1248625102-472-1-git-send-email-alex@chmrr.net>
In-Reply-To
<1248474081-sup-2762@utwig>
Documentation/config.txt claims:
    Each variable must belong to some section, which means that there
    must be a section header before the first setting of a variable.

However, the parsing code did not enforce this. This change makes it a syntax error to defined a variable before the first section header.

Signed-off-by: Alex Vandiver <alex@chmrr.net>
---
 config.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/config.c b/config.c
index 1b3823d..447ad00 100644
--- a/config.c
+++ b/config.c
@@ -248,6 +248,8 @@ static int git_parse_file(config_fn_t fn, void *data)
 		}
 		if (!isalpha(c))
 			break;
+		if (baselen == 0)
+			break;
 		var[baselen] = tolower(c);
 		if (get_value(fn, data, var, baselen+1) < 0)
 			break;
-- 
1.6.3.3.473.gb74fc4.dirty
Previous: Alex VandiverNext: Johannes Schindelin
Message 6 of 17 in “Section renaming can lose content”
  1. 0/2 Section renaming can lose contentAlex Vandiver, Jul 24, 2009
  2. 1/2 Make section_name_match start on '[', and return the length on successAlex Vandiver, Jul 24, 2009
  3. 2/2 After renaming a section, print any trailing variable definitionsAlex Vandiver, Jul 24, 2009
  4. Nanako ShiraishiJul 24, 2009
  5. Alex VandiverJul 24, 2009
  6. Make git config fail on variables with no section, as documentedAlex Vandiver, Jul 26, 2009
  7. Johannes SchindelinJul 26, 2009
  8. Alex VandiverJul 26, 2009
  9. Johannes SchindelinJul 26, 2009
  10. Alex VandiverJul 26, 2009
  11. Junio C HamanoJul 24, 2009
  12. (unknown)Nanako Shiraishi, Jul 25, 2009
  13. Johannes SchindelinJul 25, 2009
  14. Johannes SchindelinJul 25, 2009
  15. Alex VandiverJul 25, 2009
  16. Junio C HamanoJul 25, 2009
  17. Johannes SchindelinJul 25, 2009

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.