clean up use of IkiWiki::Receive
authorJoey Hess <joey@gnu.kitenet.net>
Thu, 10 Sep 2009 20:09:19 +0000 (16:09 -0400)
committerJoey Hess <joey@gnu.kitenet.net>
Thu, 10 Sep 2009 20:15:48 +0000 (16:15 -0400)
Loading and use of IkiWiki::Receive can all be pushed into the git plugin,
rather than scattered around.

I had at first wanted to make a receive plugin and move it there,
but a plugin was not a good fit; you don't want users to have to manually
load it, and making the git plugin load the receive plugin at the right
times would need more, and ugly code.

IkiWiki/Plugin/git.pm
IkiWiki/Receive.pm
IkiWiki/Wrapper.pm
ikiwiki.in

index 68b114a7328332a54d8e66426bd09dc1eec0b030..ad58231e0bbd897e0f65dec50cc1be451fa3c92a 100644 (file)
@@ -14,6 +14,7 @@ my $no_chdir=0;
 sub import {
        hook(type => "checkconfig", id => "git", call => \&checkconfig);
        hook(type => "getsetup", id => "git", call => \&getsetup);
+       hook(type => "genwrapper", id => "git", call => \&genwrapper);
        hook(type => "rcs", id => "rcs_update", call => \&rcs_update);
        hook(type => "rcs", id => "rcs_prepedit", call => \&rcs_prepedit);
        hook(type => "rcs", id => "rcs_commit", call => \&rcs_commit);
@@ -41,6 +42,7 @@ sub checkconfig () {
                        wrappermode => (defined $config{git_wrappermode} ? $config{git_wrappermode} : "06755"),
                };
        }
+
        if (defined $config{git_test_receive_wrapper} &&
            length $config{git_test_receive_wrapper}) {
                push @{$config{wrappers}}, {
@@ -49,6 +51,13 @@ sub checkconfig () {
                        wrappermode => (defined $config{git_wrappermode} ? $config{git_wrappermode} : "06755"),
                };
        }
+       
+       # Run receive test only if being called by the wrapper, and not
+       # when generating same.
+       if ($config{test_receive} && ! exists $config{wrapper}) {
+               require IkiWiki::Receive;
+               IkiWiki::Receive::test();
+       }
 }
 
 sub getsetup () {
@@ -115,6 +124,16 @@ sub getsetup () {
                },
 }
 
+sub genwrapper {
+       if ($config{test_receive}) {
+               require IkiWiki::Receive;
+               return IkiWiki::Receive::genwrapper();
+       }
+       else {
+               return "";
+       }
+}
+
 sub safe_git (&@) {
        # Start a child process safely without resorting /bin/sh.
        # Return command output or success state (in scalar context).
index 37b6f2a62667600c0ad181eb448d4629504bdd4c..101c13ee5582ddbf6c33230ae74351497bfa1b69 100644 (file)
@@ -1,5 +1,4 @@
 #!/usr/bin/perl
-
 package IkiWiki::Receive;
 
 use warnings;
@@ -20,9 +19,9 @@ sub trusted () {
                ! grep { $_ eq $user } @{$config{untrusted_committers}};
 }
 
-sub gen_wrapper () {
+sub genwrapper () {
        # Test for commits from untrusted committers in the wrapper, to
-       # avoid loading ikiwiki at all for trusted commits.
+       # avoid starting ikiwiki proper at all for trusted commits.
 
        my $ret=<<"EOF";
        {
@@ -37,6 +36,8 @@ EOF
                        "u != $uid";
                } @{$config{untrusted_committers}}).
                ") exit(0);\n";
+
+       
        $ret.=<<"EOF";
                asprintf(&s, "CALLER_UID=%i", u);
                newenviron[i++]=s;
index cf85738d68163763e8ac2bb1c7fc2ab04ef69187..ff110b5ffb9763cb5fbb9248c0b5d95bc52fb5e1 100644 (file)
@@ -37,10 +37,6 @@ sub gen_wrapper () {
                addenv("$var", s);
 EOF
        }
-
-       if ($config{test_receive}) {
-               require IkiWiki::Receive;
-       }
        
        my @wrapper_hooks;
        run_hooks(genwrapper => sub { push @wrapper_hooks, shift->() });
index 4e9b812f852cb4b9805c51d7af6c0d0576d8a976..b8581d880eea398ac10a697c311f36428a18a67c 100755 (executable)
@@ -190,10 +190,6 @@ sub main () {
        elsif ($config{post_commit} && ! commit_hook_enabled()) {
                # do nothing
        }
-       elsif ($config{test_receive}) {
-               require IkiWiki::Receive;
-               IkiWiki::Receive::test();
-       }
        else {
                if ($config{rebuild}) {
                        debug(gettext("rebuilding wiki.."));