From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-2.4 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_WEB,T_RP_MATCHES_RCVD shortcircuit=no autolearn=no autolearn_force=no version=3.4.0 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by dcvr.yhbt.net (Postfix) with ESMTP id 7E48F1F576 for ; Tue, 13 Feb 2018 10:44:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934234AbeBMKoc (ORCPT ); Tue, 13 Feb 2018 05:44:32 -0500 Received: from smtp-out-2.talktalk.net ([62.24.135.66]:8671 "EHLO smtp-out-2.talktalk.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934095AbeBMKoY (ORCPT ); Tue, 13 Feb 2018 05:44:24 -0500 Received: from lindisfarne.localdomain ([92.22.21.220]) by smtp.talktalk.net with SMTP id lY4NeT0Dyr5N9lY4UeMF1i; Tue, 13 Feb 2018 10:44:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=talktalk.net; s=cmr1711; t=1518518662; bh=tls9DGMH+5NUI/Tr0FrKuhz4O8q4oUSP2NcC5WoPkEo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:Reply-To; b=mQjBMAzkFq6kKisGb+kIYIFYOfM3YWZk4xBTv/XvB2p9P1l7aO0We9IElLg2Iw7A6 vz7oS6AcRWklX22ymgGGY+MTdEmND7pJdNtsIg8jH1xB3I0GgIpMH/MHwI+I0M8bNs ivP16Ufid875PmMZBG/hg47jZhlrARkEAGZ7GoTM= X-Originating-IP: [92.22.21.220] X-Spam: 0 X-OAuthority: v=2.2 cv=M9M9E24s c=1 sm=1 tr=0 a=VSxTZYxioCnvaH7igEU67w==:117 a=VSxTZYxioCnvaH7igEU67w==:17 a=evINK-nbAAAA:8 a=Vi1R3C_QCdLrTvDhwxkA:9 a=Vlfrem4tQV80DkA-:21 a=B7EWbvjf_PGqM3ch:21 a=RfR_gqz1fSpA9VikTjo0:22 From: Phillip Wood To: Git Mailing List Cc: Phillip Wood Subject: [PATCH 3/4] add -p: Adjust offsets of subsequent hunks when one is skipped Date: Tue, 13 Feb 2018 10:44:07 +0000 Message-Id: <20180213104408.9887-4-phillip.wood@talktalk.net> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180213104408.9887-1-phillip.wood@talktalk.net> References: <20180213104408.9887-1-phillip.wood@talktalk.net> Reply-To: Phillip Wood X-CMAE-Envelope: MS4wfNR7JzisyBvKFCCUs+CWAowm/8Qlu+xMInVfO06ruI+gIqOxIhN6CHZuFevq4Hxl+10DNmuQ6YON+04wIleXylaoQGXRR+VPvb+lGgYyVWOzcC334AUJ wNe7YPoy7diynSK3ueaSQvdR5SAugwE4iIrwpxe9eThNKHdW2xKn4NOwzZZ3AICGJjSkG8YA2JsMLav9HO9w1v94wcQaF0+tXUkqLKaJS92bcGABnC9VhGs9 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Phillip Wood 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 --- git-add--interactive.perl | 15 +++++++++++++-- t/t3701-add-interactive.sh | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/git-add--interactive.perl b/git-add--interactive.perl index 8ababa6453ac4f57a925aacbb8b9bb1c973e4a54..7a0a5896bb8fa063ace29b85840849c867b874f5 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} && diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh index 6838698a1382b24724cfbd3be04a7054489b94af..5401d74d5804b5e43286d08a905fb96c68b02e42 100755 --- a/t/t3701-add-interactive.sh +++ b/t/t3701-add-interactive.sh @@ -555,7 +555,7 @@ test_expect_success 'set up pathological context' ' EOF ' -test_expect_failure 'add -p works with pathological context lines' ' +test_expect_success 'add -p works with pathological context lines' ' git reset && printf "%s\n" n y | git add -p && -- 2.16.1