Combine multiple lines into a single one before displaying LDIF. Patch

by Gertjan Halkes <shelldap@ghalkes.nl>.

FossilOrigin-Name: c842c6cb3fb22ced491f1ddc9bb155f729b9dd31e19c5f6c52d38896e5a9f3a1
This commit is contained in:
mahlon@laika.com 2011-02-17 20:35:21 +00:00
parent 29f2cdb50c
commit ae4fb82877

View file

@ -867,6 +867,21 @@ sub comp_create
}
}
sub unwrap {
my $array = shift;
my $iter = 1;
while ($iter < $#$array) {
if (@$array[$iter] =~ m/^\W/) {
@$array[$iter - 1] =~ s/\n$//;
@$array[$iter] =~ s/^\W//;
splice(@$array, $iter - 1, 2, @$array[$iter - 1] . @$array[$iter]);
} else {
$iter++;
}
}
}
###############################################################
#
# SHELL METHODS
@ -1233,13 +1248,15 @@ sub run_edit
my $parse = sub {
my $line = shift || $_;
return unless $line =~ /^\w/; # ignore multiline
return if $line =~ /^\#/; # ignore comments
my ( $attr, $val ) = ( $1, $2 ) if $line =~ /^(.+?): (.*)$/;
return if index($attr, ':') != -1; # ignore base64
return ( $attr, $val );
};
unwrap(\@orig_ldif);
unwrap(\@new_ldif);
my $diff = Algorithm::Diff->new( \@orig_ldif, \@new_ldif );
HUNK:
while ( $diff->Next() ) {
@ -1250,7 +1267,6 @@ sub run_edit
# total deletions
if ( $diff_bit == 1 ) {
foreach ( $diff->Items(1) ) {
next unless /\w+/;
$self->debug("DELETE: $_");
my ( $attr, $val ) = $parse->( $_ ) or next;
$e->delete( $attr => [ $val ] );
@ -1260,7 +1276,6 @@ sub run_edit
# new insertions
if ( $diff_bit == 2 ) {
foreach ( $diff->Items(2) ) {
next unless /\w+/;
$self->debug("INSERT: $_");
my ( $attr, $val ) = $parse->( $_ ) or next;
$e->add( $attr => $val );
@ -1268,10 +1283,8 @@ sub run_edit
}
# replacements
# these are trickier with multivalue lines
if ( $diff_bit == 3 ) {
foreach ( $diff->Items(2) ) {
next unless /\w+/;
$self->debug("MODIFY: $_");
my ( $attr, $val ) = $parse->( $_ ) or next;