From e15e6cce6ca9eed6d0eabe6b9f100b713dcf2b59 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sat, 22 Jan 2011 22:22:48 +0000 Subject: autoindex test: check that an internal page doesn't cause indexing --- t/autoindex.t | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 't') diff --git a/t/autoindex.t b/t/autoindex.t index 9bef2415a..f56a35269 100755 --- a/t/autoindex.t +++ b/t/autoindex.t @@ -3,10 +3,11 @@ package IkiWiki; use warnings; use strict; -use Test::More tests => 17; +use Test::More tests => 20; BEGIN { use_ok("IkiWiki"); } BEGIN { use_ok("IkiWiki::Render"); } +BEGIN { use_ok("IkiWiki::Plugin::aggregate"); } BEGIN { use_ok("IkiWiki::Plugin::autoindex"); } BEGIN { use_ok("IkiWiki::Plugin::html"); } BEGIN { use_ok("IkiWiki::Plugin::mdwn"); } @@ -45,6 +46,12 @@ foreach my $page (qw(tags/numbers deleted/bar reinstated reinstated/foo gone/bar writefile("$page.html", "t/tmp", "your ad here"); } +# a directory containing only an internal page shouldn't be indexed +$pagesources{"has_internal/internal"} = "has_internal/internal._aggregated"; +$pagemtime{"has_internal/internal"} = 123456789; +$pagectime{"has_internal/internal"} = 123456789; +writefile("has_internal/internal._aggregated", "t/tmp", "this page is internal"); + # "gone" disappeared just before this refresh pass so it still has a mtime $pagemtime{gone} = $pagectime{gone} = 1000000; @@ -62,6 +69,10 @@ ok(! -f "t/tmp/gone.mdwn"); ok(! exists $wikistate{autoindex}{deleted}{expunged}); ok(! -f "t/tmp/expunged.mdwn"); +# a directory containing only an internal page shouldn't be indexed +ok(! exists $wikistate{autoindex}{deleted}{has_internal}); +ok(! -f "t/tmp/has_internal.mdwn"); + # this page was re-created, so it drops off the radar ok(! exists $wikistate{autoindex}{deleted}{reinstated}); ok(! -f "t/tmp/reinstated.mdwn"); -- cgit v1.2.3 From 0118479c9a8977ff3198622829ac4a0f3ea0de76 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sat, 22 Jan 2011 22:23:50 +0000 Subject: autoindex.t: check that attachments cause indexing --- t/autoindex.t | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 't') diff --git a/t/autoindex.t b/t/autoindex.t index f56a35269..b1425c22e 100755 --- a/t/autoindex.t +++ b/t/autoindex.t @@ -3,7 +3,7 @@ package IkiWiki; use warnings; use strict; -use Test::More tests => 20; +use Test::More tests => 22; BEGIN { use_ok("IkiWiki"); } BEGIN { use_ok("IkiWiki::Render"); } @@ -52,6 +52,12 @@ $pagemtime{"has_internal/internal"} = 123456789; $pagectime{"has_internal/internal"} = 123456789; writefile("has_internal/internal._aggregated", "t/tmp", "this page is internal"); +# a directory containing only an attachment should be indexed +$pagesources{"attached/pie.jpg"} = "attached/pie.jpg"; +$pagemtime{"attached/pie.jpg"} = 123456789; +$pagectime{"attached/pie.jpg"} = 123456789; +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; @@ -81,4 +87,8 @@ ok(! -f "t/tmp/reinstated.mdwn"); ok(! exists $wikistate{autoindex}{deleted}{tags}); ok(-s "t/tmp/tags.mdwn"); +# needs creating because of an attachment +ok(! exists $wikistate{autoindex}{deleted}{attached}); +ok(-s "t/tmp/attached.mdwn"); + 1; -- cgit v1.2.3 From dca6679a5442581746daf89e78ee83712a017b98 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 6 Jan 2011 00:15:28 +0000 Subject: autoindex: use add_autofile 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 | 37 +++++++++++++++++++++---------------- t/autoindex.t | 19 +++++++++++++++++-- 2 files changed, 38 insertions(+), 18 deletions(-) (limited to 't') diff --git a/IkiWiki/Plugin/autoindex.pm b/IkiWiki/Plugin/autoindex.pm index 11595e217..ba2dcb907 100644 --- a/IkiWiki/Plugin/autoindex.pm +++ b/IkiWiki/Plugin/autoindex.pm @@ -22,12 +22,23 @@ sub getsetup () { 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 () { @@ -66,7 +77,10 @@ sub refresh () { 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}}; @@ -109,18 +123,9 @@ sub refresh () { } if (@needed) { - if ($config{rcs}) { - IkiWiki::disable_commit_hook(); - } foreach my $page (@needed) { genindex($page); } - if ($config{rcs}) { - IkiWiki::rcs_commit_staged( - message => gettext("automatic index generation"), - ); - IkiWiki::enable_commit_hook(); - } } } diff --git a/t/autoindex.t b/t/autoindex.t index b1425c22e..04d668fbc 100755 --- a/t/autoindex.t +++ b/t/autoindex.t @@ -3,7 +3,7 @@ package IkiWiki; use warnings; use strict; -use Test::More tests => 22; +use Test::More tests => 28; 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; +my %pages; +my @del; + 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"); -# needs creating +# needs creating (deferred; part of the autofile mechanism now) 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}); +%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; -- cgit v1.2.3 From db029393f61b358576d21536554ddabcffaef90c Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sat, 22 Jan 2011 22:27:04 +0000 Subject: autoindex.t: check that none of the files that shouldn't be generated are autofiles --- t/autoindex.t | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 't') diff --git a/t/autoindex.t b/t/autoindex.t index 04d668fbc..2c1331da2 100755 --- a/t/autoindex.t +++ b/t/autoindex.t @@ -3,7 +3,7 @@ package IkiWiki; use warnings; use strict; -use Test::More tests => 28; +use Test::More tests => 33; BEGIN { use_ok("IkiWiki"); } BEGIN { use_ok("IkiWiki::Render"); } @@ -70,20 +70,25 @@ IkiWiki::Plugin::autoindex::refresh(); # a reason to be re-created is($wikistate{autoindex}{deleted}{deleted}, 1); is($wikistate{autoindex}{deleted}{gone}, 1); +ok(! exists $autofiles{deleted}); +ok(! exists $autofiles{gone}); ok(! -f "t/tmp/deleted.mdwn"); ok(! -f "t/tmp/gone.mdwn"); # this page does not exist and has no reason to be re-created, so we forget # about it - it will be re-created if it gains sub-pages ok(! exists $wikistate{autoindex}{deleted}{expunged}); +ok(! exists $autofiles{expunged}); ok(! -f "t/tmp/expunged.mdwn"); # a directory containing only an internal page shouldn't be indexed ok(! exists $wikistate{autoindex}{deleted}{has_internal}); +ok(! exists $autofiles{has_internal}); ok(! -f "t/tmp/has_internal.mdwn"); # this page was re-created, so it drops off the radar ok(! exists $wikistate{autoindex}{deleted}{reinstated}); +ok(! exists $autofiles{reinstated}); ok(! -f "t/tmp/reinstated.mdwn"); # needs creating (deferred; part of the autofile mechanism now) -- cgit v1.2.3 From 8ee9eabb1c5314f51641aaec4cb45d5c2d0fa7b8 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sat, 22 Jan 2011 22:28:50 +0000 Subject: autoindex: stop tracking deletions, use generic autofile tracking instead - Migrate the set of deletions to the {autofile} set, since it has more or less the same effect. This affects the "deleted" case in the test. - If a page has just been deleted, add it as an autofile anyway: by the time gen_autofile is called, it'll be in the list of deleted files, so it'll just be added to {autofile}. This affects the "gone" case in the test. - Behaviour change: we don't forget that a page with no reason to be re-created was deleted. This affects the 'expunged' and 'reinstated' cases in the test. --- IkiWiki/Plugin/autoindex.pm | 49 ++++++++++++++-------------------------- t/autoindex.t | 54 ++++++++++++++++++++++++++++++--------------- 2 files changed, 53 insertions(+), 50 deletions(-) (limited to 't') diff --git a/IkiWiki/Plugin/autoindex.pm b/IkiWiki/Plugin/autoindex.pm index ba2dcb907..5a58c820a 100644 --- a/IkiWiki/Plugin/autoindex.pm +++ b/IkiWiki/Plugin/autoindex.pm @@ -78,53 +78,38 @@ sub refresh () { 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 - + # Compatibility code. + # + # {deleted} contains pages that have been deleted at some point. + # This plugin used to delete from the hash sometimes, but no longer + # does; in [[todo/autoindex_should_use_add__95__autofile]] Joey + # thought the old behaviour was probably a bug. + # + # The effect of listing a page in {deleted} was to avoid re-creating + # it; we migrate these pages to {autofile} which has the same effect. + # However, {autofile} contains source filenames whereas {deleted} + # contains page names. my %deleted; if (ref $wikistate{autoindex}{deleted}) { %deleted=%{$wikistate{autoindex}{deleted}}; + delete $wikistate{autoindex}{deleted}; } elsif (ref $pagestate{index}{autoindex}{deleted}) { - # compatability code + # an even older version %deleted=%{$pagestate{index}{autoindex}{deleted}}; delete $pagestate{index}{autoindex}; } if (keys %deleted) { foreach my $dir (keys %deleted) { - # remove deleted page state if the deleted page is re-added, - # or if all its subpages are deleted - if ($deleted{$dir} && (exists $pages{$dir} || - ! grep /^$dir\/.*/, keys %pages)) { - delete $deleted{$dir}; - } + my $file=newpagefile($dir, $config{default_pageext}); + $wikistate{autoindex}{autofile}{$file} = 1; } - $wikistate{autoindex}{deleted}=\%deleted; } - my @needed; foreach my $dir (keys %dirs) { - if (! exists $pages{$dir} && ! $deleted{$dir} && - grep /^$dir\/.*/, keys %pages) { - if (exists $IkiWiki::pagemtime{$dir}) { - # This page must have just been deleted, so - # don't re-add it. And remember it was - # deleted. - if (! ref $wikistate{autoindex}{deleted}) { - $wikistate{autoindex}{deleted}={}; - } - ${$wikistate{autoindex}{deleted}}{$dir}=1; - } - else { - push @needed, $dir; - } - } - } - - if (@needed) { - foreach my $page (@needed) { - genindex($page); + if (! exists $pages{$dir} && grep /^$dir\/.*/, keys %pages) { + genindex($dir); } } } diff --git a/t/autoindex.t b/t/autoindex.t index 2c1331da2..665f0dc1c 100755 --- a/t/autoindex.t +++ b/t/autoindex.t @@ -3,7 +3,7 @@ package IkiWiki; use warnings; use strict; -use Test::More tests => 33; +use Test::More tests => 37; BEGIN { use_ok("IkiWiki"); } BEGIN { use_ok("IkiWiki::Render"); } @@ -33,7 +33,8 @@ is(checkconfig(), 1); %pagesources=%pagemtime=%oldlinks=%links=%depends=%typedlinks=%oldtypedlinks= %destsources=%renderedfiles=%pagecase=%pagestate=(); -# pages that (we claim) were deleted in an earlier pass +# Pages that (we claim) were deleted in an earlier pass. We're using deleted, +# not autofile, to test backwards compat. $wikistate{autoindex}{deleted}{deleted} = 1; $wikistate{autoindex}{deleted}{expunged} = 1; $wikistate{autoindex}{deleted}{reinstated} = 1; @@ -66,33 +67,50 @@ my @del; IkiWiki::Plugin::autoindex::refresh(); -# these pages are still on record as having been deleted, because they have +# this page is still on record as having been deleted, because it has # a reason to be re-created -is($wikistate{autoindex}{deleted}{deleted}, 1); -is($wikistate{autoindex}{deleted}{gone}, 1); -ok(! exists $autofiles{deleted}); -ok(! exists $autofiles{gone}); +is($wikistate{autoindex}{autofile}{"deleted.mdwn"}, 1); +is($autofiles{"deleted.mdwn"}{plugin}, "autoindex"); +%pages = (); +@del = (); +IkiWiki::gen_autofile("deleted.mdwn", \%pages, \@del); +is_deeply(\%pages, {}) || diag explain \%pages; +is_deeply(\@del, []) || diag explain \@del; ok(! -f "t/tmp/deleted.mdwn"); + +# this page is tried as an autofile, but because it'll be in @del, it's not +# actually created +ok(! exists $wikistate{autoindex}{autofile}{"gone.mdwn"}); +%pages = (); +@del = ("gone.mdwn"); +is($autofiles{"gone.mdwn"}{plugin}, "autoindex"); +IkiWiki::gen_autofile("gone.mdwn", \%pages, \@del); +is_deeply(\%pages, {}) || diag explain \%pages; +is_deeply(\@del, ["gone.mdwn"]) || diag explain \@del; ok(! -f "t/tmp/gone.mdwn"); -# this page does not exist and has no reason to be re-created, so we forget -# about it - it will be re-created if it gains sub-pages -ok(! exists $wikistate{autoindex}{deleted}{expunged}); -ok(! exists $autofiles{expunged}); +# this page does not exist and has no reason to be re-created, but we no longer +# have a special case for that - see +# [[todo/autoindex_should_use_add__95__autofile]] - so it won't be created +# even if it gains subpages later +is($wikistate{autoindex}{autofile}{"expunged.mdwn"}, 1); +ok(! exists $autofiles{"expunged.mdwn"}); ok(! -f "t/tmp/expunged.mdwn"); # a directory containing only an internal page shouldn't be indexed -ok(! exists $wikistate{autoindex}{deleted}{has_internal}); -ok(! exists $autofiles{has_internal}); +ok(! exists $wikistate{autoindex}{autofile}{"has_internal.mdwn"}); +ok(! exists $autofiles{"has_internal.mdwn"}); ok(! -f "t/tmp/has_internal.mdwn"); -# this page was re-created, so it drops off the radar -ok(! exists $wikistate{autoindex}{deleted}{reinstated}); -ok(! exists $autofiles{reinstated}); +# this page was re-created, but that no longer gets a special case +# (see [[todo/autoindex_should_use_add__95__autofile]]) so it's the same as +# deleted +is($wikistate{autoindex}{autofile}{"reinstated.mdwn"}, 1); +ok(! exists $autofiles{"reinstated.mdwn"}); ok(! -f "t/tmp/reinstated.mdwn"); # needs creating (deferred; part of the autofile mechanism now) -ok(! exists $wikistate{autoindex}{deleted}{tags}); +ok(! exists $wikistate{autoindex}{autofile}{"tags.mdwn"}); %pages = (); @del = (); is($autofiles{"tags.mdwn"}{plugin}, "autoindex"); @@ -102,7 +120,7 @@ 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(! exists $wikistate{autoindex}{autofile}{"attached.mdwn"}); %pages = (); @del = (); is($autofiles{"attached.mdwn"}{plugin}, "autoindex"); -- cgit v1.2.3 From 059259ecd1f974b98718bf05f8be63fa0e7c4e32 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sat, 25 Dec 2010 23:02:47 +0000 Subject: Allow autoindex files to be written into the transient underlay As with the tag plugin, for the moment keep the old behaviour in the test. --- IkiWiki/Plugin/autoindex.pm | 18 ++++++++++++++++-- t/autoindex.t | 1 + 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 't') diff --git a/IkiWiki/Plugin/autoindex.pm b/IkiWiki/Plugin/autoindex.pm index 5a58c820a..d02618581 100644 --- a/IkiWiki/Plugin/autoindex.pm +++ b/IkiWiki/Plugin/autoindex.pm @@ -9,6 +9,7 @@ use Encode; sub import { hook(type => "getsetup", id => "autoindex", call => \&getsetup); hook(type => "refresh", id => "autoindex", call => \&refresh); + IkiWiki::loadplugin("transient"); } sub getsetup () { @@ -17,6 +18,14 @@ sub getsetup () { safe => 1, rebuild => 0, }, + autoindex_commit => { + type => "boolean", + example => 1, + default => 1, + description => "commit autocreated index pages", + safe => 1, + rebuild => 0, + }, } sub genindex ($) { @@ -28,11 +37,16 @@ sub genindex ($) { $page); debug($message); + my $dir = $config{srcdir}; + if (! $config{autoindex_commit}) { + $dir = $IkiWiki::Plugin::transient::transientdir; + } + my $template = template("autoindex.tmpl"); $template->param(page => $page); - writefile($file, $config{srcdir}, $template->output); + writefile($file, $dir, $template->output); - if ($config{rcs}) { + if ($config{rcs} && $config{autoindex_commit}) { IkiWiki::disable_commit_hook(); IkiWiki::rcs_add($file); IkiWiki::rcs_commit_staged(message => $message); diff --git a/t/autoindex.t b/t/autoindex.t index 665f0dc1c..1e40b4c53 100755 --- a/t/autoindex.t +++ b/t/autoindex.t @@ -26,6 +26,7 @@ $config{userdir} = "users"; $config{tagbase} = "tags"; $config{default_pageext} = "mdwn"; $config{wiki_file_prune_regexps} = [qr/^\./]; +$config{autoindex_commit} = 1; is(checkconfig(), 1); -- cgit v1.2.3 From 5a73ed82cf9842b224537d8252aa1eb5c5176639 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sat, 22 Jan 2011 22:39:45 +0000 Subject: autoindex test: write autoindex pages into the transient underlay --- t/autoindex.t | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 't') diff --git a/t/autoindex.t b/t/autoindex.t index 1e40b4c53..b38be8313 100755 --- a/t/autoindex.t +++ b/t/autoindex.t @@ -3,7 +3,7 @@ package IkiWiki; use warnings; use strict; -use Test::More tests => 37; +use Test::More tests => 38; BEGIN { use_ok("IkiWiki"); } BEGIN { use_ok("IkiWiki::Render"); } @@ -26,7 +26,7 @@ $config{userdir} = "users"; $config{tagbase} = "tags"; $config{default_pageext} = "mdwn"; $config{wiki_file_prune_regexps} = [qr/^\./]; -$config{autoindex_commit} = 1; +$config{autoindex_commit} = 0; is(checkconfig(), 1); @@ -118,7 +118,8 @@ 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"); +ok(! -s "t/tmp/tags.mdwn"); +ok(-s "t/tmp/.ikiwiki/transient/tags.mdwn"); # needs creating because of an attachment ok(! exists $wikistate{autoindex}{autofile}{"attached.mdwn"}); @@ -128,6 +129,6 @@ 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"); +ok(-s "t/tmp/.ikiwiki/transient/attached.mdwn"); 1; -- cgit v1.2.3