threads / discuss / 50028

[Question] Complex textconv text

Subject: [Question] Complex textconv text

## tl;dr

4 messages between Dec 13, 2018 and Dec 14, 2018.

replies: 3people: 3as markdown or json

Randall S. Becker· Dec 13, 2018, 15:07 UTC · lore
Hi all,

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. I get syntax errors otherwise from the shell running the textconv. I have tried --format="-a1(A=-a1,-a16,-a32|P=-a1,-a32,-a16|=-a1,-d,a14),-a224", to no avail. How should I safely escape the characters in here?

Thanks, Randall

-- Brief whoami:
 NonStop developer since approximately 211288444200000000
 UNIX developer since approximately 421664400
-- In my real life, I talk too much.
Randall S. Becker· Dec 13, 2018, 16:14 UTC · re: Randall S. Becker · lore

RE: [Question] Complex textconv text

On December 13, 2018 10:08, I wrote: 
> I have a strange situation and need help with resolving funky characters
in
Show 7 quoted lines
> .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.
Show 5 quoted lines
> 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. I
> get syntax errors otherwise from the shell running the textconv. I have
tried -
> -format="-a1(A=-a1,-a16,-a32|P=-a1,-a32,-a16|=-a1,-d,a14),-a224", to no
> avail. How should I safely escape the characters in here?

Easiest bypass was to wrap the mess above into a shell script and execute it that way, which works just fine. I'm not sure it's possible to escape all of the special characters. Seems like the safest approach anyway.

Cheers, Randall

Junio C Hamano· Dec 14, 2018, 03:12 UTC · re: Randall S. Becker · lore

Re: [Question] Complex textconv text

"Randall S. Becker" <rsbecker@nexbridge.com> writes:
Show 16 quoted lines
> Hi all,
>
> 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)..

> I get syntax errors otherwise from the shell running the
> textconv. I have tried
> --format="-a1(A=-a1,-a16,-a32|P=-a1,-a32,-a16|=-a1,-d,a14),-a224", to no
> avail.
Would 
	textconv = enscribe-conv --format=\"-a1(A=...,-a224\"
work?

We want to show the shell what you wrote so that pipes and parens are inside a dq pair, but the .git/config language strips pair of dq, so the .git/config language parser needs to be told that these dq are not for it to eat.

Jeff King· Dec 14, 2018, 10:04 UTC · re: Junio C Hamano · lore

Re: [Question] Complex textconv text

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

← back to recent threads