example sugar script 'continuation-lines' added

This commit is contained in:
Sitaram Chamarty 2012-03-10 19:43:42 +05:30
parent 0fdd80f487
commit a9d5adcd10
3 changed files with 63 additions and 4 deletions

View file

@ -1,3 +1,16 @@
# and now for something completely different...
package SugarBox;
sub run_sugar_script {
my ($ss, $lref) = @_;
do $ss if -x $ss;
$lref = sugar_script($lref);
return $lref;
}
# ----------------------------------------------------------------------
package Gitolite::Conf::Sugar;
# syntactic sugar for the conf file, including site-local macros
@ -35,9 +48,14 @@ sub sugar {
_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);
# perl-ism; apart from keeping the full path separate from the
# simple name, this also protects %rc from change by implicit
# aliasing, which would happen if you touched $s itself
my $sfp = "$ENV{GL_BINDIR}/syntactic-sugar/$s";
_warn("skipped sugar script '$s'"), next if not -x $sfp;
$lines = SugarBox::run_sugar_script($sfp, $lines);
$lines = [ grep /\S/, map { cleanup_conf_line($_) } @$lines ];
}
}

View file

@ -158,11 +158,18 @@ __DATA__
# PLEASE READ THE DOCUMENTATION BEFORE EDITING OR ASKING QUESTIONS
# this file is in perl syntax. However, you do NOT need to know perl to edit
# it; it should be fairly self-explanatory and easy to maintain
# it; it should be fairly self-explanatory and easy to maintain. Just mind
# the commas, make sure the brackets and braces stay matched up!
%RC = (
UMASK => 0077,
GL_GITCONFIG_KEYS => "",
# uncomment as needed
SYNTACTIC_SUGAR =>
[
# 'continuation-lines',
]
);
# ------------------------------------------------------------------------------

View file

@ -0,0 +1,34 @@
# vim: syn=perl:
# "sugar script" (syntactic sugar helper) for gitolite3
# Enabling this script in the rc file allows you to use back-slash escaped
# continuation lines, like in C or shell etc.
# This script also serves as an example "sugar script" if you want to write
# your own (and maybe send them to me). A "sugar script" in gitolite will be
# executed via a perl 'do' and is expected to contain one function called
# 'sugar_script'. This function should take a listref and return a listref.
# Each item in the list is one line. There are NO newlines; g3 kills them off
# fairly early in the process.
# If you're not familiar with perl please do not try this. Ask me to write
# you a sugar script instead.
sub sugar_script {
my $lines = shift;
my @out = ();
my $keep = '';
for my $l (@$lines) {
if ($l =~ s/\\$//) {
$keep .= $l;
} else {
$l = $keep . $l if $keep;
$keep = '';
push @out, $l;
}
}
return \@out;
}