<feed xmlns='http://www.w3.org/2005/Atom'>
<title>git/add-interactive.h, branch v2.51.2</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/git/git.git/
</subtitle>
<id>https://git.shady.money/git/atom?h=v2.51.2</id>
<link rel='self' href='https://git.shady.money/git/atom?h=v2.51.2'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/'/>
<updated>2025-09-08T21:00:32Z</updated>
<entry>
<title>add-interactive: respect color.diff for diff coloring</title>
<updated>2025-09-08T21:00:32Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2025-09-08T16:42:36Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=8c78b5c8bc42728dcc8a527401955b7d1089e667'/>
<id>urn:sha1:8c78b5c8bc42728dcc8a527401955b7d1089e667</id>
<content type='text'>
The old perl git-add--interactive.perl script used the color.diff config
option to decide whether to color diffs (and if not set, it fell back to
the value of color.ui via git-config's --get-colorbool option). When we
switched to the builtin version, this was lost: we respect only
color.ui. So for example:

  git -c color.diff=false add -p

would color the diff, even when it should not.

The culprit is this line in add-interactive.c's parse_diff():

  if (want_color_fd(1, -1))

That "-1" means "no config has been set", which causes it to fall back
to the color.ui setting. We should instead be passing the value of
color.diff. But the problem is that we never even parse that config
option!

Instead the builtin interactive code parses only the value of
color.interactive, which is used for prompts and other messages. One
could perhaps argue that this should cover interactive diff coloring,
too, but historically it did not. The perl script treated
color.interactive and color.diff separately. So we should grab the
values for both, keeping separate fields in our add_i_state variable,
rather than a single use_color field.

We also load individual color slots (e.g., color.interactive.prompt),
leaving them as the empty string when color is disabled. This happens
via the init_color() helper in add-interactive, which checks that
use_color field. Now that there are two such fields, we need to pass the
appropriate one for each color.

The colors are mostly easy to divide up; color.interactive.* follows
color.interactive, and color.diff.* follows color.diff. But the "reset"
color is tricky. It is used for both types of coloring, but the two can
be configured independently. So we introduce two separate reset colors,
and use each in the appropriate spot.

There are two new tests. The first enables interactive prompt colors but
disables color.diff. We should see a colored prompt but not a colored
diff, showing that we are now respecting color.diff (and not
color.interactive or color.ui).

The second does the opposite. We disable color.interactive but turn on
color.diff with a custom fragment color. When we split a hunk, the
interactive code has to re-color the hunk header, which lets us check
that we correctly loaded the color.diff.frag config based on color.diff,
not color.interactive.

Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>add-patch: add diff.context command line overrides</title>
<updated>2025-07-29T15:52:45Z</updated>
<author>
<name>Leon Michalak</name>
<email>leonmichalak6@gmail.com</email>
</author>
<published>2025-07-29T07:01:51Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=2b3ae04011c3d679ba601c7ef9e20b9dec125ebb'/>
<id>urn:sha1:2b3ae04011c3d679ba601c7ef9e20b9dec125ebb</id>
<content type='text'>
This patch compliments the previous commit, where builtins that use
add-patch infrastructure now respect diff.context and
diff.interHunkContext file configurations.

In particular, this patch helps users who don't want to set persistent
context configurations or just want a way to override them on a one-time
basis, by allowing the relevant builtins to accept corresponding command
line options that override the file configurations.

This mimics commands such as diff and log, which allow for both context
file configuration and command line overrides.

Signed-off-by: Leon Michalak &lt;leonmichalak6@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>add-patch: respect diff.context configuration</title>
<updated>2025-07-29T15:52:45Z</updated>
<author>
<name>Leon Michalak</name>
<email>leonmichalak6@gmail.com</email>
</author>
<published>2025-07-29T07:01:50Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=2b0a2db2c0bf4870592656e8f50876957db8660c'/>
<id>urn:sha1:2b0a2db2c0bf4870592656e8f50876957db8660c</id>
<content type='text'>
Various builtins that use add-patch infrastructure do not respect
the user's diff.context and diff.interHunkContext file configurations.

The user may be used to seeing their diffs with customized context size,
but not in the patches "git add -p" shows them to pick from.

Teach add-patch infrastructure to read these configuration variables and
pass their values when spawning the underlying plumbing commands as
their command line option.

Signed-off-by: Leon Michalak &lt;leonmichalak6@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>built-in add -p: respect the `interactive.singlekey` config setting</title>
<updated>2020-01-15T20:06:17Z</updated>
<author>
<name>Johannes Schindelin</name>
<email>johannes.schindelin@gmx.de</email>
</author>
<published>2020-01-14T18:43:50Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=04f816b125dc2649e70aad686d79b05bdc1d1c61'/>
<id>urn:sha1:04f816b125dc2649e70aad686d79b05bdc1d1c61</id>
<content type='text'>
The Perl version of `git add -p` supports this config setting to allow
users to input commands via single characters (as opposed to having to
press the &lt;Enter&gt; key afterwards).

This is an opt-in feature because it requires Perl packages
(Term::ReadKey and Term::Cap, where it tries to handle an absence of the
latter package gracefully) to work. Note that at least on Ubuntu, that
Perl package is not installed by default (it needs to be installed via
`sudo apt-get install libterm-readkey-perl`), so this feature is
probably not used a whole lot.

In C, we obviously do not have these packages available, but we just
introduced `read_single_keystroke()` that is similar to what
Term::ReadKey provides, and we use that here.

Signed-off-by: Johannes Schindelin &lt;johannes.schindelin@gmx.de&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>built-in add -p: handle diff.algorithm</title>
<updated>2020-01-15T20:06:16Z</updated>
<author>
<name>Johannes Schindelin</name>
<email>johannes.schindelin@gmx.de</email>
</author>
<published>2020-01-14T18:43:46Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=08b1ea4c39b08b76fe2d1240ccbf6077ef19226a'/>
<id>urn:sha1:08b1ea4c39b08b76fe2d1240ccbf6077ef19226a</id>
<content type='text'>
The Perl version of `git add -p` reads the config setting
`diff.algorithm` and if set, uses it to generate the diff using the
specified algorithm.

This patch ports that functionality to the C version.

Note: just like `git-add--interactive.perl`, we do _not_ respect this
config setting in `git add -i`'s `diff` command, but _only_ in the
`patch` command.

Signed-off-by: Johannes Schindelin &lt;johannes.schindelin@gmx.de&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>built-in add -p: support interactive.diffFilter</title>
<updated>2020-01-15T20:06:16Z</updated>
<author>
<name>Johannes Schindelin</name>
<email>johannes.schindelin@gmx.de</email>
</author>
<published>2020-01-14T18:43:45Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=180f48df69d8e7a1a413d7c11907ecf975f09cf7'/>
<id>urn:sha1:180f48df69d8e7a1a413d7c11907ecf975f09cf7</id>
<content type='text'>
The Perl version supports post-processing the colored diff (that is
generated in addition to the uncolored diff, intended to offer a
prettier user experience) by a command configured via that config
setting, and now the built-in version does that, too.

Signed-off-by: Johannes Schindelin &lt;johannes.schindelin@gmx.de&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>built-in add -p: implement the "worktree" patch modes</title>
<updated>2019-12-22T00:06:22Z</updated>
<author>
<name>Johannes Schindelin</name>
<email>johannes.schindelin@gmx.de</email>
</author>
<published>2019-12-21T21:57:15Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=cee6cb7300354740ff765c74d535ba5d5f9b332e'/>
<id>urn:sha1:cee6cb7300354740ff765c74d535ba5d5f9b332e</id>
<content type='text'>
This is a straight-forward port of 2f0896ec3ad4 (restore: support
--patch, 2019-04-25) which added support for `git restore -p`.

Signed-off-by: Johannes Schindelin &lt;johannes.schindelin@gmx.de&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>built-in add -p: implement the "checkout" patch modes</title>
<updated>2019-12-22T00:06:22Z</updated>
<author>
<name>Johannes Schindelin</name>
<email>johannes.schindelin@gmx.de</email>
</author>
<published>2019-12-21T21:57:14Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=52628f94fc35f57f0b3c54e4f849e490bfa44449'/>
<id>urn:sha1:52628f94fc35f57f0b3c54e4f849e490bfa44449</id>
<content type='text'>
This patch teaches the built-in `git add -p` machinery all the tricks it
needs to know in order to act as the work horse for `git checkout -p`.

Apart from the minor changes (slightly reworded messages, different
`diff` and `apply --check` invocations), it requires a new function to
actually apply the changes, as `git checkout -p` is a bit special in
that respect: when the desired changes do not apply to the index, but
apply to the work tree, Git does not fail straight away, but asks the
user whether to apply the changes to the worktree at least.

Signed-off-by: Johannes Schindelin &lt;johannes.schindelin@gmx.de&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>built-in add -p: implement the "stash" and "reset" patch modes</title>
<updated>2019-12-22T00:06:21Z</updated>
<author>
<name>Johannes Schindelin</name>
<email>johannes.schindelin@gmx.de</email>
</author>
<published>2019-12-21T21:57:11Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=36bae1dc0ee777aa529dd955f2e619281265f262'/>
<id>urn:sha1:36bae1dc0ee777aa529dd955f2e619281265f262</id>
<content type='text'>
The `git stash` and `git reset` commands support a `--patch` option, and
both simply hand off to `git add -p` to perform that work. Let's teach
the built-in version of that command to be able to perform that work, too.

Signed-off-by: Johannes Schindelin &lt;johannes.schindelin@gmx.de&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>built-in add -p: prepare for patch modes other than "stage"</title>
<updated>2019-12-22T00:06:21Z</updated>
<author>
<name>Johannes Schindelin</name>
<email>johannes.schindelin@gmx.de</email>
</author>
<published>2019-12-21T21:57:10Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=d2a233cb8b9e0f7210df68c35e751e00419a8488'/>
<id>urn:sha1:d2a233cb8b9e0f7210df68c35e751e00419a8488</id>
<content type='text'>
The Perl script backing `git add -p` is used not only for that command,
but also for `git stash -p`, `git reset -p` and `git checkout -p`.

In preparation for teaching the C version of `git add -p` to support
also the latter commands, let's abstract away what is "stage" specific
into a dedicated data structure describing the differences between the
patch modes.

Finally, please note that the Perl version tries to make sure that the
diffs are only generated for the modified files. This is not actually
necessary, as the calls to Git's diff machinery already perform that
work, and perform it well. This makes it unnecessary to port the
`FILTER` field of the `%patch_modes` struct, as well as the
`get_diff_reference()` function.

Signed-off-by: Johannes Schindelin &lt;johannes.schindelin@gmx.de&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
</feed>
