~ubuntu-branches/ubuntu/utopic/gitolite3/utopic-proposed

« back to all changes in this revision

Viewing changes to src/lib/Gitolite/Conf.pm

  • Committer: Package Import Robot
  • Author(s): David Bremner
  • Date: 2013-05-18 17:59:21 UTC
  • Revision ID: package-import@ubuntu.com-20130518175921-ac4xe6vd0jtxvjot
Tags: upstream-3.5.1+4
ImportĀ upstreamĀ versionĀ 3.5.1+4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package Gitolite::Conf;
 
2
 
 
3
# explode/parse a conf file
 
4
# ----------------------------------------------------------------------
 
5
 
 
6
@EXPORT = qw(
 
7
  compile
 
8
  explode
 
9
  parse
 
10
);
 
11
 
 
12
use Exporter 'import';
 
13
use Getopt::Long;
 
14
 
 
15
use Gitolite::Common;
 
16
use Gitolite::Rc;
 
17
use Gitolite::Conf::Sugar;
 
18
use Gitolite::Conf::Store;
 
19
 
 
20
use strict;
 
21
use warnings;
 
22
 
 
23
# ----------------------------------------------------------------------
 
24
 
 
25
sub compile {
 
26
    _die "'gitolite compile' does not take any arguments" if @_;
 
27
 
 
28
    _chdir( $rc{GL_ADMIN_BASE} );
 
29
    _chdir("conf");
 
30
 
 
31
    parse( sugar('gitolite.conf') );
 
32
 
 
33
    # the order matters; new repos should be created first, to give store a
 
34
    # place to put the individual gl-conf files
 
35
    new_repos();
 
36
    store();
 
37
 
 
38
    for my $repo ( @{ $rc{NEW_REPOS_CREATED} } ) {
 
39
        trigger( 'POST_CREATE', $repo );
 
40
    }
 
41
}
 
42
 
 
43
sub parse {
 
44
    my $lines = shift;
 
45
    trace( 2, scalar(@$lines) . " lines incoming" );
 
46
 
 
47
    for my $line (@$lines) {
 
48
        # user or repo groups
 
49
        if ( $line =~ /^(@\S+) = (.*)/ ) {
 
50
            add_to_group( $1, split( ' ', $2 ) );
 
51
        } elsif ( $line =~ /^repo (.*)/ ) {
 
52
            set_repolist( split( ' ', $1 ) );
 
53
        } elsif ( $line =~ /^(-|C|R|RW\+?(?:C?D?|D?C?)M?) (.* )?= (.+)/ ) {
 
54
            my $perm  = $1;
 
55
            my @refs  = parse_refs( $2 || '' );
 
56
            my @users = parse_users($3);
 
57
 
 
58
            for my $ref (@refs) {
 
59
                for my $user (@users) {
 
60
                    add_rule( $perm, $ref, $user );
 
61
                }
 
62
            }
 
63
        } elsif ( $line =~ /^config (.+) = ?(.*)/ ) {
 
64
            my ( $key, $value ) = ( $1, $2 );
 
65
            $value =~ s/^['"](.*)["']$/$1/;
 
66
            my @validkeys = split( ' ', ( $rc{GIT_CONFIG_KEYS} || '' ) );
 
67
            push @validkeys, "gitolite-options\\..*";
 
68
            my @matched = grep { $key =~ /^$_$/ } @validkeys;
 
69
            _die "git config '$key' not allowed\ncheck GIT_CONFIG_KEYS in the rc file" if ( @matched < 1 );
 
70
            _die "bad value '$value'" if $value =~ $UNSAFE_PATT;
 
71
            add_config( 1, $key, $value );
 
72
        } elsif ( $line =~ /^subconf (\S+)$/ ) {
 
73
            trace( 2, $line );
 
74
            set_subconf($1);
 
75
        } else {
 
76
            _warn "syntax error, ignoring: '$line'";
 
77
        }
 
78
    }
 
79
    parse_done();
 
80
}
 
81
 
 
82
1;