sugar high!
make it easy to handle syntactic sugar. In summary, compile now calls parse(sugar('gitolite.conf')). Details: - cleanup_conf_line went from subar.pm to common.pm - explode() and minions went from conf.pm to the new explode.pm - the callback went away; everyone just passes whole arrays around now - the new sugar() takes a filename and returns a listref - all sugar scripts take and return a listref - the first "built-in" sugar is written (setting gitweb.owner and gitweb.description) the new RC file format (of being a hash called %rc) is getting a nice workout :-)
This commit is contained in:
parent
4ab8db4925
commit
acb2f8fe8e
4 changed files with 219 additions and 170 deletions
|
@ -4,78 +4,97 @@ package Gitolite::Conf::Sugar;
|
|||
# ----------------------------------------------------------------------
|
||||
|
||||
@EXPORT = qw(
|
||||
macro_expand
|
||||
cleanup_conf_line
|
||||
sugar
|
||||
);
|
||||
|
||||
use Exporter 'import';
|
||||
|
||||
use lib $ENV{GL_BINDIR};
|
||||
use Gitolite::Common;
|
||||
use Gitolite::Rc;
|
||||
use Gitolite::Common;
|
||||
use Gitolite::Conf::Explode;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
|
||||
sub macro_expand {
|
||||
# site-local macros, if any, then gitolite internal macros, to munge the
|
||||
# input conf line if needed
|
||||
sub sugar {
|
||||
# gets a filename, returns a listref
|
||||
|
||||
my @lines = @_;
|
||||
my @lines = ();
|
||||
explode(shift, 'master', \@lines);
|
||||
|
||||
# TODO: user macros, how to allow the user to specify them?
|
||||
my $lines;
|
||||
$lines = \@lines;
|
||||
|
||||
# cheat, to keep *our* regexes simple :)
|
||||
# XXX but this also kills the special '# BEGIN filename' and '# END
|
||||
# filename' lines that explode() surrounds the actual data with when it
|
||||
# called macro_expand(). Right now we don't need it, but...
|
||||
@lines = grep /\S/, map { cleanup_conf_line($_) } @lines;
|
||||
# run through the sugar stack one by one
|
||||
|
||||
@lines = owner_desc(@lines);
|
||||
# first, user supplied sugar:
|
||||
if (exists $rc{SYNTACTIC_SUGAR}) {
|
||||
if (ref($rc{SYNTACTIC_SUGAR}) ne 'ARRAY') {
|
||||
_warn "bad syntax for specifying sugar scripts; see docs";
|
||||
} else {
|
||||
for my $s (@{ $rc{SYNTACTIC_SUGAR} }) {
|
||||
_warn "ignoring unreadable sugar script $s" if not -r $s;
|
||||
do $s if -r $s;
|
||||
$lines = sugar_script($lines);
|
||||
$lines = [ grep /\S/, map { cleanup_conf_line($_) } @$lines ];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return @lines;
|
||||
}
|
||||
# then our stuff:
|
||||
|
||||
sub cleanup_conf_line {
|
||||
my $line = shift;
|
||||
$lines = owner_desc($lines);
|
||||
# $lines = name_vref($lines);
|
||||
|
||||
# kill comments, but take care of "#" inside *simple* strings
|
||||
$line =~ s/^((".*?"|[^#"])*)#.*/$1/;
|
||||
# normalise whitespace; keeps later regexes very simple
|
||||
$line =~ s/=/ = /;
|
||||
$line =~ s/\s+/ /g;
|
||||
$line =~ s/^ //;
|
||||
$line =~ s/ $//;
|
||||
return $line;
|
||||
return $lines;
|
||||
}
|
||||
|
||||
sub owner_desc {
|
||||
my @lines = @_;
|
||||
my $lines = shift;
|
||||
my @ret;
|
||||
|
||||
for my $line (@lines) {
|
||||
# reponame = "some description string"
|
||||
# reponame "owner name" = "some description string"
|
||||
# XXX compat breakage: (1) adding repo/owner does not automatically add an
|
||||
# entry to projects.list -- we need a post-procesor for that, and (2)
|
||||
# removing the 'repo' line no longer suffices to remove the config entry
|
||||
# from projects.list. Maybe the post-procesor should do that as well?
|
||||
|
||||
# owner = "owner name"
|
||||
# -> config gitweb.owner = owner name
|
||||
# description = "some long description"
|
||||
# -> config gitweb.description = some long description
|
||||
# category = "whatever..."
|
||||
# -> config gitweb.category = whatever...
|
||||
|
||||
# older formats:
|
||||
# repo = "some long description"
|
||||
# repo = "owner name" = "some long description"
|
||||
# -> config gitweb.owner = owner name
|
||||
# -> config gitweb.description = some long description
|
||||
|
||||
for my $line (@$lines) {
|
||||
if ( $line =~ /^(\S+)(?: "(.*?)")? = "(.*)"$/ ) {
|
||||
my ( $repo, $owner, $desc ) = ( $1, $2, $3 );
|
||||
# XXX these two checks should go into add_config
|
||||
# _die "bad repo name '$repo'" unless $repo =~ $REPONAME_PATT;
|
||||
# _die "$fragment attempting to set description for $repo"
|
||||
# if check_fragment_repo_disallowed( $fragment, $repo );
|
||||
push @ret, "config gitolite-options.repo-desc = $desc";
|
||||
push @ret, "config gitolite-options.repo-owner = $owner" if $owner;
|
||||
push @ret, "repo $repo";
|
||||
push @ret, "config gitweb.description = $desc";
|
||||
push @ret, "config gitweb.owner = $owner" if $owner;
|
||||
} elsif ( $line =~ /^desc = (\S.*)/ ) {
|
||||
push @ret, "config gitolite-options.repo-desc = $1";
|
||||
push @ret, "config gitweb.description = $1";
|
||||
} elsif ( $line =~ /^owner = (\S.*)/ ) {
|
||||
my ( $repo, $owner, $desc ) = ( $1, $2, $3 );
|
||||
push @ret, "config gitolite-options.repo-owner = $1";
|
||||
push @ret, "config gitweb.owner = $1";
|
||||
} elsif ( $line =~ /^category = (\S.*)/ ) {
|
||||
push @ret, "config gitweb.category = $1";
|
||||
} else {
|
||||
push @ret, $line;
|
||||
}
|
||||
}
|
||||
return @ret;
|
||||
return \@ret;
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue