]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Render.pm
fix add_depends to new api
[ikiwiki.git] / IkiWiki / Render.pm
index 9e00428c2127376182a304bdb34c4f8383b04880..4e8aae3bc8ea187cd82f0d8b17d17b84dfc9e2c8 100644 (file)
@@ -58,6 +58,37 @@ 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 $link (map { bestlink($page, $_) } @{$links{$page}}) {
+                               if (length $link &&
+                                   (! exists $oldlinks{$page} ||
+                                    ! grep { bestlink($page, $_) eq $link } @{$oldlinks{$page}})) {
+                                       $linkchanged{$link}=1;
+                                       $linkchangers{lc($page)}=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;
+                                       $linkchangers{lc($page)}=1;
+                               }
+                       }
+               }
+       }
+
+       return \%linkchanged, \%linkchangers;
+}
+
 sub genpage ($$) {
        my $page=shift;
        my $content=shift;
@@ -456,101 +487,88 @@ sub refresh () {
 
        if (%rendered || @del || @internal || @internal_change) {
                my @changed=(keys %rendered, @del);
-               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};
-                       my $p=pagename($f);
-                       my $reason = undef;
+               my ($linkchanged, $linkchangers)=find_changed_links(@changed);
 
-                       if (exists $depends_simple{$p}) {
-                               foreach my $d (keys %{$depends_simple{$p}}) {
-                                       if ($depends_simple{$p}{$d} == $IkiWiki::DEPEND_EXISTS) {
-                                               if (exists $lc_exists_changed{$d}) {
+               my $unsettled;
+               do {
+                       $unsettled=0;
+                       @changed=(keys %rendered, @del);
+                       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};
+                               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;
                                                }
                                        }
-                                       elsif (exists $lc_changed{$d}) {
-                                               $reason = $d;
-                                               last;
-                                       }
                                }
-                       }
-
-                       if (exists $depends{$p} && ! defined $reason) {
-                               D: foreach my $d (keys %{$depends{$p}}) {
-                                       my $sub=pagespec_translate($d);
-                                       next if $@ || ! defined $sub;
-
-                                       my @candidates;
-                                       if ($depends{$p}{$d} == $IkiWiki::DEPEND_EXISTS) {
-                                               @candidates=@exists_changed;
-                                       }
-                                       else {
-                                               @candidates=@changed;
-                                       }
-                                       # only consider internal files
-                                       # if the page explicitly depends
-                                       # on such files
-                                       if ($d =~ /internal\(/) {
-                                               if ($depends{$p}{$d} == $IkiWiki::DEPEND_EXISTS) {
-                                                       push @candidates, @internal;
+       
+                               if (exists $depends{$p} && ! defined $reason) {
+                                       D: foreach my $d (keys %{$depends{$p}}) {
+                                               my $sub=pagespec_translate($d);
+                                               next if $@ || ! defined $sub;
+       
+                                               # only consider internal files
+                                               # if the page explicitly depends
+                                               # on such files
+                                               my $internal_dep=$d =~ /internal\(/;
+
+                                               my @candidates;
+                                               if ($depends{$p}{$d} & $IkiWiki::DEPEND_PRESENCE) {
+                                                       @candidates=@exists_changed;
+                                                       push @candidates, @internal
+                                                               if $internal_dep;
                                                }
-                                               else {
-                                                       push @candidates, @internal, @internal_change;
+                                               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)) {
-                                                       $reason = $page;
-                                                       last D;
+                                               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;
+                                                       }
                                                }
                                        }
                                }
-                       }
-
-                       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 (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 (defined $reason) {
+                                       debug(sprintf(gettext("building %s, which depends on %s"), $f, $reason));
+                                       render($f);
+                                       $rendered{$f}=1;
+                                       $unsettled=1;
+                                       last;
                                }
                        }
-               }
-
-               foreach my $link (keys %linkchanged) {
+               } while $unsettled;
+               
+               # update backlinks at end
+               foreach my $link (keys %{$linkchanged}) {
                        my $linkfile=$pagesources{$link};
                        if (defined $linkfile) {
                                next if $rendered{$linkfile};