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

Re: [PATCH] config: Add --quoted option to produce machine-parsable output

From
JHJan Hudec <bulb@ucw.cz>
Date
May 21, 2007, 19:54 UTC
Message-ID
<20070521195423.GC5082@efreet.light.src>
In-Reply-To
<11797696193384-git-send-email-frank@lichtenheld.de>
On Mon, May 21, 2007 at 19:46:59 +0200, Frank Lichtenheld wrote:
> This option will enclose key names in quotes (") if they
> contain a subsection and then escape " and \. It will also
> escape line breaks in values. Together this should produce
> an easily parsable output.

That will lead to either eval (which runs perl parser and probably won't win anything) or regexps (which is not big win over parsing the .ini directly with them) on the perl side. IMHO only thing that would actually be faster is NUL-separated entries.

Either:
    KEY <NUL> VALUE <NUL>
or:
    KEY <TAB> VALUE <NUL>

I am not sure whether there can be multi-valued entries. If so, than there are three options:

1. Simply repeated key/value pairs:
   KEY <NUL> VALUE1 <NUL> KEY <NUL> VALUE2 <NUL>.
   KEY <TAB> VALUE1 <NUL> KEY <TAB> VALUE2 <NUL> resp.
2. Key/count/values:
   KEY <NUL> 1 <NUL> VALUE <NUL>
   KEY <NUL> 2 <NUL> VALUE1 <NUL> VALUE2 <NUL>
   (there's probably no benefit for the tab-nul format, because the first
   value must be terminated with NUL)
3. Empty-entry terminated:
   KEY <NUL> VALUE <NUL> <NUL>
   KEY <NUL> VALUE1 <NUL> VALUE2 <NUL> <NUL>
   (again no point in terminating the KEY with tab)
The advantage of such format is, that it can be parsed with:
    local $/ = "\0";
    while(<INPUT>) {
	$hash{$_} = <INPUT>;
    }
and slight variations for the other variants. It should be similarly easy
from python and C. Shell won't like it, though.
Note: In both bash and zsh, read -d '' line reads NUL-terminated "lines".
However, dash does not have -d option to read :-(.
-- 
						 Jan 'Bulb' Hudec <bulb@ucw.cz>
Previous: Johannes SchindelinNext: Frank Lichtenheld
Message 8 of 34 in “[RFC] Implementing git config handling in Git.pm”
  1. Frank LichtenheldMay 20, 2007
  2. Petr BaudisMay 20, 2007
  3. config: Add --quoted option to produce machine-parsable outputFrank Lichtenheld, May 21, 2007
  4. Junio C HamanoMay 21, 2007
  5. Johannes SchindelinMay 21, 2007
  6. Junio C HamanoMay 21, 2007
  7. Johannes SchindelinMay 21, 2007
  8. Jan HudecMay 21, 2007
  9. Frank LichtenheldMay 21, 2007
  10. Jakub NarebskiMay 21, 2007
  11. config: Add --null/-z option for null-delimted outputFrank Lichtenheld, Jun 17, 2007
  12. Johannes SchindelinJun 19, 2007
  13. Jakub NarebskiJun 19, 2007
  14. Frank LichtenheldJun 19, 2007
  15. Johannes SchindelinJun 19, 2007
  16. Junio C HamanoJun 19, 2007
  17. Frank LichtenheldJun 19, 2007
  18. Johannes SchindelinJun 19, 2007
  19. David KastrupJun 19, 2007
  20. Jakub NarebskiJun 19, 2007
  21. Frank LichtenheldJun 19, 2007
  22. Johannes SchindelinJun 19, 2007
  23. Frank LichtenheldJun 19, 2007
  24. Johannes SchindelinJun 20, 2007
  25. Jakub NarebskiJun 20, 2007
  26. Jakub NarebskiJun 21, 2007
  27. Frank LichtenheldJun 22, 2007
  28. 1/3 config: Complete documentation of --get-regexpFrank Lichtenheld, Jun 25, 2007
  29. 2/3 config: Change output of --get-regexp for valueless keysFrank Lichtenheld, Jun 25, 2007
  30. Junio C HamanoJun 27, 2007
  31. 3/3 config: Add --null/-z option for null-delimted outputFrank Lichtenheld, Jun 25, 2007
  32. Jakub NarebskiJun 25, 2007
  33. Frank LichtenheldJun 26, 2007
  34. Junio C HamanoJun 27, 2007

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.