From a9d5adcd106329ab1802e0197ffea44d479e0649 Mon Sep 17 00:00:00 2001 From: Sitaram Chamarty Date: Sat, 10 Mar 2012 19:43:42 +0530 Subject: [PATCH] example sugar script 'continuation-lines' added --- src/Gitolite/Conf/Sugar.pm | 24 +++++++++++++++--- src/Gitolite/Rc.pm | 9 ++++++- src/syntactic-sugar/continuation-lines | 34 ++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 4 deletions(-) create mode 100755 src/syntactic-sugar/continuation-lines diff --git a/src/Gitolite/Conf/Sugar.pm b/src/Gitolite/Conf/Sugar.pm index 881cbcf..dbf0926 100644 --- a/src/Gitolite/Conf/Sugar.pm +++ b/src/Gitolite/Conf/Sugar.pm @@ -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 ]; } } diff --git a/src/Gitolite/Rc.pm b/src/Gitolite/Rc.pm index 18cc6c5..0b81bf8 100644 --- a/src/Gitolite/Rc.pm +++ b/src/Gitolite/Rc.pm @@ -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', + ] ); # ------------------------------------------------------------------------------ diff --git a/src/syntactic-sugar/continuation-lines b/src/syntactic-sugar/continuation-lines new file mode 100755 index 0000000..1d25379 --- /dev/null +++ b/src/syntactic-sugar/continuation-lines @@ -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; +}