X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/66a7b49acb06e0e9b3d0b31d087202d3c81d85e9..c6bf4228d5c988e715ff08a9374b72ce054daa2c:/IkiWiki/Render.pm diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm index 09b646f75..599bb26e2 100644 --- a/IkiWiki/Render.pm +++ b/IkiWiki/Render.pm @@ -58,6 +58,52 @@ sub backlinks ($) { return @links; } +sub find_changed_links (@_) { + my %linkchanged; + my %linkchangers; + foreach my $file (@_) { + my $page=pagename($file); + + if (exists $links{$page}) { + foreach my $l (@{$links{$page}}) { + my $link=bestlink($page, $l); + if (length $link) { + if (! exists $oldlinks{$page} || + ! grep { bestlink($page, $_) eq $link } @{$oldlinks{$page}}) { + $linkchanged{$link}=1; + $linkchangers{lc($page)}=1; + } + } + else { + if (! grep { lc $_ eq lc $l } @{$oldlinks{$page}}) { + $linkchangers{lc($page)}=1 + } + } + + } + } + if (exists $oldlinks{$page}) { + foreach my $l (@{$oldlinks{$page}}) { + my $link=bestlink($page, $l); + if (length $link) { + if (! exists $links{$page} || + ! grep { bestlink($page, $_) eq $link } @{$links{$page}}) { + $linkchanged{$link}=1; + $linkchangers{lc($page)}=1; + } + } + else { + if (! grep { lc $_ eq lc $l } @{$links{$page}}) { + $linkchangers{lc($page)}=1 + } + } + } + } + } + + return \%linkchanged, \%linkchangers; +} + sub genpage ($$) { my $page=shift; my $content=shift; @@ -342,7 +388,7 @@ sub refresh () { run_hooks(refresh => sub { shift->() }); my ($files, $exists)=find_src_files(); - my (%rendered, @add, @del, @internal); + my (%rendered, @add, @del, @internal, @internal_change); # check for added or removed pages foreach my $file (@$files) { my $page=pagename($file); @@ -407,7 +453,7 @@ sub refresh () { $forcerebuild{$page}) { $pagemtime{$page}=$stat[9]; if (isinternal($page)) { - push @internal, $file; + push @internal_change, $file; # Preprocess internal page in scan-only mode. preprocess($page, $page, readfile($srcfile), 1); } @@ -429,7 +475,7 @@ sub refresh () { render($file); $rendered{$file}=1; } - foreach my $file (@internal) { + foreach my $file (@internal, @internal_change) { # internal pages are not rendered my $page=pagename($file); delete $depends{$page}; @@ -454,14 +500,19 @@ sub refresh () { } } - if (%rendered || @del || @internal) { - my @changed; - my $changes; + if (%rendered || @del || @internal || @internal_change) { + my @changed=(keys %rendered, @del); + my ($linkchanged, $linkchangers)=find_changed_links(@changed); + + my $unsettled; do { - $changes=0; + $unsettled=0; @changed=(keys %rendered, @del); - my %lcchanged = map { lc(pagename($_)) => 1 } @changed; - + my @exists_changed=(@add, @del); + + my %lc_changed = map { lc(pagename($_)) => 1 } @changed; + my %lc_exists_changed = map { lc(pagename($_)) => 1 } @exists_changed; + # rebuild dependant pages foreach my $f (@$files) { next if $rendered{$f}; @@ -470,7 +521,15 @@ sub refresh () { if (exists $depends_simple{$p}) { foreach my $d (keys %{$depends_simple{$p}}) { - if (exists $lcchanged{$d}) { + 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; } @@ -485,10 +544,27 @@ sub refresh () { # only consider internal files # if the page explicitly depends # on such files - foreach my $file (@changed, $d =~ /internal\(/ ? @internal : ()) { + my $internal_dep=$d =~ /internal\(/; + + my @candidates; + if ($depends{$p}{$d} & $IkiWiki::DEPEND_PRESENCE) { + @candidates=@exists_changed; + push @candidates, @internal + if $internal_dep; + } + if (($depends{$p}{$d} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS))) { + @candidates=@changed; + push @candidates, @internal, @internal_change + if $internal_dep; + } + + foreach my $file (@candidates) { next if $file eq $f; my $page=pagename($file); if ($sub->($page, location => $p)) { + if ($depends{$p}{$d} & $IkiWiki::DEPEND_LINKS) { + next unless $linkchangers->{lc($page)}; + } $reason = $page; last D; } @@ -500,39 +576,14 @@ sub refresh () { debug(sprintf(gettext("building %s, which depends on %s"), $f, $reason)); render($f); $rendered{$f}=1; - $changes++; + $unsettled=1; last; } } - } while $changes; + } while $unsettled; - # 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 (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; - } - } - } - } - - foreach my $link (keys %linkchanged) { + # update backlinks at end + foreach my $link (keys %{$linkchanged}) { my $linkfile=$pagesources{$link}; if (defined $linkfile) { next if $rendered{$linkfile};