]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki/Wrapper.pm
remove some unimportant changelog entries to cut it down a bit..
[git.ikiwiki.info.git] / IkiWiki / Wrapper.pm
index 238f71a91bdc28360e6a0910b1d391c8d45e25d0..52a7ca2c70e4ab05b45e5b3c2b852e43e57731f0 100644 (file)
@@ -4,6 +4,7 @@ use warnings;
 use strict;
 use Cwd q{abs_path};
 use Data::Dumper;
+use IkiWiki;
 
 package IkiWiki;
 
@@ -28,7 +29,6 @@ sub gen_wrapper () { #{{{
        push @envsave, qw{REMOTE_ADDR QUERY_STRING REQUEST_METHOD REQUEST_URI
                       CONTENT_TYPE CONTENT_LENGTH GATEWAY_INTERFACE
                       HTTP_COOKIE} if $config{cgi};
-       push @envsave, qw{REV} if $config{svn};
        my $envsave="";
        foreach my $var (@envsave) {
                $envsave.=<<"EOF"
@@ -36,11 +36,22 @@ sub gen_wrapper () { #{{{
                asprintf(&newenviron[i++], "%s=%s", "$var", s);
 EOF
        }
+       if ($config{rcs} eq "svn" && $config{notify}) {
+               # Support running directly as hooks/post-commit by passing
+               # $2 in REV in the environment.
+               $envsave.=<<"EOF"
+       if (argc == 3)
+               asprintf(&newenviron[i++], "REV=%s", argv[2]);
+       else if ((s=getenv("REV")))
+               asprintf(&newenviron[i++], "%s=%s", "REV", s);
+EOF
+       }
        
        $Data::Dumper::Indent=0; # no newlines
        my $configstring=Data::Dumper->Dump([\%config], ['*config']);
        $configstring=~s/\\/\\\\/g;
        $configstring=~s/"/\\"/g;
+       $configstring=~s/\n/\\\n/g;
        
        open(OUT, ">$wrapper.c") || error("failed to write $wrapper.c: $!");;
        print OUT <<"EOF";
@@ -56,7 +67,7 @@ extern char **environ;
 int main (int argc, char **argv) {
        /* Sanitize environment. */
        char *s;
-       char *newenviron[$#envsave+4];
+       char *newenviron[$#envsave+5];
        int i=0;
 $envsave
        newenviron[i++]="HOME=$ENV{HOME}";