aboutsummaryrefslogtreecommitdiffstats
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
parentf4d92bf6686072b0889e9843cf55ac8d0ad1a59a (diff)
downloadmgagit-17ad237cd599702f.tar
mgagit-17ad237cd599702f.tar.gz
mgagit-17ad237cd599702f.tar.bz2
mgagit-17ad237cd599702f.tar.xz
mgagit-17ad237cd599702f.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.
-rw-r--r--NEWS2
-rw-r--r--lib/MGA/Git.pm26
2 files changed, 24 insertions, 4 deletions
diff --git a/NEWS b/NEWS
index 552d02a..4b8ee28 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,8 @@
- soft_repo.gl: Put maintainer nick in square brackets
- allow non-ldap group definitions
- add the showconf command, to show repos configuration in yaml
+- don't copy the repodef options to each repo definition
+- add the repo_conf and origin_conf functions in templates
Version 0.10
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);
}