Skip to content
Browse files

compile: make the parse a function instead of inline

Again, prep for delegation, when we'll be reading fragments of config rules
from various files and tacking them onto the %repos hash.

note: this patch best viewed with "git diff -w", clicking "Ignore space
change" in gitk, or eqvt :-)
  • Loading branch information...
1 parent 3267c3f commit 34a6f89c265fce7c3ce35ac130d85e7861209157 Sitaram Chamarty committed Oct 2, 2009
Showing with 67 additions and 61 deletions.
  1. +67 −61 src/gl-compile-conf
View
128 src/gl-compile-conf
@@ -119,80 +119,86 @@ sub expand_list
# "compile" GL conf
# ----------------------------------------------------------------------------
-my $conf_fh = wrap_open( "<", $GL_CONF );
+sub parse_conf_file
+{
+ my ($conffile) = @_;
+ my $conf_fh = wrap_open( "<", $conffile );
-# the syntax is fairly simple, so we parse it inline
+ # the syntax is fairly simple, so we parse it inline
-my @repos;
-while (<$conf_fh>)
-{
- # normalise whitespace; keeps later regexes very simple
- s/=/ = /;
- s/\s+/ /g;
- s/^ //;
- s/ $//;
- # kill comments
- s/#.*//;
- # and blank lines
- next unless /\S/;
-
- # user or repo groups
- if (/^(@\S+) = (.*)/)
+ my @repos;
+ while (<$conf_fh>)
{
- do { $groups{$1}{$_} = 1 } for ( expand_list( split(' ', $2) ) );
- # again, we take the more "relaxed" pattern
- die "$ATTN bad group $1\n" unless $1 =~ $REPONAME_PATT;
- }
- # repo(s)
- elsif (/^repo (.*)/)
- {
- # grab the list and expand any @stuff in it
- @repos = split ' ', $1;
- @repos = expand_list ( @repos );
- }
- # actual permission line
- elsif (/^(R|RW|RW\+) (.* )?= (.+)/)
- {
- my $perms = $1;
- my @refs; @refs = split(' ', $2) if $2;
- my @users = split ' ', $3;
-
- # if no ref is given, this PERM applies to all refs
- @refs = qw(refs/.*) unless @refs;
- # fully qualify refs that dont start with "refs/"; prefix them with
- # "refs/heads/"
- @refs = map { m(^refs/) or s(^)(refs/heads/); $_ } @refs;
-
- # expand the user list, unless it is just "@all"
- @users = expand_list ( @users )
- unless (@users == 1 and $users[0] eq '@all');
- do { die "$ATTN bad username $_\n" unless $_ =~ $USERNAME_PATT } for @users;
-
- # ok, we can finally populate the %repos hash
- for my $repo (@repos) # each repo in the current stanza
+ # normalise whitespace; keeps later regexes very simple
+ s/=/ = /;
+ s/\s+/ /g;
+ s/^ //;
+ s/ $//;
+ # kill comments
+ s/#.*//;
+ # and blank lines
+ next unless /\S/;
+
+ # user or repo groups
+ if (/^(@\S+) = (.*)/)
+ {
+ do { $groups{$1}{$_} = 1 } for ( expand_list( split(' ', $2) ) );
+ # again, we take the more "relaxed" pattern
+ die "$ATTN bad group $1\n" unless $1 =~ $REPONAME_PATT;
+ }
+ # repo(s)
+ elsif (/^repo (.*)/)
+ {
+ # grab the list and expand any @stuff in it
+ @repos = split ' ', $1;
+ @repos = expand_list ( @repos );
+ }
+ # actual permission line
+ elsif (/^(R|RW|RW\+) (.* )?= (.+)/)
{
- for my $user (@users)
+ my $perms = $1;
+ my @refs; @refs = split(' ', $2) if $2;
+ my @users = split ' ', $3;
+
+ # if no ref is given, this PERM applies to all refs
+ @refs = qw(refs/.*) unless @refs;
+ # fully qualify refs that dont start with "refs/"; prefix them with
+ # "refs/heads/"
+ @refs = map { m(^refs/) or s(^)(refs/heads/); $_ } @refs;
+
+ # expand the user list, unless it is just "@all"
+ @users = expand_list ( @users )
+ unless (@users == 1 and $users[0] eq '@all');
+ do { die "$ATTN bad username $_\n" unless $_ =~ $USERNAME_PATT } for @users;
+
+ # ok, we can finally populate the %repos hash
+ for my $repo (@repos) # each repo in the current stanza
{
- $user_list{$user}++; # only to catch lint, see later
+ for my $user (@users)
+ {
+ $user_list{$user}++; # only to catch lint, see later
- # for 1st level check (see faq/tips doc)
- $repos{$repo}{R}{$user} = 1 if $perms =~ /R/;
- $repos{$repo}{W}{$user} = 1 if $perms =~ /W/;
+ # for 1st level check (see faq/tips doc)
+ $repos{$repo}{R}{$user} = 1 if $perms =~ /R/;
+ $repos{$repo}{W}{$user} = 1 if $perms =~ /W/;
- # for 2nd level check, store each "ref, perms" pair in order
- for my $ref (@refs)
- {
- push @{ $repos{$repo}{$user} }, { $ref => $perms };
+ # for 2nd level check, store each "ref, perms" pair in order
+ for my $ref (@refs)
+ {
+ push @{ $repos{$repo}{$user} }, { $ref => $perms };
+ }
}
}
}
- }
- else
- {
- die "$ATTN can't make head or tail of '$_'\n";
+ else
+ {
+ die "$ATTN can't make head or tail of '$_'\n";
+ }
}
}
+parse_conf_file($GL_CONF);
+
my $compiled_fh = wrap_open( ">", $GL_CONF_COMPILED );
print $compiled_fh Data::Dumper->Dump([\%repos], [qw(*repos)]);
close $compiled_fh or die "$ATTN close compiled-conf failed: $!\n";

0 comments on commit 34a6f89

Please sign in to comment.
Something went wrong with that request. Please try again.