Reduce disk writes in post-compile triggers
[gitolite.git] / src / syntactic-sugar / continuation-lines
blobd63475ff7139c9d1d1ae33d379769c0b2b0e9334
1 # vim: syn=perl:
3 # "sugar script" (syntactic sugar helper) for gitolite3
5 # Enabling this script in the rc file allows you to use back-slash escaped
6 # continuation lines, like in C or shell etc.
8 # This script also serves as an example "sugar script" if you want to write
9 # your own (and maybe send them to me).  A "sugar script" in gitolite will be
10 # executed via a perl 'do' and is expected to contain one function called
11 # 'sugar_script'.  This function should take a listref and return a listref.
12 # Each item in the list is one line.  There are NO newlines; g3 kills them off
13 # fairly early in the process.
15 # If you're not familiar with perl please do not try this.  Ask me to write
16 # you a sugar script instead.
18 sub sugar_script {
19     my $lines = shift;
21     my @out  = ();
22     my $keep = '';
23     for my $l (@$lines) {
24         # skip RULE_INFO lines if in continuation mode
25         next if $keep and $l =~ /^ *#/;
26         if ( $l =~ s/\\$// ) {
27             $keep .= $l;
28         } else {
29             $l = $keep . $l if $keep;
30             $keep = '';
31             push @out, $l;
32         }
33     }
35     return \@out;