]> sipb.mit.edu Git - ikiwiki.git/commitdiff
fix handling of influences of pagespecs that fail to match
authorJoey Hess <joey@gnu.kitenet.net>
Thu, 8 Oct 2009 17:38:46 +0000 (13:38 -0400)
committerJoey Hess <joey@gnu.kitenet.net>
Thu, 8 Oct 2009 17:38:46 +0000 (13:38 -0400)
If a pagespec fails to match, I had been throwing the influences away, but
that is not right. Consider `backlink(foo)`, where foo does not exist.
It still needs to be added as an influence, because if it is created, it
will influence the pagespec to match.

But with that fix, `link(bar)` had as influences all pages, whether they
link to bar or not. Which is not necessary, because modifiying a page to
add a link to bar will directly cause the pagespec to match.

So, in match_link (and all the match_* functions for page metadata),
only return an influence if the match succeeds.

match_backlink had been implemented as the inverse of match_link, but that
is no longer completly true. While match_link does not return an influence
on failure, match_backlink does.

match_created_before/after also return the influence on failure, this way
if created_after(foo) currently fails because foo does not exist, it will
still update the page with the pagespec if foo is created.

IkiWiki.pm
IkiWiki/Plugin/meta.pm

index c250d50adfc6e73fafde2df3f0c35ec97136a389..2064c881a5497a3de1a15f28029d2f810218623e 100644 (file)
@@ -1789,13 +1789,12 @@ sub add_depends ($$;@) {
        }
 
        # Analyse the pagespec, and match it against all pages
        }
 
        # Analyse the pagespec, and match it against all pages
-       # to get a list of influences, and add explicit 
-       # content dependencies for those.
+       # to get a list of influences, and add explicit dependencies
+       # for those.
        my $sub=pagespec_translate($pagespec);
        return if $@;
        foreach my $p (keys %pagesources) {
                my $r=$sub->($p, location => $page );
        my $sub=pagespec_translate($pagespec);
        return if $@;
        foreach my $p (keys %pagesources) {
                my $r=$sub->($p, location => $page );
-               next unless $r;
                my %i=$r->influences;
                foreach my $i (keys %i) {
                        $depends_simple{$page}{lc $i} |= $i{$i};
                my %i=$r->influences;
                foreach my $i (keys %i) {
                        $depends_simple{$page}{lc $i} |= $i{$i};
@@ -2026,7 +2025,13 @@ sub new {
 }
 
 sub influences {
 }
 
 sub influences {
-       return %{$_[0][1]};
+       my $this=shift;
+       if (! @_) {
+               return %{$this->[1]};
+       }
+       else {
+               $this->[1]={@_};
+       }
 }
 
 sub merge_influences {
 }
 
 sub merge_influences {
@@ -2090,7 +2095,7 @@ sub match_link ($$;@) {
        my $from=exists $params{location} ? $params{location} : '';
 
        my $links = $IkiWiki::links{$page};
        my $from=exists $params{location} ? $params{location} : '';
 
        my $links = $IkiWiki::links{$page};
-       return IkiWiki::FailReason->new("$page has no links", $page => $IkiWiki::DEPEND_LINKS)
+       return IkiWiki::FailReason->new("$page has no links")
                unless $links && @{$links};
        my $bestlink = IkiWiki::bestlink($from, $link);
        foreach my $p (@{$links}) {
                unless $links && @{$links};
        my $bestlink = IkiWiki::bestlink($from, $link);
        foreach my $p (@{$links}) {
@@ -2107,11 +2112,13 @@ sub match_link ($$;@) {
                                if match_glob($p_rel, $link, %params);
                }
        }
                                if match_glob($p_rel, $link, %params);
                }
        }
-       return IkiWiki::FailReason->new("$page does not link to $link", $page => $IkiWiki::DEPEND_LINKS);
+       return IkiWiki::FailReason->new("$page does not link to $link");
 }
 
 sub match_backlink ($$;@) {
 }
 
 sub match_backlink ($$;@) {
-       return match_link($_[1], $_[0], @_);
+       my $ret=match_link($_[1], $_[0], @_);
+       $ret->influences($_[1] => $IkiWiki::DEPEND_LINKS);
+       return $ret;
 }
 
 sub match_created_before ($$;@) {
 }
 
 sub match_created_before ($$;@) {
index c160e7ebaac0f090495112b34b64f55fa15a4476..da3e6223311e1f6a3a4808409fb2a93af2d38e63 100644 (file)
@@ -294,11 +294,11 @@ sub match {
                        return IkiWiki::SuccessReason->new("$re matches $field of $page", $page => $IkiWiki::DEPEND_CONTENT);
                }
                else {
                        return IkiWiki::SuccessReason->new("$re matches $field of $page", $page => $IkiWiki::DEPEND_CONTENT);
                }
                else {
-                       return IkiWiki::FailReason->new("$re does not match $field of $page", $page => $IkiWiki::DEPEND_CONTENT);
+                       return IkiWiki::FailReason->new("$re does not match $field of $page");
                }
        }
        else {
                }
        }
        else {
-               return IkiWiki::FailReason->new("$page does not have a $field", $page => $IkiWiki::DEPEND_CONTENT);
+               return IkiWiki::FailReason->new("$page does not have a $field");
        }
 }
 
        }
 }