POST_CREATE efficiency... (please read below if you care)

The POST_CREATE trigger is called when

  * a user creates a new "wild" repo,
  * a user uses the "perms" command, and
  * a user uses the "fork" command.

The trigger calls 3 programs (see rc file):

    post-compile/update-git-configs
    post-compile/update-gitweb-access-list
    post-compile/update-git-daemon-access-list

(They are also called by the POST_COMPILE trigger, by the way.)

However, the 3 programs shown are a bit wasteful -- they run through
*all* the repos when really only *one* repo has been affected.

This patch

  * passes the repo name to the 3 programs (duh!)

  * adds the optimisation to the first of the 3 programs listed above
    (the one dealing with 'git config').

For the other two programs (gitweb and git-daemon), you have 3 choices:

  * if you don't have too many repos, ignore the problem.

  * take out the 2nd and 3rd lines from the POST_CREATE list in the rc
    file, so they don't run.

    Then run 'gitolite trigger POST_COMPILE' from cron at regular
    intervals.  (Note that is POST_COMPILE not POST_CREATE!)  However,
    this means that gitweb and daemon permissions won't be current
    immediately after someone adds a new repo or sets perms etc.; they
    get updated only on the next cron run.

  * patch the programs to add this optimisation (and send me the
    patches).  The optimisation would check if arg-1 ($1 in shell,
    $ARGV[0] in perl) is 'POST_CREATE', and if it is, take the *next*
    argument as a repo name that may have changed.
This commit is contained in:
Sitaram Chamarty 2012-04-22 21:25:54 +05:30
parent 895b3614ed
commit 198dcfd4c8
3 changed files with 22 additions and 5 deletions

View file

@ -59,4 +59,4 @@ ln -sf `gitolite query-rc GL_ADMIN_BASE`/hooks/common/* hooks
echo "$from" > gl-forked-from echo "$from" > gl-forked-from
# trigger post_create # trigger post_create
gitolite trigger POST_CREATE gitolite trigger POST_CREATE $to $GL_USER

View file

@ -34,8 +34,9 @@ if ( $ARGV[0] eq '-l' ) {
getperms(@ARGV); # doesn't return getperms(@ARGV); # doesn't return
} }
my $repo = shift;
setperms(@ARGV); setperms(@ARGV);
_system( "gitolite", "trigger", "POST_CREATE" ); _system( "gitolite", "trigger", "POST_CREATE", $repo, $ENV{GL_USER} );
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
@ -50,7 +51,6 @@ sub getperms {
} }
sub setperms { sub setperms {
my $repo = shift;
_die "sorry you are not authorised" if repo_missing($repo) or creator($repo) ne $ENV{GL_USER}; _die "sorry you are not authorised" if repo_missing($repo) or creator($repo) ne $ENV{GL_USER};
my $pf = "$rc{GL_REPO_BASE}/$repo.git/gl-perms"; my $pf = "$rc{GL_REPO_BASE}/$repo.git/gl-perms";

View file

@ -13,13 +13,30 @@ use Gitolite::Conf::Load;
use strict; use strict;
use warnings; use warnings;
# ----------------------------------------------------------------------
my $RB = $rc{GL_REPO_BASE}; my $RB = $rc{GL_REPO_BASE};
_chdir($RB); _chdir($RB);
# ----------------------------------------------------------------------
# if called from POST_CREATE, we have only a single repo to worry about
if (@ARGV and $ARGV[0] eq 'POST_CREATE') {
my $repo = $ARGV[1];
fixup_config($repo);
exit 0;
}
# ----------------------------------------------------------------------
# else it's all repos (i.e., called from POST_COMPILE)
my $lpr = list_phy_repos(); my $lpr = list_phy_repos();
for my $pr (@$lpr) { for my $pr (@$lpr) {
fixup_config($pr);
}
sub fixup_config {
my $pr = shift;
my $gc = git_config( $pr, '.' ); my $gc = git_config( $pr, '.' );
while ( my ( $key, $value ) = each( %{$gc} ) ) { while ( my ( $key, $value ) = each( %{$gc} ) ) {
next if $key =~ /^gitolite-options\./; next if $key =~ /^gitolite-options\./;