[PATCH v5 0/9] Correct offsets of hunks when one is skipped

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Phillip Wood <phillip.wood@xxxxxxxxxxxxx>

I've updated these to clean up the perl style in response to Junio's
comments on v4.

Cover letter to v1:

While working on a patch series to stage selected lines from a hunk
without having to edit it I got worried that subsequent patches would
be applied in the wrong place which lead to this series to correct the
offsets of hunks following those that are skipped or edited.

Interdiff to v4:
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index a64c0db57d..f83e7450ad 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -892,8 +892,11 @@ sub merge_hunk {
 	$o_cnt = $n_cnt = 0;
 	for ($i = 1; $i < @{$prev->{TEXT}}; $i++) {
 		my $line = $prev->{TEXT}[$i];
-		if ($line =~ /^[+\\]/) {
-			$n_cnt++ if ($line =~ /^\+/);
+		if ($line =~ /^\+/) {
+			$n_cnt++;
+			push @line, $line;
+			next;
+		} elsif ($line =~ /^\\/) {
 			push @line, $line;
 			next;
 		}
@@ -910,8 +913,11 @@ sub merge_hunk {
 
 	for ($i = 1; $i < @{$this->{TEXT}}; $i++) {
 		my $line = $this->{TEXT}[$i];
-		if ($line =~ /^[+\\]/) {
-			$n_cnt++ if ($line =~ /^\+/);
+		if ($line =~ /^\+/) {
+			$n_cnt++;
+			push @line, $line;
+			next;
+		} elsif ($line =~ /^\\/) {
 			push @line, $line;
 			next;
 		}
@@ -945,7 +951,9 @@ sub coalesce_overlapping_hunks {
 			$ofs_delta += $o_cnt - $n_cnt;
 			# If this hunk has been edited then subtract
 			# the delta that is due to the edit.
-			$_->{OFS_DELTA} and $ofs_delta -= $_->{OFS_DELTA};
+			if ($_->{OFS_DELTA}) {
+				$ofs_delta -= $_->{OFS_DELTA};
+			}
 			next;
 		}
 		if ($ofs_delta) {
@@ -955,7 +963,9 @@ sub coalesce_overlapping_hunks {
 		}
 		# If this hunk was edited then adjust the offset delta
 		# to reflect the edit.
-		$_->{OFS_DELTA} and $ofs_delta += $_->{OFS_DELTA};
+		if ($_->{OFS_DELTA}) {
+			$ofs_delta += $_->{OFS_DELTA};
+		}
 		if (defined $last_o_ctx &&
 		    $o_ofs <= $last_o_ctx &&
 		    !$_->{DIRTY} &&


Phillip Wood (9):
  add -i: add function to format hunk header
  t3701: indent here documents
  t3701: use test_write_lines and write_script
  t3701: don't hard code sha1 hash values
  t3701: add failing test for pathological context lines
  add -p: adjust offsets of subsequent hunks when one is skipped
  add -p: calculate offset delta for edited patches
  add -p: fix counting when splitting and coalescing
  add -p: don't rely on apply's '--recount' option

 git-add--interactive.perl  | 108 +++++++++++++----
 t/t3701-add-interactive.sh | 291 +++++++++++++++++++++++++--------------------
 2 files changed, 249 insertions(+), 150 deletions(-)

-- 
2.16.2




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux