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

Re: [Question] Complex textconv text

From
Jeff King <peff@peff.net>
Date
Dec 14, 2018, 10:04 UTC
Message-ID
<20181214100457.GB13465@sigill.intra.peff.net>
In-Reply-To
<xmqqo99odcou.fsf@gitster-ct.c.googlers.com>
On Fri, Dec 14, 2018 at 12:12:01PM +0900, Junio C Hamano wrote:
Show 25 quoted lines
> > I have a strange situation and need help with resolving funky characters in
> > .git/config. My situation is this:
> >
> > [diff "*.dat"]
> > 	textconv = enscribe-conv
> > --format=-a1\(A=-a1,-a16,-a32\|P=-a1,-a32,-a16\|=-a1,-d,a14\),-a224
> >
> > Basically this is a formatter for diff so that I can show structured binary
> > data. The unquoted syntax of the format string is:
> >  --format=-a1(A=-a1,-a16,-a32|P=-a1,-a32,-a16|=-a1,-d,a14),-a224
> >
> > Content is not really important. The issue is that git is reporting fatal:
> > bad config line 2 in file .git/config when I escape the (, ), and |
> > characters.
> 
> That failure is understandable, as
> 
>     The following escape sequences (beside `\"` and `\\`) are recognized:
>     `\n` for newline character (NL), `\t` for horizontal tabulation (HT, TAB)
>     and `\b` for backspace (BS).  Other char escape sequences (including octal
>     escape sequences) are invalid.
> 
> is what Documentation/config.txt says.  \(, \) and \| is not a way
> to escape these letters from the .git/config parser (they do not
> need to be escaped from .git/config parser)..

Yes. It's a little unfriendly that we don't pass them through, since that would do what Randall wants here. But doing so would be unfriendly to somebody who _did_ want to quote them, and is confused why there are passed through literally.

At any rate, the "right" way here is to quote the backslashes that are meant to be passed through to the shell, like:

  textconv = foo \\(X\\|\\)

Note that if you write the config using git-config, that's what it produces:

  $ git config -f file foo.bar '\(X\|Y\)'
  $ cat file
  [foo]
	bar = \\(X\\|Y\\)

I agree that your double-quote suggestion is more readable (or as Randall eventually figured out, hiding it all in a real script ;) ).

-Peff
Previous: Junio C Hamano
Message 4 of 4 in “[Question] Complex textconv text”
  1. Randall S. BeckerDec 13, 2018
  2. Randall S. BeckerDec 13, 2018
  3. Junio C HamanoDec 14, 2018
  4. Jeff KingDec 14, 2018

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.