]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/commitdiff
autoindex: use add_autofile
authorSimon McVittie <smcv@debian.org>
Thu, 6 Jan 2011 00:15:28 +0000 (00:15 +0000)
committerSimon McVittie <smcv@debian.org>
Sat, 22 Jan 2011 22:25:48 +0000 (22:25 +0000)
This does cause a minor regression: index pages are now committed
individually rather than being a single commit per rebuild.

This also means the autoindex regression test needs to trigger the
autofile generation pass.

IkiWiki/Plugin/autoindex.pm
t/autoindex.t

index 11595e217cdccf6d7bb571a3bb9f6c79ef4ddd7f..ba2dcb907ce9657f1792432e3efd4dec2f977f5f 100644 (file)
@@ -22,12 +22,23 @@ sub getsetup () {
 sub genindex ($) {
        my $page=shift;
        my $file=newpagefile($page, $config{default_pageext});
 sub genindex ($) {
        my $page=shift;
        my $file=newpagefile($page, $config{default_pageext});
-       my $template=template("autoindex.tmpl");
-       $template->param(page => $page);
-       writefile($file, $config{srcdir}, $template->output);
-       if ($config{rcs}) {
-               IkiWiki::rcs_add($file);
-       }
+
+       add_autofile($file, "autoindex", sub {
+                       my $message = sprintf(gettext("creating index page %s"),
+                               $page);
+                       debug($message);
+
+                       my $template = template("autoindex.tmpl");
+                       $template->param(page => $page);
+                       writefile($file, $config{srcdir}, $template->output);
+
+                       if ($config{rcs}) {
+                               IkiWiki::disable_commit_hook();
+                               IkiWiki::rcs_add($file);
+                               IkiWiki::rcs_commit_staged(message => $message);
+                               IkiWiki::enable_commit_hook();
+                       }
+               });
 }
 
 sub refresh () {
 }
 
 sub refresh () {
@@ -66,7 +77,10 @@ sub refresh () {
 
                chdir($origdir) || die "chdir $origdir: $!";
        }
 
                chdir($origdir) || die "chdir $origdir: $!";
        }
-       
+
+       # FIXME: some of this is probably redundant with add_autofile now, and
+       # the rest should perhaps be added to the autofile machinery
+
        my %deleted;
        if (ref $wikistate{autoindex}{deleted}) {
                %deleted=%{$wikistate{autoindex}{deleted}};
        my %deleted;
        if (ref $wikistate{autoindex}{deleted}) {
                %deleted=%{$wikistate{autoindex}{deleted}};
@@ -109,18 +123,9 @@ sub refresh () {
        }
        
        if (@needed) {
        }
        
        if (@needed) {
-               if ($config{rcs}) {
-                       IkiWiki::disable_commit_hook();
-               }
                foreach my $page (@needed) {
                        genindex($page);
                }
                foreach my $page (@needed) {
                        genindex($page);
                }
-               if ($config{rcs}) {
-                       IkiWiki::rcs_commit_staged(
-                               message => gettext("automatic index generation"),
-                       );
-                       IkiWiki::enable_commit_hook();
-               }
        }
 }
 
        }
 }
 
index b1425c22eedc51813028ba602839e9b6f7b90c92..04d668fbc8fc159b54194852a9db5119b4b52ae6 100755 (executable)
@@ -3,7 +3,7 @@ package IkiWiki;
 
 use warnings;
 use strict;
 
 use warnings;
 use strict;
-use Test::More tests => 22;
+use Test::More tests => 28;
 
 BEGIN { use_ok("IkiWiki"); }
 BEGIN { use_ok("IkiWiki::Render"); }
 
 BEGIN { use_ok("IkiWiki"); }
 BEGIN { use_ok("IkiWiki::Render"); }
@@ -61,6 +61,9 @@ writefile("attached/pie.jpg", "t/tmp", "I lied, this isn't a real JPEG");
 # "gone" disappeared just before this refresh pass so it still has a mtime
 $pagemtime{gone} = $pagectime{gone} = 1000000;
 
 # "gone" disappeared just before this refresh pass so it still has a mtime
 $pagemtime{gone} = $pagectime{gone} = 1000000;
 
+my %pages;
+my @del;
+
 IkiWiki::Plugin::autoindex::refresh();
 
 # these pages are still on record as having been deleted, because they have
 IkiWiki::Plugin::autoindex::refresh();
 
 # these pages are still on record as having been deleted, because they have
@@ -83,12 +86,24 @@ ok(! -f "t/tmp/has_internal.mdwn");
 ok(! exists $wikistate{autoindex}{deleted}{reinstated});
 ok(! -f "t/tmp/reinstated.mdwn");
 
 ok(! exists $wikistate{autoindex}{deleted}{reinstated});
 ok(! -f "t/tmp/reinstated.mdwn");
 
-# needs creating
+# needs creating (deferred; part of the autofile mechanism now)
 ok(! exists $wikistate{autoindex}{deleted}{tags});
 ok(! exists $wikistate{autoindex}{deleted}{tags});
+%pages = ();
+@del = ();
+is($autofiles{"tags.mdwn"}{plugin}, "autoindex");
+IkiWiki::gen_autofile("tags.mdwn", \%pages, \@del);
+is_deeply(\%pages, {"t/tmp/tags" => 1}) || diag explain \%pages;
+is_deeply(\@del, []) || diag explain \@del;
 ok(-s "t/tmp/tags.mdwn");
 
 # needs creating because of an attachment
 ok(! exists $wikistate{autoindex}{deleted}{attached});
 ok(-s "t/tmp/tags.mdwn");
 
 # needs creating because of an attachment
 ok(! exists $wikistate{autoindex}{deleted}{attached});
+%pages = ();
+@del = ();
+is($autofiles{"attached.mdwn"}{plugin}, "autoindex");
+IkiWiki::gen_autofile("attached.mdwn", \%pages, \@del);
+is_deeply(\%pages, {"t/tmp/attached" => 1}) || diag explain \%pages;
+is_deeply(\@del, []) || diag explain \@del;
 ok(-s "t/tmp/attached.mdwn");
 
 1;
 ok(-s "t/tmp/attached.mdwn");
 
 1;