new sugar function to help with RW+CDM

This commit is contained in:
Sitaram Chamarty 2012-03-17 22:30:02 +05:30
parent a6a666af78
commit 5ae9b4abab

View file

@ -63,13 +63,38 @@ sub sugar {
# then our stuff:
$lines = option($lines);
$lines = rw_cdm($lines);
$lines = option($lines); # must come after rw_cdm
$lines = owner_desc($lines);
$lines = name_vref($lines);
return $lines;
}
sub rw_cdm {
my $lines = shift;
my @ret;
# repo foo <...> RWC = ...
# -> option CREATE_IS_C = 1
# (and similarly DELETE_IS_D and MERGE_CHECK)
# but only once per repo of course
my %seen = ();
for my $line (@$lines) {
push @ret, $line;
if ( $line =~ /^repo / ) {
%seen = ();
} elsif ( $line =~ /^(-|C|R|RW\+?(?:C?D?|D?C?)M?) (.* )?= (.+)/ ) {
my $perms = $1;
push @ret, "option DELETE_IS_D = 1" if $perms =~ /D/ and not $seen{D}++;
push @ret, "option CREATE_IS_C = 1" if $perms =~ /RW.*C/ and not $seen{C}++;
push @ret, "option MERGE_CHECK = 1" if $perms =~ /M/ and not $seen{M}++;
}
}
return \@ret;
}
sub option {
my $lines = shift;
my @ret;