Fix for edge case Diff::LCS traversals. Also ensure re-edit state is

cleared in between attempts.

FossilOrigin-Name: b5f423d47a752b8e4f68a622ef1afe984ccc1f2e130de0aae5aa110309ab16d3
This commit is contained in:
mahlon@laika.com 2013-04-18 19:06:47 +00:00
parent 5ada092f95
commit cbbb816258

View file

@ -1511,6 +1511,7 @@ sub run_edit
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 @@ sub run_edit
}
else {
unlink $self->{'ldif_fname'};
$self->{'edit_again'} = undef;
return;
}
}
@ -1554,7 +1556,7 @@ sub run_edit
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 @@ sub run_edit
}
}
# attr insertions
# attr insertion hunk
#
if ( $diff_bit == 2 ) {
foreach ( $diff->Items(2) ) {
@ -1574,9 +1576,12 @@ sub run_edit
}
}
# 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 @@ sub run_edit
$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 strict;
use warnings;
$0 = 'shelldap';
my $VERSION = '1.0.0';
my $VERSION = '1.0.1';
use Getopt::Long;
use YAML::Syck;