1 # and now for something completely different...
6 my ( $ss, $lref ) = @_;
8 $lref = sugar_script
($lref);
12 # ----------------------------------------------------------------------
14 package Gitolite
::Conf
::Sugar
;
16 # syntactic sugar for the conf file, including site-local macros
17 # ----------------------------------------------------------------------
23 use Exporter
'import';
27 use Gitolite
::Conf
::Explode
;
32 # ----------------------------------------------------------------------
35 # gets a filename, returns a listref
38 explode
( shift, 'master', \
@lines );
43 # run through the sugar stack one by one
45 # first, user supplied sugar:
46 if ( exists $rc{SYNTACTIC_SUGAR
} ) {
47 if ( ref( $rc{SYNTACTIC_SUGAR
} ) ne 'ARRAY' ) {
48 _warn
"bad syntax for specifying sugar scripts; see docs";
50 for my $s ( @
{ $rc{SYNTACTIC_SUGAR
} } ) {
52 # perl-ism; apart from keeping the full path separate from the
53 # simple name, this also protects %rc from change by implicit
54 # aliasing, which would happen if you touched $s itself
55 my $sfp = _which
( "syntactic-sugar/$s", 'r' );
57 _warn
("skipped sugar script '$s'"), next if not -r
$sfp;
58 $lines = SugarBox
::run_sugar_script
( $sfp, $lines );
59 $lines = [ grep /\S/, map { cleanup_conf_line
($_) } @
$lines ];
66 $lines = rw_cdm
($lines);
67 $lines = option
($lines); # must come after rw_cdm
68 $lines = owner_desc
($lines);
69 $lines = name_vref
($lines);
70 $lines = role_names
($lines);
71 $lines = skip_block
($lines);
80 # repo foo <...> RWC = ...
81 # -> option CREATE_IS_C = 1
82 # (and similarly DELETE_IS_D and MERGE_CHECK)
83 # but only once per repo of course
86 for my $line (@
$lines) {
88 if ( $line =~ /^repo / ) {
90 } elsif ( $line =~ /^(-|C|R|RW\+?(?:C?D?|D?C?)M?) (.* )?= (.+)/ ) {
92 push @ret, "option DELETE_IS_D = 1" if $perms =~ /D/ and not $seen{D
}++;
93 push @ret, "option CREATE_IS_C = 1" if $perms =~ /RW.*C/ and not $seen{C
}++;
94 push @ret, "option MERGE_CHECK = 1" if $perms =~ /M/ and not $seen{M
}++;
105 # -> config gitolite-options.foo = bar
107 for my $line (@
$lines) {
108 $line =~ s/option mirror\.slaves/option mirror.copies/;
109 if ( $line =~ /^option (\S+) = (\S.*)/ ) {
110 push @ret, "config gitolite-options.$1 = $2";
122 # owner = "owner name"
123 # -> config gitweb.owner = owner name
124 # desc = "some long description"
125 # -> config gitweb.description = some long description
126 # category = "whatever..."
127 # -> config gitweb.category = whatever...
129 for my $line (@
$lines) {
130 if ( $line =~ /^desc = (\S.*)/ ) {
131 push @ret, "config gitweb.description = $1";
132 } elsif ( $line =~ /^owner = (\S.*)/ ) {
133 push @ret, "config gitweb.owner = $1";
134 } elsif ( $line =~ /^category = (\S.*)/ ) {
135 push @ret, "config gitweb.category = $1";
147 # <perm> NAME/foo = <user>
148 # -> <perm> VREF/NAME/foo = <user>
150 for my $line (@
$lines) {
151 if ( $line =~ /^(-|R\S+) \S.* = \S.*/ ) {
152 $line =~ s
( NAME
/)( VREF/NAME
/)g
;
163 # <perm> [<ref>] = <user list containing CREATOR|READERS|WRITERS>
164 # -> same but with "@" prepended to rolenames
166 for my $line (@
$lines) {
167 if ( $line =~ /^(-|C|R|RW\+?(?:C?D?|D?C?)M?) (.* )?= (.+)/ ) {
168 my ( $p, $r ) = ( $1, $2 );
170 for ( split ' ', $3 ) {
171 $_ = "\@$_" if $_ eq 'CREATOR' or $rc{ROLES
}{$_};
175 # mind the spaces (or play safe and run cleanup_conf_line again)
176 push @ret, cleanup_conf_line
("$p $r = $u");
190 $skip = 1 if /^= *begin testconf$/;
191 $skip = 1 if /^= *begin template-data$/;
192 # add code for other types of blocks here as needed
194 next if $skip .. /^= *end$/;