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

Re: Add ".git/config" file parser

From
Linus Torvalds <torvalds@osdl.org>
Date
Oct 10, 2005, 22:12 UTC
Message-ID
<Pine.LNX.4.64.0510101456570.14597@g5.osdl.org>
In-Reply-To
<434AE209.60605@zytor.com>
On Mon, 10 Oct 2005, H. Peter Anvin wrote:
Show 5 quoted lines
> 
> A suggestion: if you make your basic types (integer, string, boolean)
> recognizable by the parser, you can present them in that way.  This pretty
> much means strings will have to always be double-quoted, but that avoids a
> bunch of ambiguities.

Well, the parser is already pretty unambiguous, purely by virtue of being stupid as hell.

In particular, the only thing quoting does is to actually make whitespace meaningful, and as a way to allow comments inside strings (otherwise a "#" or ";" is always a "comment starts here" marker).

Outside of quotes, any whitespace will just collapse to a single space (and be removed from beginning and end).

And quite frankly, always keeping the things as strings just makes things so much easier and the interfaces very simple. And if/when you want to turn the string into a boolean or a regular integer, there are two helper functions that do exactly that, so it's not very hard.

I considered using some "smart" parser (ie using something like flex/bison), but the thing is, I didn't want smart. I personally think it's a lot more important for the file format to be _nice_, and there I think it's fine if

	[diff]
		external=/usr/local/bin/gnu-diff

doesn't need quotes, even if it's obviously a string. Simplicity is a virtue (both in parsing and in the "language" parsed).

In fact, even the example I had - with a space and an argument - doesn't need quotes (since the single space will be collapsed to a single space), I just put that as an example.

Side note: the design is meant to allow different programs to share the same config file without having to know about each others config variables. Anything they don't recognize is just ignored. The downside is that if you mistype an option name, nobody will recognize it, and nobody will complain either.

That was one of the reasons for the "scoping". It not only allows grouping of variables, but it means that the "git-diff-xyz" family of programs might decide that they'll report anything that starts with "diff." but that they don't understand as a warning (but preferably not error, since it might be a newer option that an older version of git just doesn't understand).

		Linus
Previous: H. Peter AnvinNext: Junio C Hamano
Message 14 of 18 in “Seeing various mode changes on cygwin”
  1. Jonas FonsecaOct 8, 2005
  2. Junio C HamanoOct 8, 2005
  3. Alex RiesenOct 8, 2005
  4. Junio C HamanoOct 8, 2005
  5. Linus TorvaldsOct 9, 2005
  6. Junio C HamanoOct 9, 2005
  7. Daniel BarkalowOct 10, 2005
  8. Junio C HamanoOct 10, 2005
  9. Daniel BarkalowOct 10, 2005
  10. Linus TorvaldsOct 10, 2005
  11. Add ".git/config" file parserLinus Torvalds, Oct 10, 2005
  12. Linus TorvaldsOct 10, 2005
  13. H. Peter AnvinOct 10, 2005
  14. Linus TorvaldsOct 10, 2005
  15. Junio C HamanoOct 12, 2005
  16. Use core.filemode.Junio C Hamano, Oct 12, 2005
  17. H. Peter AnvinOct 9, 2005
  18. Alex RiesenOct 9, 2005

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.