summaryrefslogtreecommitdiff
path: root/git-add--interactive.perl
diff options
context:
space:
mode:
authorPhillip Wood <phillip.wood@dunelm.org.uk>2018-03-01 10:51:00 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-03-01 19:39:15 (GMT)
commitfecc6f3a6862c55dee0e9a2390acaf4b23991fef (patch)
tree39aa5de17d2a04356169f092ba3cec93bd54a382 /git-add--interactive.perl
parent23fea4c240218d519da01e6d2d64264084a7334c (diff)
downloadgit-fecc6f3a6862c55dee0e9a2390acaf4b23991fef.zip
git-fecc6f3a6862c55dee0e9a2390acaf4b23991fef.tar.gz
git-fecc6f3a6862c55dee0e9a2390acaf4b23991fef.tar.bz2
add -p: adjust offsets of subsequent hunks when one is skipped
Since commit 8cbd431082 ("git-add--interactive: replace hunk recounting with apply --recount", 2008-7-2) if a hunk is skipped then we rely on the context lines to apply subsequent hunks in the right place. While this works most of the time it is possible for hunks to end up being applied in the wrong place. To fix this adjust the offset of subsequent hunks to correct for any change in the number of insertions or deletions due to the skipped hunk. The change in offset due to edited hunks that have the number of insertions or deletions changed is ignored here, it will be fixed in the next commit. Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-add--interactive.perl')
-rwxr-xr-xgit-add--interactive.perl15
1 files changed, 13 insertions, 2 deletions
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index 64f869c..6f6a21d 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -926,14 +926,25 @@ sub coalesce_overlapping_hunks {
my @out = ();
my ($last_o_ctx, $last_was_dirty);
+ my $ofs_delta = 0;
- for (grep { $_->{USE} } @in) {
+ for (@in) {
if ($_->{TYPE} ne 'hunk') {
push @out, $_;
next;
}
my $text = $_->{TEXT};
- my ($o_ofs) = parse_hunk_header($text->[0]);
+ my ($o_ofs, $o_cnt, $n_ofs, $n_cnt) =
+ parse_hunk_header($text->[0]);
+ unless ($_->{USE}) {
+ $ofs_delta += $o_cnt - $n_cnt;
+ next;
+ }
+ if ($ofs_delta) {
+ $n_ofs += $ofs_delta;
+ $_->{TEXT}->[0] = format_hunk_header($o_ofs, $o_cnt,
+ $n_ofs, $n_cnt);
+ }
if (defined $last_o_ctx &&
$o_ofs <= $last_o_ctx &&
!$_->{DIRTY} &&