Permalink
Browse files

example sugar script 'continuation-lines' added

  • Loading branch information...
1 parent 0fdd80f commit a9d5adcd106329ab1802e0197ffea44d479e0649 @sitaramc sitaramc committed Mar 10, 2012
Showing with 63 additions and 4 deletions.
  1. +21 −3 src/Gitolite/Conf/Sugar.pm
  2. +8 −1 src/Gitolite/Rc.pm
  3. +34 −0 src/syntactic-sugar/continuation-lines
View
@@ -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
@@ -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',
+ ]
);
# ------------------------------------------------------------------------------
@@ -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;
+}

0 comments on commit a9d5adc

Please sign in to comment.