<feed xmlns='http://www.w3.org/2005/Atom'>
<title>git/add-patch.c, branch v2.25.0</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/git/git.git/
</subtitle>
<id>https://www.git.shady.money/git/atom?h=v2.25.0</id>
<link rel='self' href='https://www.git.shady.money/git/atom?h=v2.25.0'/>
<link rel='alternate' type='text/html' href='https://www.git.shady.money/git/'/>
<updated>2019-12-13T20:37:14Z</updated>
<entry>
<title>built-in add -p: show helpful hint when nothing can be staged</title>
<updated>2019-12-13T20:37:14Z</updated>
<author>
<name>Johannes Schindelin</name>
<email>johannes.schindelin@gmx.de</email>
</author>
<published>2019-12-13T08:08:06Z</published>
<link rel='alternate' type='text/html' href='https://www.git.shady.money/git/commit/?id=2e4083198d1508206488af4c82093ceb6cf20f4e'/>
<id>urn:sha1:2e4083198d1508206488af4c82093ceb6cf20f4e</id>
<content type='text'>
This patch will make `git add -p` show "No changes." or "Only binary
files changed." in that case.

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: only show the applicable parts of the help text</title>
<updated>2019-12-13T20:37:14Z</updated>
<author>
<name>Johannes Schindelin</name>
<email>johannes.schindelin@gmx.de</email>
</author>
<published>2019-12-13T08:08:05Z</published>
<link rel='alternate' type='text/html' href='https://www.git.shady.money/git/commit/?id=54d9d9b2eebe1c8f8b54626f98a5e1414ce766ba'/>
<id>urn:sha1:54d9d9b2eebe1c8f8b54626f98a5e1414ce766ba</id>
<content type='text'>
When displaying the only hunk in a file's diff, the prompt already
excludes the commands to navigate to the previous/next hunk.

Let's also let the `?` command show only the help lines corresponding to
the commands that are displayed in the prompt.

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 'q' ("quit") command</title>
<updated>2019-12-13T20:37:14Z</updated>
<author>
<name>Johannes Schindelin</name>
<email>johannes.schindelin@gmx.de</email>
</author>
<published>2019-12-13T08:08:04Z</published>
<link rel='alternate' type='text/html' href='https://www.git.shady.money/git/commit/?id=ade246efed509a68348901e7a085ceb55915bfea'/>
<id>urn:sha1:ade246efed509a68348901e7a085ceb55915bfea</id>
<content type='text'>
This command is actually very similar to the 'd' ("do not stage this
hunk or any of the later hunks in the file") command: it just does
something on top, namely leave the loop and return a value indicating
that we're quittin'.

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 '/' ("search regex") command</title>
<updated>2019-12-13T20:37:14Z</updated>
<author>
<name>Johannes Schindelin</name>
<email>johannes.schindelin@gmx.de</email>
</author>
<published>2019-12-13T08:08:03Z</published>
<link rel='alternate' type='text/html' href='https://www.git.shady.money/git/commit/?id=d6cf873340703098f2d7f54be457e4db1b32cf7b'/>
<id>urn:sha1:d6cf873340703098f2d7f54be457e4db1b32cf7b</id>
<content type='text'>
This patch implements the hunk searching feature in the C version of
`git add -p`.

A test is added to verify that this behavior matches the one of the Perl
version of `git add -p`.

Note that this involves a change of behavior: the Perl version uses (of
course) the Perl flavor of regular expressions, while this patch uses
the regcomp()/regexec(), i.e. POSIX extended regular expressions. In
practice, this behavior change is unlikely to matter.

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 'g' ("goto") command</title>
<updated>2019-12-13T20:37:14Z</updated>
<author>
<name>Johannes Schindelin</name>
<email>johannes.schindelin@gmx.de</email>
</author>
<published>2019-12-13T08:08:02Z</published>
<link rel='alternate' type='text/html' href='https://www.git.shady.money/git/commit/?id=9254bdfb4f971be4be5364341a0387e8a1f3734a'/>
<id>urn:sha1:9254bdfb4f971be4be5364341a0387e8a1f3734a</id>
<content type='text'>
With this patch, it is now possible to see a summary of the available
hunks and to navigate between them (by number).

A test is added to verify that this behavior matches the one of the Perl
version of `git add -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 hunk editing</title>
<updated>2019-12-13T20:37:14Z</updated>
<author>
<name>Johannes Schindelin</name>
<email>johannes.schindelin@gmx.de</email>
</author>
<published>2019-12-13T08:08:01Z</published>
<link rel='alternate' type='text/html' href='https://www.git.shady.money/git/commit/?id=bcdd297b782b19782d8e09b18682ec61d7c36897'/>
<id>urn:sha1:bcdd297b782b19782d8e09b18682ec61d7c36897</id>
<content type='text'>
Just like `git add --edit` allows the user to edit the diff before it is
being applied to the index, this feature allows the user to edit the
diff *hunk*.

Naturally, it gets a bit more complicated here because the result has
to play well with the remaining hunks of the overall diff. Therefore,
we have to do a loop in which we let the user edit the hunk, then test
whether the result would work, and if not, drop the edits and let the
user decide whether to try editing the hunk again.

Note: in contrast to the Perl version, we use the same diff
"coalescing" (i.e. merging overlapping hunks into a single one) also for
the check after editing, and we introduce a new flag for that purpose
that asks the `reassemble_patch()` function to pretend that all hunks
were selected for use.

This allows us to continue to run `git apply` *without* the
`--allow-overlap` option (unlike the Perl version), and it also fixes
two known breakages in `t3701-add-interactive.sh` (which we cannot mark
as resolved so far because the Perl script version is still the default
and continues to have those breakages).

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: coalesce hunks after splitting them</title>
<updated>2019-12-13T20:37:14Z</updated>
<author>
<name>Johannes Schindelin</name>
<email>johannes.schindelin@gmx.de</email>
</author>
<published>2019-12-13T08:07:59Z</published>
<link rel='alternate' type='text/html' href='https://www.git.shady.money/git/commit/?id=11f2c0dae8f8889b533455d700121d437f4be19f'/>
<id>urn:sha1:11f2c0dae8f8889b533455d700121d437f4be19f</id>
<content type='text'>
This is considered "the right thing to do", according to 933e44d3a0
("add -p": work-around an old laziness that does not coalesce hunks,
2011-04-06).

Note: we cannot simply modify the hunks while merging them; Once we
implement hunk editing, we will call `reassemble_patch()` whenever a
hunk is edited, therefore we must not modify the hunks (because the user
might e.g. hit `K` and change their mind whether to stage the previous
hunk).

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 hunk splitting feature</title>
<updated>2019-12-13T20:37:14Z</updated>
<author>
<name>Johannes Schindelin</name>
<email>johannes.schindelin@gmx.de</email>
</author>
<published>2019-12-13T08:07:58Z</published>
<link rel='alternate' type='text/html' href='https://www.git.shady.money/git/commit/?id=510aeca199c4feeb38d318cc151ecf5464a3a865'/>
<id>urn:sha1:510aeca199c4feeb38d318cc151ecf5464a3a865</id>
<content type='text'>
If this developer's workflow is any indication, then this is *the* most
useful feature of Git's interactive `add `command.

Note: once again, this is not a verbatim conversion from the Perl code
to C: the `hunk_splittable()` function, for example, essentially did all
the work of splitting the hunk, just to find out whether more than one
hunk would have been the result (and then tossed that result into the
trash). In C we instead count the number of resulting hunks (without
actually doing the work of splitting, but just counting the transitions
from non-context lines to context lines), and store that information
with the hunk, and we do that *while* parsing the diff in the first
place.

Another deviation: the built-in `git add -p` was designed with a single
strbuf holding the diff (and another one holding the colored diff, if
that one was asked for) in mind, and hunks essentially store just the
start and end offsets pointing into that strbuf. As a consequence, when
we split hunks, we now use a special mode where the hunk header is
generated dynamically, and only the rest of the hunk is stored using
such start/end offsets. This way, we also avoid the frequent
formatting/re-parsing of the hunk header of the Perl version.

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: show different prompts for mode changes and deletions</title>
<updated>2019-12-13T20:37:14Z</updated>
<author>
<name>Johannes Schindelin</name>
<email>johannes.schindelin@gmx.de</email>
</author>
<published>2019-12-13T08:07:57Z</published>
<link rel='alternate' type='text/html' href='https://www.git.shady.money/git/commit/?id=0ecd9d27fc3b38c19cf75d7cad98d0120adb7383'/>
<id>urn:sha1:0ecd9d27fc3b38c19cf75d7cad98d0120adb7383</id>
<content type='text'>
Just like the Perl version, we now helpfully ask the user whether they
want to stage a mode change, or a deletion.

Note that we define the prompts in an array, in preparation for a later
patch that changes those prompts to yet different versions for `git
reset -p`, `git stash -p` and `git checkout -p` (which all call the `git
add -p` machinery to do the actual work).

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 app -p: allow selecting a mode change as a "hunk"</title>
<updated>2019-12-13T20:37:14Z</updated>
<author>
<name>Johannes Schindelin</name>
<email>johannes.schindelin@gmx.de</email>
</author>
<published>2019-12-13T08:07:56Z</published>
<link rel='alternate' type='text/html' href='https://www.git.shady.money/git/commit/?id=5906d5de77628e956d708e9a1796c12bee316b59'/>
<id>urn:sha1:5906d5de77628e956d708e9a1796c12bee316b59</id>
<content type='text'>
This imitates the way the Perl version treats mode changes: it offers
the mode change up for the user to decide, as if it was a diff hunk.

In contrast to the Perl version, we make use of the fact that the mode
line is the first hunk, and explicitly strip out that line from the diff
header if that "hunk" was not selected to be applied, and skipping that
hunk while coalescing the diff. The Perl version plays some kind of diff
line lego instead.

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>
