With Git 2.25 (Q1 2020), The effort to move "git-add--interactive
" Perl script to C continues.
As a result, the hunk splitting feature (the one accessed with the 's' key) will change.
See commit 2e40831, commit 54d9d9b, commit ade246e, commit d6cf873, commit 9254bdf, commit bcdd297, commit b38dd9e, commit 11f2c0d, commit 510aeca, commit 0ecd9d2, commit 5906d5d, commit 47dc4fd, commit 80399ae, commit 7584dd3, commit 12c24cf, commit 25ea47a, commit e3bd11b, commit 1942ee4, commit f6aa7ec (13 Dec 2019) by Johannes Schindelin (dscho
).
(Merged by Junio C Hamano -- gitster
-- in commit 45b96a6, 25 Dec 2019)
built-in add -p
: implement the hunk splitting feature
Signed-off-by: Johannes Schindelin
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.