diff options
35 files changed, 568 insertions, 244 deletions
diff --git a/IkiWiki.pm b/IkiWiki.pm index 97d84c9de..7adc63139 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -28,6 +28,11 @@ our $VERSION = 3.00; # plugin interface version, next is ikiwiki version our $version='unknown'; # VERSION_AUTOREPLACE done by Makefile, DNE our $installdir='/usr'; # INSTALLDIR_AUTOREPLACE done by Makefile, DNE +# Page dependency types. +our $DEPEND_CONTENT=1; +our $DEPEND_PRESENCE=2; +our $DEPEND_LINKS=4; + # Optimisation. use Memoize; memoize("abs2rel"); @@ -1524,18 +1529,28 @@ sub loadindex () { $links{$page}=$d->{links}; $oldlinks{$page}=[@{$d->{links}}]; } - if (exists $d->{depends_simple}) { + if (ref $d->{depends_simple} eq 'ARRAY') { + # old format $depends_simple{$page}={ map { $_ => 1 } @{$d->{depends_simple}} }; } + elsif (exists $d->{depends_simple}) { + $depends_simple{$page}=$d->{depends_simple}; + } if (exists $d->{dependslist}) { + # old format $depends{$page}={ - map { $_ => 1 } @{$d->{dependslist}} + map { $_ => $DEPEND_CONTENT } + @{$d->{dependslist}} }; } + elsif (exists $d->{depends} && ! ref $d->{depends}) { + # old format + $depends{$page}={$d->{depends} => $DEPEND_CONTENT }; + } elsif (exists $d->{depends}) { - $depends{$page}={$d->{depends} => 1}; + $depends{$page}=$d->{depends}; } if (exists $d->{state}) { $pagestate{$page}=$d->{state}; @@ -1581,11 +1596,11 @@ sub saveindex () { }; if (exists $depends{$page}) { - $index{page}{$src}{dependslist} = [ keys %{$depends{$page}} ]; + $index{page}{$src}{depends} = $depends{$page}; } if (exists $depends_simple{$page}) { - $index{page}{$src}{depends_simple} = [ keys %{$depends_simple{$page}} ]; + $index{page}{$src}{depends_simple} = $depends_simple{$page}; } if (exists $pagestate{$page}) { @@ -1753,20 +1768,38 @@ sub rcs_receive () { $hooks{rcs}{rcs_receive}{call}->(); } -sub add_depends ($$) { +sub add_depends ($$;@) { my $page=shift; my $pagespec=shift; + my $deptype=0; + if (@_) { + my %params=@_; + + $deptype=$deptype | $DEPEND_PRESENCE if $params{presence}; + $deptype=$deptype | $DEPEND_LINKS if $params{links}; + } + $deptype=$DEPEND_CONTENT unless $deptype; + + # Is the pagespec a simple page name? if ($pagespec =~ /$config{wiki_file_regexp}/ && - $pagespec !~ /[\s*?()!]/) { - # a simple dependency, which can be matched by string eq - $depends_simple{$page}{lc $pagespec} = 1; + $pagespec !~ /[\s*?()!]/) { + $depends_simple{$page}{lc $pagespec} |= $deptype; return 1; } - return unless pagespec_valid($pagespec); + # Analyse the pagespec, and match it against all pages + # to get a list of influences, and add explicit + # content dependencies for those. + my $sub=pagespec_translate($pagespec); + return if $@; + foreach my $p (keys %pagesources) { + my $r=$sub->($p, location => $page ); + map { $depends_simple{$page}{lc $_} |= $DEPEND_CONTENT } $r->influences + if $r; + } - $depends{$page}{$pagespec} = 1; + $depends{$page}{$pagespec} |= $deptype; return 1; } @@ -1873,10 +1906,10 @@ sub pagespec_translate ($) { }gx) { my $word=$1; if (lc $word eq 'and') { - $code.=' &&'; + $code.=' &'; } elsif (lc $word eq 'or') { - $code.=' ||'; + $code.=' |'; } elsif ($word eq "(" || $word eq ")" || $word eq "!") { $code.=' '.$word; @@ -1962,36 +1995,40 @@ sub glob2re ($) { package IkiWiki::FailReason; use overload ( - '""' => sub { ${$_[0]} }, + '""' => sub { $_[0][0] }, '0+' => sub { 0 }, '!' => sub { bless $_[0], 'IkiWiki::SuccessReason'}, + '&' => sub { $_[0][1]={%{$_[0][1]}, %{$_[1][1]}}; $_[0] }, + '|' => sub { $_[1][1]={%{$_[0][1]}, %{$_[1][1]}}; $_[1] }, fallback => 1, ); -sub new { - my $class = shift; - my $value = shift; - return bless \$value, $class; -} - -package IkiWiki::ErrorReason; - -our @ISA = 'IkiWiki::FailReason'; +our @ISA = 'IkiWiki::SuccessReason'; package IkiWiki::SuccessReason; use overload ( - '""' => sub { ${$_[0]} }, + '""' => sub { $_[0][0] }, '0+' => sub { 1 }, '!' => sub { bless $_[0], 'IkiWiki::FailReason'}, + '&' => sub { $_[1][1]={%{$_[0][1]}, %{$_[1][1]}}; $_[1] }, + '|' => sub { $_[0][1]={%{$_[0][1]}, %{$_[1][1]}}; $_[0] }, fallback => 1, ); sub new { my $class = shift; my $value = shift; - return bless \$value, $class; -}; + return bless [$value, {map { $_ => 1 } @_}], $class; +} + +sub influences { + return keys %{$_[0][1]}; +} + +package IkiWiki::ErrorReason; + +our @ISA = 'IkiWiki::FailReason'; package IkiWiki::PageSpec; @@ -2042,23 +2079,23 @@ sub match_link ($$;@) { my $from=exists $params{location} ? $params{location} : ''; my $links = $IkiWiki::links{$page}; - return IkiWiki::FailReason->new("$page has no links") unless $links && @{$links}; + return IkiWiki::FailReason->new("$page has no links", $page) unless $links && @{$links}; my $bestlink = IkiWiki::bestlink($from, $link); foreach my $p (@{$links}) { if (length $bestlink) { - return IkiWiki::SuccessReason->new("$page links to $link") + return IkiWiki::SuccessReason->new("$page links to $link", $page) if $bestlink eq IkiWiki::bestlink($page, $p); } else { - return IkiWiki::SuccessReason->new("$page links to page $p matching $link") + return IkiWiki::SuccessReason->new("$page links to page $p matching $link", $page) if match_glob($p, $link, %params); my ($p_rel)=$p=~/^\/?(.*)/; $link=~s/^\///; - return IkiWiki::SuccessReason->new("$page links to page $p_rel matching $link") + return IkiWiki::SuccessReason->new("$page links to page $p_rel matching $link", $page) if match_glob($p_rel, $link, %params); } } - return IkiWiki::FailReason->new("$page does not link to $link"); + return IkiWiki::FailReason->new("$page does not link to $link", $page); } sub match_backlink ($$;@) { @@ -2074,14 +2111,14 @@ sub match_created_before ($$;@) { if (exists $IkiWiki::pagectime{$testpage}) { if ($IkiWiki::pagectime{$page} < $IkiWiki::pagectime{$testpage}) { - return IkiWiki::SuccessReason->new("$page created before $testpage"); + return IkiWiki::SuccessReason->new("$page created before $testpage", $testpage); } else { - return IkiWiki::FailReason->new("$page not created before $testpage"); + return IkiWiki::FailReason->new("$page not created before $testpage", $testpage); } } else { - return IkiWiki::ErrorReason->new("$testpage does not exist"); + return IkiWiki::ErrorReason->new("$testpage does not exist", $testpage); } } @@ -2094,14 +2131,14 @@ sub match_created_after ($$;@) { if (exists $IkiWiki::pagectime{$testpage}) { if ($IkiWiki::pagectime{$page} > $IkiWiki::pagectime{$testpage}) { - return IkiWiki::SuccessReason->new("$page created after $testpage"); + return IkiWiki::SuccessReason->new("$page created after $testpage", $testpage); } else { - return IkiWiki::FailReason->new("$page not created after $testpage"); + return IkiWiki::FailReason->new("$page not created after $testpage", $testpage); } } else { - return IkiWiki::ErrorReason->new("$testpage does not exist"); + return IkiWiki::ErrorReason->new("$testpage does not exist", $testpage); } } diff --git a/IkiWiki/Plugin/brokenlinks.pm b/IkiWiki/Plugin/brokenlinks.pm index eb698b0be..9e65f52c6 100644 --- a/IkiWiki/Plugin/brokenlinks.pm +++ b/IkiWiki/Plugin/brokenlinks.pm @@ -23,9 +23,8 @@ sub preprocess (@) { my %params=@_; $params{pages}="*" unless defined $params{pages}; - # Needs to update whenever a page is added or removed, so - # register a dependency. - add_depends($params{page}, $params{pages}); + # Needs to update whenever the links on a page change. + add_depends($params{page}, $params{pages}, links => 1); my @broken; foreach my $link (keys %IkiWiki::brokenlinks) { diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm index 5d16dff75..a1117992a 100644 --- a/IkiWiki/Plugin/calendar.pm +++ b/IkiWiki/Plugin/calendar.pm @@ -104,19 +104,22 @@ sub format_month (@) { "$archivebase/$year/".sprintf("%02d", $month), linktext => " $monthname "); } - add_depends($params{page}, "$archivebase/$year/".sprintf("%02d", $month)); + add_depends($params{page}, "$archivebase/$year/".sprintf("%02d", $month), + presence => 1); if (exists $cache{$pagespec}{"$pyear/$pmonth"}) { $purl = htmllink($params{page}, $params{destpage}, "$archivebase/$pyear/" . sprintf("%02d", $pmonth), linktext => " $pmonthname "); } - add_depends($params{page}, "$archivebase/$pyear/".sprintf("%02d", $pmonth)); + add_depends($params{page}, "$archivebase/$pyear/".sprintf("%02d", $pmonth), + presence => 1); if (exists $cache{$pagespec}{"$nyear/$nmonth"}) { $nurl = htmllink($params{page}, $params{destpage}, "$archivebase/$nyear/" . sprintf("%02d", $nmonth), linktext => " $nmonthname "); } - add_depends($params{page}, "$archivebase/$nyear/".sprintf("%02d", $nmonth)); + add_depends($params{page}, "$archivebase/$nyear/".sprintf("%02d", $nmonth), + presence => 1); # Start producing the month calendar $calendar=<<EOF; @@ -209,11 +212,11 @@ EOF # Add dependencies to update the calendar whenever pages # matching the pagespec are added or removed. - add_depends($params{page}, $params{pages}); + add_depends($params{page}, $params{pages}, presence => 1); # Explicitly add all currently linked pages as dependencies, so # that if they are removed, the calendar will be sure to be updated. foreach my $p (@list) { - add_depends($params{page}, $p); + add_depends($params{page}, $p, presence => 1); } return $calendar; @@ -246,19 +249,19 @@ sub format_year (@) { "$archivebase/$year", linktext => "$year"); } - add_depends($params{page}, "$archivebase/$year"); + add_depends($params{page}, "$archivebase/$year", presence => 1); if (exists $cache{$pagespec}{"$pyear"}) { $purl = htmllink($params{page}, $params{destpage}, "$archivebase/$pyear", linktext => "\←"); } - add_depends($params{page}, "$archivebase/$pyear"); + add_depends($params{page}, "$archivebase/$pyear", presence => 1); if (exists $cache{$pagespec}{"$nyear"}) { $nurl = htmllink($params{page}, $params{destpage}, "$archivebase/$nyear", linktext => "\→"); } - add_depends($params{page}, "$archivebase/$nyear"); + add_depends($params{page}, "$archivebase/$nyear", presence => 1); # Start producing the year calendar $calendar=<<EOF; @@ -310,7 +313,7 @@ EOF else { $calendar.=qq{\t<td class="$tag">$monthabbr</td>\n}; } - add_depends($params{page}, "$archivebase/$year/$mtag"); + add_depends($params{page}, "$archivebase/$year/$mtag", presence => 1); $calendar.=qq{\t</tr>\n} if ($month % $params{months_per_row} == 0); } diff --git a/IkiWiki/Plugin/edittemplate.pm b/IkiWiki/Plugin/edittemplate.pm index 0bafc95d0..2dd1dbe68 100644 --- a/IkiWiki/Plugin/edittemplate.pm +++ b/IkiWiki/Plugin/edittemplate.pm @@ -58,7 +58,7 @@ sub preprocess (@) { $pagestate{$params{page}}{edittemplate}{$params{match}}=$link; return "" if ($params{silent} && IkiWiki::yesno($params{silent})); - add_depends($params{page}, $link); + add_depends($params{page}, $link, presence => 1); return sprintf(gettext("edittemplate %s registered for %s"), htmllink($params{page}, $params{destpage}, $link), $params{match}); diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm index ccfadfd69..cebd9037c 100644 --- a/IkiWiki/Plugin/inline.pm +++ b/IkiWiki/Plugin/inline.pm @@ -197,7 +197,7 @@ sub preprocess_inline (@) { split ' ', $params{pagenames}; } else { - add_depends($params{page}, $params{pages}); + add_depends($params{page}, $params{pages}, presence => $quick); @list = pagespec_match_list( [ grep { $_ ne $params{page} } keys %pagesources ], @@ -248,10 +248,9 @@ sub preprocess_inline (@) { } # Explicitly add all currently displayed pages as dependencies, so - # that if they are removed or otherwise changed, the inline will be - # sure to be updated. + # that if they are removed, the inline will be sure to be updated. foreach my $p ($#list >= $#feedlist ? @list : @feedlist) { - add_depends($params{page}, $p); + add_depends($params{page}, $p, presence => $quick); } if ($feeds && exists $params{feedpages}) { diff --git a/IkiWiki/Plugin/linkmap.pm b/IkiWiki/Plugin/linkmap.pm index 941ed5f36..3d20a6521 100644 --- a/IkiWiki/Plugin/linkmap.pm +++ b/IkiWiki/Plugin/linkmap.pm @@ -28,9 +28,9 @@ sub preprocess (@) { $params{pages}="*" unless defined $params{pages}; - # Needs to update whenever a page is added or removed, so - # register a dependency. - add_depends($params{page}, $params{pages}); + # Needs to update whenever a relevant page is added, or removed, or + # its links change. + add_depends($params{page}, $params{pages}, presence => 1, links => 1); # Can't just return the linkmap here, since the htmlscrubber # scrubs out all <object> tags (with good reason!) @@ -56,7 +56,7 @@ sub genmap ($) { # Get all the items to map. my %mapitems = (); - foreach my $item (keys %links) { + foreach my $item (keys %pagesources) { if (pagespec_match($item, $params{pages}, location => $params{page})) { $mapitems{$item}=urlto($item, $params{destpage}); } diff --git a/IkiWiki/Plugin/listdirectives.pm b/IkiWiki/Plugin/listdirectives.pm index bd73f1a04..4023ed7d7 100644 --- a/IkiWiki/Plugin/listdirectives.pm +++ b/IkiWiki/Plugin/listdirectives.pm @@ -84,7 +84,7 @@ sub preprocess (@) { foreach my $plugin (@pluginlist) { $result .= '<li class="listdirectives">'; my $link=linkpage($config{directive_description_dir}."/".$plugin); - add_depends($params{page}, $link); + add_depends($params{page}, $link, presence => 1); $result .= htmllink($params{page}, $params{destpage}, $link); $result .= '</li>'; } diff --git a/IkiWiki/Plugin/map.pm b/IkiWiki/Plugin/map.pm index 54146dc46..625cfdfca 100644 --- a/IkiWiki/Plugin/map.pm +++ b/IkiWiki/Plugin/map.pm @@ -68,13 +68,13 @@ sub preprocess (@) { } # Needs to update whenever a page is added or removed (or in some - # cases, when its content changes, if show=title), so register a - # dependency. - add_depends($params{page}, $params{pages}); + # cases, when its content changes, if show= is specified), so + # register a dependency. + add_depends($params{page}, $params{pages}, presence => ! exists $params{show}); # Explicitly add all currently shown pages, to detect when pages # are removed. foreach my $item (keys %mapitems) { - add_depends($params{page}, $item); + add_depends($params{page}, $item, presence => ! exists $params{show}); } # Create the map. diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm index 514b09369..a8ee5bc85 100644 --- a/IkiWiki/Plugin/meta.pm +++ b/IkiWiki/Plugin/meta.pm @@ -195,7 +195,7 @@ sub preprocess (@) { if (! length $link) { error gettext("redir page not found") } - add_depends($page, $link); + add_depends($page, $link, presence => 1); $value=urlto($link, $page); $value.='#'.$redir_anchor if defined $redir_anchor; @@ -291,21 +291,21 @@ sub match { if (defined $val) { if ($val=~/^$re$/i) { - return IkiWiki::SuccessReason->new("$re matches $field of $page"); + return IkiWiki::SuccessReason->new("$re matches $field of $page", $page); } else { - return IkiWiki::FailReason->new("$re does not match $field of $page"); + return IkiWiki::FailReason->new("$re does not match $field of $page", $page); } } else { - return IkiWiki::FailReason->new("$page does not have a $field"); + return IkiWiki::FailReason->new("$page does not have a $field", $page); } } package IkiWiki::PageSpec; sub match_title ($$;@) { - IkiWiki::Plugin::meta::match("title", @_); + IkiWiki::Plugin::meta::match("title", @_); } sub match_author ($$;@) { diff --git a/IkiWiki/Plugin/orphans.pm b/IkiWiki/Plugin/orphans.pm index 711226772..ae330b23b 100644 --- a/IkiWiki/Plugin/orphans.pm +++ b/IkiWiki/Plugin/orphans.pm @@ -23,9 +23,13 @@ sub preprocess (@) { my %params=@_; $params{pages}="*" unless defined $params{pages}; - # Needs to update whenever a page is added or removed, so - # register a dependency. - add_depends($params{page}, $params{pages}); + # Needs to update whenever a link changes, on any page + # since any page could link to one of the pages we're + # considering as orphans. + add_depends($params{page}, "*", links => 1); + # Also needs to update whenever potential orphans are added or + # removed. + add_depends($params{page}, $params{pages}, presence => 1); my @orphans; foreach my $page (pagespec_match_list( diff --git a/IkiWiki/Plugin/pagecount.pm b/IkiWiki/Plugin/pagecount.pm index 5a2301af4..80561350b 100644 --- a/IkiWiki/Plugin/pagecount.pm +++ b/IkiWiki/Plugin/pagecount.pm @@ -23,8 +23,8 @@ sub preprocess (@) { $params{pages}="*" unless defined $params{pages}; # Needs to update count whenever a page is added or removed, so - # register a dependency. - add_depends($params{page}, $params{pages}); + # register a presence dependency. + add_depends($params{page}, $params{pages}, presence => 1); my @pages; if ($params{pages} eq "*") { diff --git a/IkiWiki/Plugin/pagestats.pm b/IkiWiki/Plugin/pagestats.pm index 874ead7e6..afe4eeaf2 100644 --- a/IkiWiki/Plugin/pagestats.pm +++ b/IkiWiki/Plugin/pagestats.pm @@ -35,14 +35,17 @@ sub preprocess (@) { $params{pages}="*" unless defined $params{pages}; my $style = ($params{style} or 'cloud'); - # Needs to update whenever a page is added or removed, so - # register a dependency. - add_depends($params{page}, $params{pages}); - add_depends($params{page}, $params{among}) if exists $params{among}; + # Needs to update whenever a page is added or removed. + add_depends($params{page}, $params{pages}, exists => 1); + # Also needs to update when any page with links changes, + # in case the links point to our displayed pages. + # (Among limits this further.) + add_depends($params{page}, exists $params{among} ? $params{among} : "*", + links => 1); my %counts; my $max = 0; - foreach my $page (pagespec_match_list([keys %links], + foreach my $page (pagespec_match_list([keys %pagesources], $params{pages}, location => $params{page})) { use IkiWiki::Render; diff --git a/IkiWiki/Plugin/postsparkline.pm b/IkiWiki/Plugin/postsparkline.pm index d2e5c2378..3205958d4 100644 --- a/IkiWiki/Plugin/postsparkline.pm +++ b/IkiWiki/Plugin/postsparkline.pm @@ -48,7 +48,7 @@ sub preprocess (@) { error gettext("unknown formula"); } - add_depends($params{page}, $params{pages}); + add_depends($params{page}, $params{pages}, presence => 1); my @list=sort { $params{timehash}->{$b} <=> $params{timehash}->{$a} } pagespec_match_list( diff --git a/IkiWiki/Plugin/progress.pm b/IkiWiki/Plugin/progress.pm index 76d994acc..26c537a84 100644 --- a/IkiWiki/Plugin/progress.pm +++ b/IkiWiki/Plugin/progress.pm @@ -36,8 +36,8 @@ sub preprocess (@) { $fill.="%"; } elsif (defined $params{totalpages} and defined $params{donepages}) { - add_depends($params{page}, $params{totalpages}); - add_depends($params{page}, $params{donepages}); + add_depends($params{page}, $params{totalpages}, presence => 1); + add_depends($params{page}, $params{donepages}, presence => 1); my @pages=keys %pagesources; my $totalcount=0; diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm index 246c2260d..79935f323 100644 --- a/IkiWiki/Render.pm +++ b/IkiWiki/Render.pm @@ -7,7 +7,7 @@ use strict; use IkiWiki; use Encode; -my %backlinks; +my (%backlinks, %rendered); our %brokenlinks; my $links_calculated=0; @@ -147,6 +147,8 @@ sub genpage ($$) { sub scan ($) { my $file=shift; + debug(sprintf(gettext("scanning %s"), $file)); + my $type=pagetype($file); if (defined $type) { my $srcfile=srcfile($file); @@ -202,8 +204,11 @@ sub fast_file_copy (@) { } } -sub render ($) { +sub render ($$) { my $file=shift; + return if $rendered{$file}; + debug(shift); + $rendered{$file}=1; my $type=pagetype($file); my $srcfile=srcfile($file); @@ -273,7 +278,8 @@ sub srcdir_check () { } sub find_src_files () { - my (@files, %pages); + my @files; + my %pages; eval q{use File::Find}; error($@) if $@; find({ @@ -291,11 +297,11 @@ sub find_src_files () { else { $f=~s/^\Q$config{srcdir}\E\/?//; push @files, $f; - my $pagename = pagename($f); - if ($pages{$pagename}) { - debug(sprintf(gettext("%s has multiple possible source pages"), $pagename)); + my $page = pagename($f); + if ($pages{$page}) { + debug(sprintf(gettext("%s has multiple possible source pages"), $page)); } - $pages{$pagename}=1; + $pages{$page}=1; } } }, @@ -331,19 +337,14 @@ sub find_src_files () { }, }, $dir); }; - - # Returns a list of all source files found, and a hash of - # the corresponding page names. return \@files, \%pages; } -sub refresh () { - srcdir_check(); - run_hooks(refresh => sub { shift->() }); - my ($files, $exists)=find_src_files(); +sub find_new_files ($) { + my $files=shift; + my @new; + my @internal_new; - my (%rendered, @add, @del, @internal); - # check for added or removed pages foreach my $file (@$files) { my $page=pagename($file); if (exists $pagesources{$page} && $pagesources{$page} ne $file) { @@ -353,10 +354,10 @@ sub refresh () { $pagesources{$page}=$file; if (! $pagemtime{$page}) { if (isinternal($page)) { - push @internal, $file; + push @internal_new, $file; } else { - push @add, $file; + push @new, $file; if ($config{getctime} && -e "$config{srcdir}/$file") { eval { my $time=rcs_getctime("$config{srcdir}/$file"); @@ -373,10 +374,19 @@ sub refresh () { } } } + + return \@new, \@internal_new; +} + +sub find_del_files ($) { + my $pages=shift; + my @del; + my @internal_del; + foreach my $page (keys %pagemtime) { - if (! $exists->{$page}) { + if (! $pages->{$page}) { if (isinternal($page)) { - push @internal, $pagesources{$page}; + push @internal_del, $pagesources{$page}; } else { debug(sprintf(gettext("removing old page %s"), $page)); @@ -397,8 +407,13 @@ sub refresh () { } } - # find changed and new files - my @needsbuild; + return \@del, \@internal_del; +} + +sub find_changed ($) { + my $files=shift; + my @changed; + my @internal_changed; foreach my $file (@$files) { my $page=pagename($file); my ($srcfile, @stat)=srcfile_stat($file); @@ -406,150 +421,242 @@ sub refresh () { $stat[9] > $pagemtime{$page} || $forcerebuild{$page}) { $pagemtime{$page}=$stat[9]; + if (isinternal($page)) { - push @internal, $file; # Preprocess internal page in scan-only mode. preprocess($page, $page, readfile($srcfile), 1); + push @internal_changed, $file; } else { - push @needsbuild, $file; + push @changed, $file; } } } - run_hooks(needsbuild => sub { shift->(\@needsbuild) }); + return \@changed, \@internal_changed; +} - # scan and render files - foreach my $file (@needsbuild) { - debug(sprintf(gettext("scanning %s"), $file)); - scan($file); - } - calculate_links(); - foreach my $file (@needsbuild) { - debug(sprintf(gettext("building %s"), $file)); - render($file); - $rendered{$file}=1; - } - foreach my $file (@internal) { - # internal pages are not rendered +sub calculate_old_links ($$) { + my ($changed, $del)=@_; + my %oldlink_targets; + foreach my $file (@$changed, @$del) { my $page=pagename($file); - delete $depends{$page}; - delete $depends_simple{$page}; - foreach my $old (@{$renderedfiles{$page}}) { - delete $destsources{$old}; + if (exists $oldlinks{$page}) { + foreach my $l (@{$oldlinks{$page}}) { + $oldlink_targets{$page}{$l}=bestlink($page, $l); + } } - $renderedfiles{$page}=[]; } - - # rebuild pages that link to added or removed pages - if (@add || @del) { - foreach my $f (@add, @del) { - my $p=pagename($f); - foreach my $page (keys %{$backlinks{$p}}) { - my $file=$pagesources{$page}; - next if $rendered{$file}; - debug(sprintf(gettext("building %s, which links to %s"), $file, $p)); - render($file); - $rendered{$file}=1; + return \%oldlink_targets; +} + +sub derender_internal ($) { + my $file=shift; + my $page=pagename($file); + delete $depends{$page}; + delete $depends_simple{$page}; + foreach my $old (@{$renderedfiles{$page}}) { + delete $destsources{$old}; + } + $renderedfiles{$page}=[]; +} + +sub render_linkers ($) { + my $f=shift; + my $p=pagename($f); + foreach my $page (keys %{$backlinks{$p}}) { + my $file=$pagesources{$page}; + render($file, sprintf(gettext("building %s, which links to %s"), $file, $p)); + } +} + +sub remove_unrendered () { + foreach my $src (keys %rendered) { + my $page=pagename($src); + foreach my $file (@{$oldrenderedfiles{$page}}) { + if (! grep { $_ eq $file } @{$renderedfiles{$page}}) { + debug(sprintf(gettext("removing %s, no longer built by %s"), $file, $page)); + prune($config{destdir}."/".$file); } } } +} - if (%rendered || @del || @internal) { - my @changed=(keys %rendered, @del); +sub calculate_changed_links ($$$) { + my ($changed, $del, $oldlink_targets)=@_; - my %lcchanged = map { lc(pagename($_)) => 1 } @changed; - - # rebuild dependant pages - foreach my $f (@$files) { - next if $rendered{$f}; - my $p=pagename($f); - my $reason = undef; + my (%backlinkchanged, %linkchangers); - if (exists $depends_simple{$p}) { - foreach my $d (keys %{$depends_simple{$p}}) { - if (exists $lcchanged{$d}) { - $reason = $d; - last; - } + foreach my $file (@$changed, @$del) { + my $page=pagename($file); + + if (exists $links{$page}) { + foreach my $l (@{$links{$page}}) { + my $target=bestlink($page, $l); + if (! exists $oldlink_targets->{$page}{$l} || + $target ne $oldlink_targets->{$page}{$l}) { + $backlinkchanged{$target}=1; + $linkchangers{lc($page)}=1; } + delete $oldlink_targets->{$page}{$l}; } + } + if (exists $oldlink_targets->{$page} && + %{$oldlink_targets->{$page}}) { + foreach my $target (values %{$oldlink_targets->{$page}}) { + $backlinkchanged{$target}=1; + } + $linkchangers{lc($page)}=1; + } + } + + return \%backlinkchanged, \%linkchangers; +} - if (exists $depends{$p} && ! defined $reason) { - D: foreach my $d (keys %{$depends{$p}}) { - my $sub=pagespec_translate($d); - next if $@ || ! defined $sub; +sub render_dependent ($$$$$$$) { + my ($files, $new, $internal_new, $del, $internal_del, + $internal_changed, $linkchangers)=@_; - # only consider internal files - # if the page explicitly depends - # on such files - foreach my $file (@changed, $d =~ /internal\(/ ? @internal : ()) { + my @changed=(keys %rendered, @$del); + my @exists_changed=(@$new, @$del); + + my %lc_changed = map { lc(pagename($_)) => 1 } @changed; + my %lc_exists_changed = map { lc(pagename($_)) => 1 } @exists_changed; + + foreach my $f (@$files) { + next if $rendered{$f}; + my $p=pagename($f); + my $reason = undef; + + if (exists $depends_simple{$p}) { + foreach my $d (keys %{$depends_simple{$p}}) { + if (($depends_simple{$p}{$d} & $IkiWiki::DEPEND_CONTENT && + $lc_changed{$d}) + || + ($depends_simple{$p}{$d} & $IkiWiki::DEPEND_PRESENCE && + $lc_exists_changed{$d}) + || + ($depends_simple{$p}{$d} & $IkiWiki::DEPEND_LINKS && + $linkchangers->{$d}) + ) { + $reason = $d; + last; + } + } + } + + if (exists $depends{$p} && ! defined $reason) { + foreach my $dep (keys %{$depends{$p}}) { + my $sub=pagespec_translate($dep); + next if $@ || ! defined $sub; + + # only consider internal files + # if the page explicitly depends + # on such files + my $internal_dep=$dep =~ /internal\(/; + + my $in=sub { + my $list=shift; + my $type=shift; + foreach my $file (@$list) { next if $file eq $f; my $page=pagename($file); if ($sub->($page, location => $p)) { - $reason = $page; - last D; + if ($type == $IkiWiki::DEPEND_LINKS) { + next unless $linkchangers->{lc($page)}; + } + return $page; } } + return undef; + }; + + if ($depends{$p}{$dep} & $IkiWiki::DEPEND_CONTENT) { + last if $reason = + $in->(\@changed, $IkiWiki::DEPEND_CONTENT); + last if $internal_dep && ($reason = + $in->($internal_new, $IkiWiki::DEPEND_CONTENT) || + $in->($internal_del, $IkiWiki::DEPEND_CONTENT) || + $in->($internal_changed, $IkiWiki::DEPEND_CONTENT)); } - } - - if (defined $reason) { - debug(sprintf(gettext("building %s, which depends on %s"), $f, $reason)); - render($f); - $rendered{$f}=1; - } - } - - # handle backlinks; if a page has added/removed links, - # update the pages it links to - my %linkchanged; - foreach my $file (@changed) { - my $page=pagename($file); - - if (exists $links{$page}) { - foreach my $link (map { bestlink($page, $_) } @{$links{$page}}) { - if (length $link && - (! exists $oldlinks{$page} || - ! grep { bestlink($page, $_) eq $link } @{$oldlinks{$page}})) { - $linkchanged{$link}=1; - } + if ($depends{$p}{$dep} & $IkiWiki::DEPEND_PRESENCE) { + last if $reason = + $in->(\@exists_changed, $IkiWiki::DEPEND_PRESENCE); + last if $internal_dep && ($reason = + $in->($internal_new, $IkiWiki::DEPEND_PRESENCE) || + $in->($internal_del, $IkiWiki::DEPEND_PRESENCE)); } - } - if (exists $oldlinks{$page}) { - foreach my $link (map { bestlink($page, $_) } @{$oldlinks{$page}}) { - if (length $link && - (! exists $links{$page} || - ! grep { bestlink($page, $_) eq $link } @{$links{$page}})) { - $linkchanged{$link}=1; - } + if ($depends{$p}{$dep} & $IkiWiki::DEPEND_LINKS) { + last if $reason = + $in->(\@changed, $IkiWiki::DEPEND_LINKS); + last if $internal_dep && ($reason = + $in->($internal_new, $IkiWiki::DEPEND_LINKS) || + $in->($internal_del, $IkiWiki::DEPEND_LINKS) || + $in->($internal_changed, $IkiWiki::DEPEND_LINKS)); } } } - - foreach my $link (keys %linkchanged) { - my $linkfile=$pagesources{$link}; - if (defined $linkfile) { - next if $rendered{$linkfile}; - debug(sprintf(gettext("building %s, to update its backlinks"), $linkfile)); - render($linkfile); - $rendered{$linkfile}=1; - } + + if (defined $reason) { + render($f, sprintf(gettext("building %s, which depends on %s"), $f, $reason)); + return 1; } } - # remove no longer rendered files - foreach my $src (keys %rendered) { - my $page=pagename($src); - foreach my $file (@{$oldrenderedfiles{$page}}) { - if (! grep { $_ eq $file } @{$renderedfiles{$page}}) { - debug(sprintf(gettext("removing %s, no longer built by %s"), $file, $page)); - prune($config{destdir}."/".$file); - } + return 0; +} + +sub render_backlinks ($) { + my $backlinkchanged=shift; + foreach my $link (keys %$backlinkchanged) { + my $linkfile=$pagesources{$link}; + if (defined $linkfile) { + render($linkfile, sprintf(gettext("building %s, to update its backlinks"), $linkfile)); } } +} + +sub refresh () { + srcdir_check(); + run_hooks(refresh => sub { shift->() }); + my ($files, $pages)=find_src_files(); + my ($new, $internal_new)=find_new_files($files); + my ($del, $internal_del)=find_del_files($pages); + my ($changed, $internal_changed)=find_changed($files); + run_hooks(needsbuild => sub { shift->($changed) }); + my $oldlink_targets=calculate_old_links($changed, $del); + + foreach my $file (@$changed) { + scan($file); + } + + calculate_links(); + + foreach my $file (@$changed) { + render($file, sprintf(gettext("building %s"), $file)); + } + foreach my $file (@$internal_new, @$internal_del, @$internal_changed) { + derender_internal($file); + } + + my ($backlinkchanged, $linkchangers)=calculate_changed_links($changed, + $del, $oldlink_targets); + + foreach my $file (@$new, @$del) { + render_linkers($file); + } + + if (@$changed || @$internal_changed || + @$del || @$internal_del || @$internal_new) { + 1 while render_dependent($files, $new, $internal_new, + $del, $internal_del, $internal_changed, + $linkchangers); + } + + render_backlinks($backlinkchanged); + remove_unrendered(); - if (@del) { - run_hooks(delete => sub { shift->(@del) }); + if (@$del) { + run_hooks(delete => sub { shift->(@$del) }); } if (%rendered) { run_hooks(change => sub { shift->(keys %rendered) }); diff --git a/debian/NEWS b/debian/NEWS index 808105fd5..520f38815 100644 --- a/debian/NEWS +++ b/debian/NEWS @@ -1,3 +1,13 @@ +ikiwiki (3.14159266) UNRELEASED; urgency=low + + To take advantage of significant performance improvements, all + wikis need to be rebuilt on upgrade to this version. If you + listed your wiki in /etc/ikiwiki/wikilist this will be done + automatically when the Debian package is upgraded. Or use + ikiwiki-mass-rebuild to force a rebuild. + + -- Joey Hess <joeyh@debian.org> Mon, 05 Oct 2009 16:48:59 -0400 + ikiwiki (3.1415926) unstable; urgency=low In order to fix a performance bug, all wikis need to be rebuilt on diff --git a/debian/changelog b/debian/changelog index ca5409af7..565a0cffa 100644 --- a/debian/changelog +++ b/debian/changelog @@ -10,6 +10,30 @@ ikiwiki (3.14159266) UNRELEASED; urgency=low * mirrorlist: Display nothing if list is empty. * Fix a bug that could lead to duplicate links being recorded for tags. + * Added support framework for multiple types of dependencies. + * Allow declaring that a dependency is only affected by page presence + or changes to its links. + (By passing presence => 1 or links => 1 to add_depends.) + * pagecount, calendar, postsparkline, progress: Use a presence dependency, + which makes these directives much less expensive to use, since page + edits will no longer trigger an unnecessary update. + * map: Use a presence dependency unless show= is specified. + This makes maps efficient enough that they can be used on sidebars! + * inline: Use a presence dependency in quick mode. + * brokenlinks: Use a link dependency. + This makes it much more efficient, only updating when really necessary. + * orphans, pagestats: Use a combination of presence and link dependencies. + This makes them more efficient. It also fixes a longstanding bug, + where if only a small set of pages were considered by orphans/pagestats, + changes to links on other pages failed to cause an update. + * linkmap: Use a combination of presence and link dependencies. + This makes the map be regenerated much less frequently in many cases, + so larger maps are more practical to use now. + * Transitive dependencies are now correctly supported. + * Rebuild wikis on upgrade to this version to get improved dependency + info. + * Plugins providing PageSpec `match_*` functions should pass additional + influence information when creating result objects. -- Joey Hess <joeyh@debian.org> Sun, 27 Sep 2009 17:40:03 -0400 diff --git a/debian/postinst b/debian/postinst index 2ba26e5b6..dd4be6e0e 100755 --- a/debian/postinst +++ b/debian/postinst @@ -4,7 +4,7 @@ set -e # Change this when some incompatible change is made that requires # rebuilding all wikis. -firstcompat=3.1415926 +firstcompat=3.14159266 if [ "$1" = configure ] && \ dpkg --compare-versions "$2" lt "$firstcompat"; then diff --git a/doc/bugs/Inline_doesn__39__t_wikilink_to_pages.mdwn b/doc/bugs/Inline_doesn__39__t_wikilink_to_pages.mdwn index 32f9f1245..13b80b436 100644 --- a/doc/bugs/Inline_doesn__39__t_wikilink_to_pages.mdwn +++ b/doc/bugs/Inline_doesn__39__t_wikilink_to_pages.mdwn @@ -2,10 +2,6 @@ It seems that the [[ikiwiki/directive/inline]] directive doesn't generate wikili \[[!inline pages="bugs/* and !*/discussion and backlink(bugs)" feeds=no postform=no archive=yes show="10"]] -But here it is: - -[[!inline pages="bugs/* and !*/discussion and backlink(bugs)" feeds=no postform=no archive=yes show="10"]] - and note that it only included the 'normal' wikilinks (and also note that this page is not marked done even though the done page is inlined). One might also wonder if inline would make this page link to any internal links on those inlined pages too, but I think that would be overkill. diff --git a/doc/bugs/bestlink_change_update_issue.mdwn b/doc/bugs/bestlink_change_update_issue.mdwn index 5ce4a93d2..8a526e821 100644 --- a/doc/bugs/bestlink_change_update_issue.mdwn +++ b/doc/bugs/bestlink_change_update_issue.mdwn @@ -1,13 +1,29 @@ * Has bugs updating things if the bestlink of a page changes due to adding/removing a page. For example, if Foo/Bar links to "Baz", which is Foo/Baz, and Foo/Bar/Baz gets added, it will update the links in Foo/Bar - to point to it, but will forget to update the linkbacks in Foo/Baz. + to point to it, but will forget to update the backlinks in Foo/Baz. -* And if Foo/Bar/Baz is then removed, it forgets to update Foo/Bar to link - back to Foo/Baz. + The buggy code is in `refresh()`, when it determines what + links, on what pages, have changed. It only looks at + changed/added/deleted pages when doing this. But when Foo/Bar/Baz + is added, Foo/Bar is not changed -- so the change it its + backlinks is not noticed. -As of 1.33, this is still true. The buggy code is the %linkchanged -calculation in refresh(), which doesn't detect that the link has changed in -this case. + To fix this, it needs to consider, when rebuilding Foo/Bar for the changed + links, what oldlinks Foo/Bar had. If one of the oldlinks linked to + Foo/Baz, and not links to Foo/Bar/Baz, it could then rebuild Foo/Baz. -Still true in 1.43 although the code is much different now.. + Problem is that in order to do that, it needs to be able to tell that + the oldlinks linked to Foo/Baz. Which would mean either calculating + all links before the scan phase, or keeping a copy of the backlinks + from the last build, and using that. The first option would be a lot + of work for this minor issue.. it might be less expensive to just rebuild + *all* pages that Foo/Bar links to. + + Keeping a copy of the backlinks has some merit. It could also be + incrementally updated. + +* And if Foo/Bar/Baz is then removed, Foo/Bar gets a broken link, + instead of changing back to linking to Foo/Baz. + +This old bug still exists as of 031d1bf5046ab77c796477a19967e7c0c512c417. diff --git a/doc/bugs/transitive_dependencies.mdwn b/doc/bugs/transitive_dependencies.mdwn index 9586bc9b0..0a2e9ec28 100644 --- a/doc/bugs/transitive_dependencies.mdwn +++ b/doc/bugs/transitive_dependencies.mdwn @@ -65,4 +65,4 @@ Downsides here: modification to plugins/brokenlinks causes an unnecessary update of plugins, and could be solved by adding more dependency types.) ---[[Joey]] +[[done]] --[[Joey]] diff --git a/doc/examples/blog/index.mdwn b/doc/examples/blog/index.mdwn index aef46eb68..01b714fcd 100644 --- a/doc/examples/blog/index.mdwn +++ b/doc/examples/blog/index.mdwn @@ -1,4 +1,4 @@ -[[!pagestats pages="./tags/*"]] +[[!pagestats pages="./tags/*" among="./posts/*"]] Welcome to my blog. diff --git a/doc/examples/blog/tags.mdwn b/doc/examples/blog/tags.mdwn index 53cc8d368..b5eca5b71 100644 --- a/doc/examples/blog/tags.mdwn +++ b/doc/examples/blog/tags.mdwn @@ -1,3 +1,3 @@ -[[!pagestats pages="./tags/*"]] +[[!pagestats pages="./tags/*" among="./posts/*"]] On the right you can see the tag cloud for this blog. diff --git a/doc/ikiwiki/directive/inline.mdwn b/doc/ikiwiki/directive/inline.mdwn index 99f795972..4e087ab6c 100644 --- a/doc/ikiwiki/directive/inline.mdwn +++ b/doc/ikiwiki/directive/inline.mdwn @@ -98,7 +98,7 @@ Here are some less often needed parameters: * `feedonly` - Only generate the feed, do not display the pages inline on the page. * `quick` - Build archives in quick mode, without reading page contents for - metadata. By default, this also turns off generation of any feeds. + metadata. This also turns off generation of any feeds. * `timeformat` - Use this to specify how to display the time or date for pages in the blog. The format string is passed to the strftime(3) function. * `feedpages` - A [[PageSpec]] of inlined pages to include in the rss/atom diff --git a/doc/ikiwiki/directive/linkmap.mdwn b/doc/ikiwiki/directive/linkmap.mdwn index db79a1491..38cf0fd11 100644 --- a/doc/ikiwiki/directive/linkmap.mdwn +++ b/doc/ikiwiki/directive/linkmap.mdwn @@ -9,9 +9,7 @@ Only links between mapped pages will be shown; links pointing to or from unmapped pages will be omitted. If the pages to include are not specified, the links between all pages (and other files) in the wiki are mapped. For best results, only a small set of pages should be mapped, since otherwise -the map can become very large, unwieldy, and complicated. Also, the map is -rebuilt whenever one of the mapped pages is changed, which can make the -wiki a bit slow. +the map can become very large, unwieldy, and complicated. Here are descriptions of all the supported parameters to the `linkmap` directive: diff --git a/doc/ikiwiki/directive/pagestats.mdwn b/doc/ikiwiki/directive/pagestats.mdwn index 66f851dbd..f14c80b07 100644 --- a/doc/ikiwiki/directive/pagestats.mdwn +++ b/doc/ikiwiki/directive/pagestats.mdwn @@ -12,13 +12,13 @@ And here's how to create a table of all the pages on the wiki: \[[!pagestats style="table"]] -The optional `among` parameter limits display to pages that match a -[[ikiwiki/PageSpec]]. For instance, to display a cloud of tags used on blog -entries, you could use: +The optional `among` parameter limits the pages whose outgoing links are +considered. For instance, to display a cloud of tags used on blog +entries, while ignoring other pages that use those tags, you could use: \[[!pagestats pages="tags/*" among="blog/posts/*"]] -or to display a cloud of tags related to Linux, you could use: +Or to display a cloud of tags related to Linux, you could use: \[[!pagestats pages="tags/* and not tags/linux" among="tagged(linux)"]] diff --git a/doc/plugins.mdwn b/doc/plugins.mdwn index 527568208..697b4a219 100644 --- a/doc/plugins.mdwn +++ b/doc/plugins.mdwn @@ -1,7 +1,7 @@ Most of ikiwiki's [[features]] are implemented as plugins. Many of these plugins are included with ikiwiki. -[[!pagestats pages="plugins/type/* and !plugins/type/slow"]] +[[!pagestats pages="plugins/type/* and !plugins/type/slow" among="plugins/*"]] There's documentation if you want to [[write]] your own plugins, or you can [[install]] plugins [[contributed|contrib]] by others. @@ -13,7 +13,5 @@ will fit most uses of ikiwiki. ## Plugin directory -[[!inline pages="plugins/* and !plugins/type/* and !plugins/write and -!plugins/write/* and !plugins/contrib and !plugins/install and !*/Discussion" -feedpages="created_after(plugins/graphviz)" archive="yes" sort=title -rootpage="plugins/contrib" postformtext="Add a new plugin named:" show=0]] +[[!map pages="plugins/* and !plugins/type/* and !plugins/write and +!plugins/write/* and !plugins/contrib and !plugins/install and !*/Discussion"]] diff --git a/doc/plugins/contrib.mdwn b/doc/plugins/contrib.mdwn index a03e6a95d..ac6c1b751 100644 --- a/doc/plugins/contrib.mdwn +++ b/doc/plugins/contrib.mdwn @@ -1,6 +1,4 @@ These plugins are provided by third parties and are not currently included in ikiwiki. See [[install]] for installation help. -[[!inline pages="plugins/contrib/* and !*/Discussion" -feedpages="created_after(plugins/contrib/navbar)" archive="yes" -rootpage="plugins/contrib" postformtext="Add a new plugin named:" show=0]] +[[!map pages="plugins/contrib/* and !*/Discussion"]] diff --git a/doc/plugins/orphans.mdwn b/doc/plugins/orphans.mdwn index ea7c4df13..e403c2d18 100644 --- a/doc/plugins/orphans.mdwn +++ b/doc/plugins/orphans.mdwn @@ -10,5 +10,6 @@ Here's a list of orphaned pages on this wiki: [[!orphans pages="* and !news/* and !todo/* and !bugs/* and !users/* and !recentchanges and !examples/* and !tips/* and !sandbox/* and !templates/* and +!forum/* and !*.js and !wikiicons/* and !plugins/*"]] """]] diff --git a/doc/plugins/sidebar.mdwn b/doc/plugins/sidebar.mdwn index 36982eff3..4e356d65a 100644 --- a/doc/plugins/sidebar.mdwn +++ b/doc/plugins/sidebar.mdwn @@ -16,6 +16,10 @@ will turn off the sidebar altogether. Warning: Any change to the sidebar will cause a rebuild of the whole wiki, since every page includes a copy that has to be updated. This can -especially be a problem if the sidebar includes [[inline]] or [[map]] -directives, since any changes to pages inlined or mapped onto the sidebar +especially be a problem if the sidebar includes an [[ikiwiki/directive/inline]] +directive, since any changes to pages inlined into the sidebar will change the sidebar and cause a full wiki rebuild. + +Instead, if you include a [[ikiwiki/directive/map]] directive on the sidebar, +and it does not use the `show` parameter, only adding or removing pages +included in the map will cause a full rebuild. Modifying pages will not. diff --git a/doc/plugins/write.mdwn b/doc/plugins/write.mdwn index 8e8c3311e..6b47033e5 100644 --- a/doc/plugins/write.mdwn +++ b/doc/plugins/write.mdwn @@ -982,6 +982,13 @@ an IkiWiki::FailReason object if the match fails. If the match cannot be attempted at all, for any page, it can instead return an IkiWiki::ErrorReason object explaining why. +When constructing these objects, you should also include a list of any +pages whose contents or other metadata influenced the result of the match. +For example, "backlink(foo)" is influenced by the contents of page foo; +"link(foo)" and "title(bar)" are influenced by the contents of any +page they match; "created_before(foo)" is influenced by the metadata of +foo; while "glob(*)" is not influenced by the contents of any page. + ### Setup plugins The ikiwiki setup file is loaded using a pluggable mechanism. If you look diff --git a/doc/todo/dependency_types.mdwn b/doc/todo/dependency_types.mdwn index 3bb1b5452..479cc95cc 100644 --- a/doc/todo/dependency_types.mdwn +++ b/doc/todo/dependency_types.mdwn @@ -248,6 +248,7 @@ sigh. that the page links to, which is just what link dependencies are triggered on. +[[done]] ---- ### the removal problem diff --git a/ikiwiki-transition b/ikiwiki-transition index 8a20cf655..1bebb1176 100755 --- a/ikiwiki-transition +++ b/ikiwiki-transition @@ -299,7 +299,7 @@ sub oldloadindex { $pagemtime{$page}=$items{mtime}[0]; $oldlinks{$page}=[@{$items{link}}]; $links{$page}=[@{$items{link}}]; - $depends{$page}={ $items{depends}[0] => 1 } if exists $items{depends}; + $depends{$page}={ $items{depends}[0] => $IkiWiki::DEPEND_CONTENT } if exists $items{depends}; $destsources{$_}=$page foreach @{$items{dest}}; $renderedfiles{$page}=[@{$items{dest}}]; $pagecase{lc $page}=$page; diff --git a/t/add_depends.t b/t/add_depends.t new file mode 100755 index 000000000..d49aa74ce --- /dev/null +++ b/t/add_depends.t @@ -0,0 +1,98 @@ +#!/usr/bin/perl +use warnings; +use strict; +use Test::More tests => 88; + +BEGIN { use_ok("IkiWiki"); } +%config=IkiWiki::defaultconfig(); +$config{srcdir}=$config{destdir}="/dev/null"; +IkiWiki::checkconfig(); + +$pagesources{"foo$_"}="foo$_.mdwn" for 0..9; + +# avoids adding an unparseable pagespec +ok(! add_depends("foo0", "foo and (bar")); +ok(! add_depends("foo0", "foo another")); + +# simple and not-so-simple dependencies split +ok(add_depends("foo0", "*")); +ok(add_depends("foo0", "bar")); +ok(add_depends("foo0", "BAZ")); +ok(exists $IkiWiki::depends_simple{foo0}{"bar"}); +ok(exists $IkiWiki::depends_simple{foo0}{"baz"}); # lowercase +ok(! exists $IkiWiki::depends_simple{foo0}{"*"}); +ok(! exists $IkiWiki::depends{foo0}{"bar"}); +ok(! exists $IkiWiki::depends{foo0}{"baz"}); + +# default dependencies are content dependencies +ok($IkiWiki::depends{foo0}{"*"} & $IkiWiki::DEPEND_CONTENT); +ok(! ($IkiWiki::depends{foo0}{"*"} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS))); +ok($IkiWiki::depends_simple{foo0}{"bar"} & $IkiWiki::DEPEND_CONTENT); +ok(! ($IkiWiki::depends_simple{foo0}{"bar"} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS))); + +# adding other dep types standalone +ok(add_depends("foo2", "*", presence => 1)); +ok(add_depends("foo2", "bar", links => 1)); +ok($IkiWiki::depends{foo2}{"*"} & $IkiWiki::DEPEND_PRESENCE); +ok(! ($IkiWiki::depends{foo2}{"*"} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS))); +ok($IkiWiki::depends_simple{foo2}{"bar"} & $IkiWiki::DEPEND_LINKS); +ok(! ($IkiWiki::depends_simple{foo2}{"bar"} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_CONTENT))); + +# adding combined dep types +ok(add_depends("foo2", "baz", links => 1, presence => 1)); +ok($IkiWiki::depends_simple{foo2}{"baz"} & $IkiWiki::DEPEND_LINKS); +ok($IkiWiki::depends_simple{foo2}{"baz"} & $IkiWiki::DEPEND_PRESENCE); +ok(! ($IkiWiki::depends_simple{foo2}{"baz"} & $IkiWiki::DEPEND_CONTENT)); + +# adding dep types to existing dependencies should merge the flags +ok(add_depends("foo2", "baz")); +ok($IkiWiki::depends_simple{foo2}{"baz"} & $IkiWiki::DEPEND_LINKS); +ok($IkiWiki::depends_simple{foo2}{"baz"} & $IkiWiki::DEPEND_PRESENCE); +ok(($IkiWiki::depends_simple{foo2}{"baz"} & $IkiWiki::DEPEND_CONTENT)); +ok(add_depends("foo2", "bar", presence => 1)); # had only links before +ok($IkiWiki::depends_simple{foo2}{"bar"} & ($IkiWiki::DEPEND_LINKS | $IkiWiki::DEPEND_PRESENCE)); +ok(! ($IkiWiki::depends_simple{foo2}{"bar"} & $IkiWiki::DEPEND_CONTENT)); +ok(add_depends("foo0", "bar", links => 1)); # had only content before +ok($IkiWiki::depends{foo0}{"*"} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS)); +ok(! ($IkiWiki::depends{foo0}{"*"} & $IkiWiki::DEPEND_PRESENCE)); + +# Adding a pagespec that requires page metadata should add the influence +# as an explicit content dependency. +$links{foo0}=$links{foo9}=[qw{bar baz}]; +foreach my $spec ("* and ! link(bar)", "* or link(bar)") { + ok(add_depends("foo3", $spec, presence => 1)); + ok($IkiWiki::depends{foo3}{$spec} & $IkiWiki::DEPEND_PRESENCE); + ok(! ($IkiWiki::depends{foo3}{$spec} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS))); + ok($IkiWiki::depends_simple{foo3}{foo3} == $IkiWiki::DEPEND_CONTENT); + ok(add_depends("foo4", $spec, links => 1)); + ok($IkiWiki::depends{foo4}{$spec} & $IkiWiki::DEPEND_LINKS); + ok(! ($IkiWiki::depends{foo4}{$spec} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_PRESENCE))); + ok($IkiWiki::depends_simple{foo4}{foo4} == $IkiWiki::DEPEND_CONTENT); +} + +# a pagespec with backlinks() will add as an influence the page with the links +$links{foo0}=[qw{foo5 foo7}]; +foreach my $spec ("bugs or (backlink(foo0) and !*.png)", "backlink(foo)") { + ok(add_depends("foo5", $spec, presence => 1)); + ok($IkiWiki::depends{foo5}{$spec} & $IkiWiki::DEPEND_PRESENCE); + ok(! ($IkiWiki::depends{foo5}{$spec} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS))); + ok($IkiWiki::depends_simple{foo5}{foo0} == $IkiWiki::DEPEND_CONTENT); + ok(add_depends("foo6", $spec, links => 1)); + ok($IkiWiki::depends{foo6}{$spec} & $IkiWiki::DEPEND_LINKS); + ok(! ($IkiWiki::depends{foo6}{$spec} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_CONTENT))); + ok($IkiWiki::depends_simple{foo5}{foo0} == $IkiWiki::DEPEND_CONTENT); + ok(add_depends("foo7", $spec, presence => 1, links => 1)); + ok($IkiWiki::depends{foo7}{$spec} & $IkiWiki::DEPEND_PRESENCE); + ok($IkiWiki::depends{foo7}{$spec} & $IkiWiki::DEPEND_LINKS); + ok(! ($IkiWiki::depends{foo7}{$spec} & $IkiWiki::DEPEND_CONTENT)); + ok($IkiWiki::depends_simple{foo7}{foo0} == $IkiWiki::DEPEND_CONTENT); + ok(add_depends("foo8", $spec)); + ok($IkiWiki::depends{foo8}{$spec} & $IkiWiki::DEPEND_CONTENT); + ok(! ($IkiWiki::depends{foo8}{$spec} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS))); + ok($IkiWiki::depends_simple{foo8}{foo0} == $IkiWiki::DEPEND_CONTENT); +} + +# content is the default if unknown types are entered +ok(add_depends("foo9", "*", presenCe => 1)); +ok($IkiWiki::depends{foo9}{"*"} & $IkiWiki::DEPEND_CONTENT); +ok(! ($IkiWiki::depends{foo9}{"*"} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS))); diff --git a/t/pagespec_match.t b/t/pagespec_match.t index 64408f489..1a0db1cef 100755 --- a/t/pagespec_match.t +++ b/t/pagespec_match.t @@ -1,7 +1,7 @@ #!/usr/bin/perl use warnings; use strict; -use Test::More tests => 54; +use Test::More tests => 64; BEGIN { use_ok("IkiWiki"); } @@ -88,3 +88,24 @@ ok(! pagespec_match("foo", "no_such_function(foo)"), "foo"); my $ret=pagespec_match("foo", "(invalid"); ok(! $ret, "syntax error"); ok($ret =~ /syntax error/, "error message"); + +$ret=pagespec_match("foo", "bar or foo"); +ok($ret, "simple match"); +is($ret, "foo matches foo", "stringified return"); + +$ret=pagespec_match("foo", "link(bar)"); +is(join(",", $ret->influences), 'foo', "link is influenced by the page with the link"); +$ret=pagespec_match("bar", "backlink(foo)"); +is(join(",", $ret->influences), 'foo', "backlink is influenced by the page with the link"); +$ret=pagespec_match("bar", "backlink(foo)"); +is(join(",", $ret->influences), 'foo', "backlink is influenced by the page with the link"); +$ret=pagespec_match("bar", "created_before(foo)"); +is(join(",", $ret->influences), 'foo', "created_before is influenced by the comparison page"); +$ret=pagespec_match("bar", "created_after(foo)"); +is(join(",", $ret->influences), 'foo', "created_after is influenced by the comparison page"); +$ret=pagespec_match("bar", "link(quux) and created_after(foo)"); +is(join(",", sort $ret->influences), 'foo,quux', "influences add up over AND"); +$ret=pagespec_match("bar", "link(quux) and created_after(foo)"); +is(join(",", sort $ret->influences), 'foo,quux', "influences add up over OR"); +$ret=pagespec_match("bar", "!link(quux) and !created_after(foo)"); +is(join(",", sort $ret->influences), 'foo,quux', "influences unaffected by negation"); |