From: Jeff King <peff@peff.net>
To: Mahmoud Al-Qudsi <mqudsi@neosmart.net>
Cc: git@vger.kernel.org
Subject: Re: (Some?) control codes not escaped when using `git add -p`
Date: Thu, 12 Oct 2017 14:47:36 -0400 [thread overview]
Message-ID: <20171012184736.rglkbyryauwuvn2a@sigill.intra.peff.net> (raw)
In-Reply-To: <CACcTrKctqAWeWWrc9Q+Y7ewXGc_o+uJoeHS83LDw5O_s1-3Nug@mail.gmail.com>
On Thu, Oct 12, 2017 at 12:59:06PM -0500, Mahmoud Al-Qudsi wrote:
> Hello list,
>
> Running git 2.7.4, I’ve run into an issue where control codes that would
> normally be escaped when using `git diff` are not similarly escaped when using
> `git add -p`.
>
> As a concrete example, I have a text file including the following "text":
>
> :map ^[[H <Home>
> :map ^[[5~ ^B "page up
> :map ^[[6~ ^F "page down
The diffs generated for "git diff" and "git add -p" are done by the
exact same code. And that code doesn't do any escaping or cleverness; it
will output the raw bytes of the difference.
What is likely causing the different in what you see is that "git diff".
outputs through a pager, and the snippets of "add -p" do not. The
default pager, "less", does escape some control codes (but with the -R
option, which git uses by default, it passes through colors).
Try:
git --no-pager diff
or:
GIT_PAGER=cat git diff
and you'll likely see output similar to what you get with "add -p".
The reason that "add -p" doesn't go through a pager by default is simply
that it would be annoying, since we show snippets and then ask for user
input.
However, since Git v2.9.0, "add -p" (and all of the interactive commands
like "checkout -p", etc) know about the interactive.diffFilter config
option. You could use that to munge the results however you like. E.g.:
# we can't use [:cntrl:] here because we want to keep newlines.
# likewise, we want to keep ESC for color codes
git config interactive.diffFilter "tr '\000-\011\013-\032\034-\037' '?'"
-Peff
prev parent reply other threads:[~2017-10-12 18:47 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-12 17:59 (Some?) control codes not escaped when using `git add -p` Mahmoud Al-Qudsi
2017-10-12 18:47 ` Jeff King [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171012184736.rglkbyryauwuvn2a@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=mqudsi@neosmart.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).