aboutsummaryrefslogtreecommitdiffstats
path: root/lib/MGA/Git.pm
diff options
context:
space:
mode:
authorNicolas Vigier <boklm@mars-attacks.org>2013-10-07 17:08:13 +0200
committerNicolas Vigier <boklm@mars-attacks.org>2013-10-07 17:08:13 +0200
commit17ad237cd599702f805122508a0dc3bafdc020d0 (patch)
treeffdc770768bdf3b49609db00d0e13aa2a4ee8d26 /lib/MGA/Git.pm
parentf4d92bf6686072b0889e9843cf55ac8d0ad1a59a (diff)
downloadmgagit-17ad237cd599702f805122508a0dc3bafdc020d0.tar
mgagit-17ad237cd599702f805122508a0dc3bafdc020d0.tar.gz
mgagit-17ad237cd599702f805122508a0dc3bafdc020d0.tar.bz2
mgagit-17ad237cd599702f805122508a0dc3bafdc020d0.tar.xz
mgagit-17ad237cd599702f805122508a0dc3bafdc020d0.zip
Add the repo_conf and origin_conf functions in templates
And remove the duplication of options from main repo definition to each repo definition. Now that we can use the repo_conf function this is no longer useful.
Diffstat (limited to 'lib/MGA/Git.pm')
-rw-r--r--lib/MGA/Git.pm26
1 files changed, 22 insertions, 4 deletions
diff --git a/lib/MGA/Git.pm b/lib/MGA/Git.pm
index f87e9af..72407c4 100644
--- a/lib/MGA/Git.pm
+++ b/lib/MGA/Git.pm
@@ -43,7 +43,7 @@ sub load_gitrepos_dir {
my $name = "$infos->{prefix}/$bname";
$r->{repos}{$name} = LoadFile("$infos->{include_dir}/$file");
$r->{repos}{$name}{name} = $bname;
- @{$r->{repos}{$name}}{keys %$infos} = values %$infos;
+ $r->{repos}{$name}{origin} = $infos->{origin};
} elsif ($file =~ m/(.+)\.group$/ && exists $infos->{group_prefix}) {
my $bname = $1;
my $name = $infos->{group_prefix} . $bname;
@@ -62,19 +62,35 @@ sub load_gitrepos {
my ($r) = @_;
$r->{repos} = {};
foreach my $repodef (@{$config->{repos_config}}) {
+ $repodef->{origin} = $repodef->{prefix};
if ($repodef->{include_dir} || $repodef->{git_url}) {
load_gitrepos_dir($r, $repodef);
}
foreach my $repo ($repodef->{repos} ? @{$repodef->{repos}} : ()) {
my $name = "$repodef->{prefix}/$repo->{name}";
+ $repo->{origin} = $repodef->{origin};
$r->{repos}{$name} = $repo;
- my %infos = %$repodef;
- delete $infos{repos};
- @{$r->{repos}{$name}}{keys %infos} = values %infos;
}
}
}
+sub origin_config {
+ my ($r, $reponame, $confname) = @_;
+ my $origin = $r->{repos}{$reponame}{origin};
+ foreach my $repodef (@{$config->{repos_config}}) {
+ next unless ($repodef->{prefix} eq $origin);
+ return $repodef->{$confname} if defined $repodef->{$confname};
+ last;
+ }
+ return $config->{$confname};
+}
+
+sub repo_config {
+ my ($r, $reponame, $confname) = @_;
+ my $res = $r->{repos}{$reponame}{$confname};
+ return defined $res ? $res : origin_config($r, $reponame, $confname);
+}
+
sub get_ldap {
state $ldap;
return $ldap if $ldap;
@@ -151,6 +167,8 @@ sub gitolite_repo_config {
r => $r,
repo => $repo,
config => $config,
+ repo_conf => sub { repo_config($r, $repo, @_) },
+ origin_conf => sub { origin_config($r, $repo, @_) },
};
return process_tmpl($r->{repos}{$repo}{gl_template}, 'gl', $vars);
}