]> sipb.mit.edu Git - ikiwiki.git/commitdiff
fix support of a single dependency that combines links and exists types
authorJoey Hess <joey@gnu.kitenet.net>
Tue, 6 Oct 2009 22:09:46 +0000 (18:09 -0400)
committerJoey Hess <joey@gnu.kitenet.net>
Tue, 6 Oct 2009 22:09:46 +0000 (18:09 -0400)
This is very common, and the code has to test each type differently, since
the list of candidates to test, as well as the test, will vary per type.
Much happier with this code now.

IkiWiki/Render.pm

index e863141070b802db6b2f824c65fe0ca9e8afe1e5..8f9cbf673e481b9e1a291f6b0d58673f895d5917 100644 (file)
@@ -545,38 +545,53 @@ sub render_dependent ($$$$$$$) {
                }
        
                if (exists $depends{$p} && ! defined $reason) {
                }
        
                if (exists $depends{$p} && ! defined $reason) {
-                       D: foreach my $d (keys %{$depends{$p}}) {
-                               my $sub=pagespec_translate($d);
+                       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
                                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_new, @$internal_del
-                                               if $internal_dep;
-                               }
-                               if (($depends{$p}{$d} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS))) {
-                                       @candidates=@changed;
-                                       push @candidates, @$internal_new, @$internal_del, @$internal_changed
-                                               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 &&
-                                                   ! $depends{$p}{$d} & $IkiWiki::DEPEND_CONTENT) {
-                                                       next unless $linkchangers->{lc($page)};
+                               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)) {
+                                                       if ($type == $IkiWiki::DEPEND_LINKS) {
+                                                               next unless $linkchangers->{lc($page)};
+                                                       }
+                                                       return $page;
                                                }
                                                }
-                                               $reason = $page;
-                                               last D;
                                        }
                                        }
+                                       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 ($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 ($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));
                                }
                        }
                }
                                }
                        }
                }