aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Hess <joey@gnu.kitenet.net>2009-10-13 14:37:14 -0400
committerJoey Hess <joey@gnu.kitenet.net>2009-10-13 14:37:14 -0400
commita20bc7a3fc6a2f2369022873ef7c2afbd5e49105 (patch)
treeb885c1392e469a16f40a228345558e4ff3a97623
parent5e4e43e2c73d6077f8091fe063add1ebce9335e3 (diff)
downloadikiwiki-a20bc7a3fc6a2f2369022873ef7c2afbd5e49105.tar
ikiwiki-a20bc7a3fc6a2f2369022873ef7c2afbd5e49105.tar.gz
influence blocker implementation
This avoids unnecessary influences being recorded from pagespecs such as "link(done) and bugs/*", when a page cannot ever possibly match. A pagespec term that returns a value without influence is an influence blocker. If such a blocker has a false value (possibly due to being negated) and is ANDed with another term, it blocks that term's influence from propigating out. If the term is ORed, or has a true value, it does not block influence. (Consider "link(done) or bugs/*" and "link(done) and !nosuchpage") In the implementation in merge_influence, I had to be careful to never negate $this or $other when testing if they are an influence blocker, since negation mutates the object. Thus the slightly weird if statement.
-rw-r--r--IkiWiki.pm20
1 files changed, 16 insertions, 4 deletions
diff --git a/IkiWiki.pm b/IkiWiki.pm
index 2847c7e0f..ac01ea418 100644
--- a/IkiWiki.pm
+++ b/IkiWiki.pm
@@ -2071,7 +2071,7 @@ use overload (
'""' => sub { $_[0][0] },
'0+' => sub { 0 },
'!' => sub { bless $_[0], 'IkiWiki::SuccessReason'},
- '&' => sub { $_[0]->merge_influences($_[1]); $_[0] },
+ '&' => sub { $_[0]->merge_influences($_[1], 1); $_[0] },
'|' => sub { $_[1]->merge_influences($_[0]); $_[1] },
fallback => 1,
);
@@ -2084,7 +2084,7 @@ use overload (
'""' => sub { $_[0][0] },
'0+' => sub { 1 },
'!' => sub { bless $_[0], 'IkiWiki::FailReason'},
- '&' => sub { $_[1]->merge_influences($_[0]); $_[1] },
+ '&' => sub { $_[1]->merge_influences($_[0], 1); $_[1] },
'|' => sub { $_[0]->merge_influences($_[1]); $_[0] },
fallback => 1,
);
@@ -2110,8 +2110,20 @@ sub influences_static {
sub merge_influences {
my $this=shift;
my $other=shift;
- foreach my $influence (keys %{$other->[1]}) {
- $this->[1]{$influence} |= $other->[1]{$influence};
+ my $anded=shift;
+
+ if (! $anded || (($this || %{$this->[1]}) &&
+ ($other || %{$other->[1]}))) {
+ foreach my $influence (keys %{$other->[1]}) {
+ $this->[1]{$influence} |= $other->[1]{$influence};
+ }
+ }
+ else {
+ # influence blocker
+ print STDERR "merging $this and $other; found influence blocker\n";
+ $this->[1]={};
+ $this->[2]=1;
+ return;
}
}