Fix for edge case Diff::LCS traversals. Also ensure re-edit state is
authorMahlon E. Smith <mahlon@laika.com>
Thu, 18 Apr 2013 12:06:48 -0700
changeset 54 0cc20d93ff50
parent 53 ae62c24653ef
child 55 d7392bebb86c
Fix for edge case Diff::LCS traversals. Also ensure re-edit state is cleared in between attempts.
shelldap
--- a/shelldap	Tue Mar 19 16:36:30 2013 -0700
+++ b/shelldap	Thu Apr 18 12:06:48 2013 -0700
@@ -1511,6 +1511,7 @@
 	if ( $hash_orig eq $self->chksum($self->{'ldif_fname'}) ) {
 		print "Entry not modified.\n";
 		unlink $self->{'ldif_fname'};
+		$self->{'edit_again'} = undef;
 		return;
 	}
 
@@ -1523,6 +1524,7 @@
 		}
 		else {
 			unlink $self->{'ldif_fname'};
+			$self->{'edit_again'} = undef;
 			return;
 		}
 	}
@@ -1554,7 +1556,7 @@
 		my $diff_bit = $diff->Diff();
 		my %seen_attr;
 
-		# attr removals
+		# attr removal hunk
 		#
 		if ( $diff_bit == 1 ) {
 			foreach ( $diff->Items(1) ) {
@@ -1564,7 +1566,7 @@
 			}
 		}
 
-		# attr insertions
+		# attr insertion hunk
 		#
 		if ( $diff_bit == 2 ) {
 			foreach ( $diff->Items(2) ) {
@@ -1574,9 +1576,12 @@
 			}
 		}
 
-		# attr change
+		# attr change hunk
 		#
 		if ( $diff_bit == 3 ) {
+
+			# modification to existing line
+			#
 			foreach ( $diff->Items(2) ) {
 				my ( $attr, $val ) = $parse->( $_ ) or next;
 				$self->debug("MODIFY: $_");
@@ -1608,6 +1613,15 @@
 					$e->replace( $attr => \@new_vals );
 				}
 			}
+
+			# deletion within the same hunk
+			#
+			foreach ( $diff->Items(1) ) {
+				my ( $attr, $val ) = $parse->( $_ ) or next;
+				next if $seen_attr{ $attr };
+				$self->debug("DELETE: $_");
+				$e->delete( $attr => [ $val ] );
+			}
 		}
 	}
 
@@ -2143,7 +2157,7 @@
 use warnings;
 
 $0 = 'shelldap';
-my $VERSION = '1.0.0';
+my $VERSION = '1.0.1';
 
 use Getopt::Long;
 use YAML::Syck;