<feed xmlns='http://www.w3.org/2005/Atom'>
<title>git/add-patch.c, branch v2.28.1</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/git/git.git/
</subtitle>
<id>https://www.git.shady.money/git/atom?h=v2.28.1</id>
<link rel='self' href='https://www.git.shady.money/git/atom?h=v2.28.1'/>
<link rel='alternate' type='text/html' href='https://www.git.shady.money/git/'/>
<updated>2020-06-09T01:06:31Z</updated>
<entry>
<title>Merge branch 'js/checkout-p-new-file'</title>
<updated>2020-06-09T01:06:31Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2020-06-09T01:06:31Z</published>
<link rel='alternate' type='text/html' href='https://www.git.shady.money/git/commit/?id=2bdf00e66ae501c417fa33f887f2c60ef8719b2a'/>
<id>urn:sha1:2bdf00e66ae501c417fa33f887f2c60ef8719b2a</id>
<content type='text'>
"git checkout -p" did not handle a newly added path at all.

* js/checkout-p-new-file:
  checkout -p: handle new files correctly
</content>
</entry>
<entry>
<title>checkout -p: handle new files correctly</title>
<updated>2020-05-27T21:50:20Z</updated>
<author>
<name>Johannes Schindelin</name>
<email>johannes.schindelin@gmx.de</email>
</author>
<published>2020-05-27T21:09:06Z</published>
<link rel='alternate' type='text/html' href='https://www.git.shady.money/git/commit/?id=2c8bd8471a6abc68064dafc743362547fc730f77'/>
<id>urn:sha1:2c8bd8471a6abc68064dafc743362547fc730f77</id>
<content type='text'>
The original patch selection code was written for `git add -p`, and the
fundamental unit on which it works is a hunk.

We hacked around that to handle deletions back in 24ab81ae4d
(add-interactive: handle deletion of empty files, 2009-10-27). But `git
add -p` would never see a new file, since we only consider the set of
tracked files in the index.

However, since the same machinery was used for `git checkout -p` &amp;
friends, we can see new files.

Handle this case specifically, adding a new prompt for it that is
modeled after the `deleted file` case.

This also fixes the problem where added _empty_ files could not be
staged via `git checkout -p`.

Reported-by: Merlin Büge &lt;toni@bluenox07.de&gt;
Helped-by: Jeff King &lt;peff@peff.net&gt;
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>interactive: refactor code asking the user for interactive input</title>
<updated>2020-04-10T17:26:31Z</updated>
<author>
<name>Johannes Schindelin</name>
<email>johannes.schindelin@gmx.de</email>
</author>
<published>2020-04-10T11:27:50Z</published>
<link rel='alternate' type='text/html' href='https://www.git.shady.money/git/commit/?id=08d383f23e80e418c844952fcc4e2e635962c292'/>
<id>urn:sha1:08d383f23e80e418c844952fcc4e2e635962c292</id>
<content type='text'>
There are quite a few code locations (e.g. `git clean --interactive`)
where Git asks the user for an answer. In preparation for fixing a bug
shared by all of them, and also to DRY up the code, let's refactor it.

Please note that most of these callers trimmed white-space both at the
beginning and at the end of the answer, instead of trimming only the
end (as the caller in `add-patch.c` does).

Therefore, technically speaking, we change behavior in this patch. At
the same time, it can be argued that this is actually a bug fix.

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: 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://www.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://www.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://www.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://www.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://www.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://www.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://www.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>
