From 17ad237cd599702f805122508a0dc3bafdc020d0 Mon Sep 17 00:00:00 2001 From: Nicolas Vigier Date: Mon, 7 Oct 2013 17:08:13 +0200 Subject: 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. --- NEWS | 2 ++ lib/MGA/Git.pm | 26 ++++++++++++++++++++++---- 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); } -- cgit v1.2.1