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

Re: Consider escaping special characters like 'less' does

From
Joris Valette <joris.valette@gmail.com>
Date
Oct 15, 2017, 21:37 UTC
Message-ID
<CA+o7MD84O5uTOz0xAGmd=xL+Hw8UsVCu5v_HEEeMWvAhSRQCeA@mail.gmail.com>
In-Reply-To
<20171015200635.e2u4qkxlz2xwpfov@sigill.intra.peff.net>
2017-10-15 22:06 GMT+02:00 Jeff King <peff@peff.net>:
> Git's diff generation will never do such escaping by default, because it
> means creating a patch that cannot be applied to get back the original
> content.

Indeed this would be a problem. That's where my knowledge of git's source code ends, but in that case, can't the output be discriminated against the command that was executed? Command that outputs an applicable patch -> don't escape Command that outputs a diff to see changes -> escape

Show 21 quoted lines
> There _are_ already options to create diffs that cannot be applied, like
> --textconv. So it would be possible to add a similar option for
> escaping. But I don't think we really need or want a separate option,
> when you can already do one of:
>
>   1. If your files have special binary characters that are hard to see,
>      you can use the existing textconv system to do whatever escaping
>      you like. And then the Git will diff the result of the escaping,
>      which means you get readable diffs when they change.
>
>   2. Put the raw output of git's diff through a filter that escapes. We
>      already do this most of the time by piping through less. The most
>      noticeable exception is "add --patch". There you can set up a
>      program to filter as well. There's more information in a recent
>      thread here:
>
>        https://public-inbox.org/git/20171012184736.rglkbyryauwuvn2a@sigill.intra.peff.net/
>
> It doesn't seem out of the question to me to have an out-of-the-box
> default for interactive.diffFilter which does some basic escaping (we
> could even implement it inside the perl script for efficiency).

Yes I read this thread, but I was left unsatisfied because I would like something out-of-the-box. Your suggestion might be the best solution then: implement some default escaping for interactive.diffFilter.

Joris
Previous: Jeff KingNext: Jeff King
Message 6 of 13 in “Consider escaping special characters like 'less' does”
  1. Joris ValetteOct 15, 2017
  2. Jason PyeronOct 15, 2017
  3. Andreas SchwabOct 15, 2017
  4. Joris ValetteOct 15, 2017
  5. Jeff KingOct 15, 2017
  6. Joris ValetteOct 15, 2017
  7. Jeff KingOct 16, 2017
  8. Andreas SchwabOct 16, 2017
  9. Jeff KingOct 16, 2017
  10. Junio C HamanoOct 17, 2017
  11. Jeff KingOct 17, 2017
  12. Jason PyeronOct 22, 2017
  13. Jeff KingOct 23, 2017

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.