';
}
diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm
index eef3013a0..9b041a748 100644
--- a/IkiWiki/Plugin/meta.pm
+++ b/IkiWiki/Plugin/meta.pm
@@ -195,7 +195,7 @@ sub preprocess (@) {
if (! length $link) {
error gettext("redir page not found")
}
- add_depends($page, $link, content => 0);
+ add_depends($page, $link, presence => 1);
$value=urlto($link, $page);
$value.='#'.$redir_anchor if defined $redir_anchor;
diff --git a/IkiWiki/Plugin/pagecount.pm b/IkiWiki/Plugin/pagecount.pm
index 17eda0618..80561350b 100644
--- a/IkiWiki/Plugin/pagecount.pm
+++ b/IkiWiki/Plugin/pagecount.pm
@@ -23,8 +23,8 @@ sub preprocess (@) {
$params{pages}="*" unless defined $params{pages};
# Needs to update count whenever a page is added or removed, so
- # register a contentless dependency.
- add_depends($params{page}, $params{pages}, content => 0);
+ # register a presence dependency.
+ add_depends($params{page}, $params{pages}, presence => 1);
my @pages;
if ($params{pages} eq "*") {
diff --git a/IkiWiki/Plugin/postsparkline.pm b/IkiWiki/Plugin/postsparkline.pm
index 694d39575..3205958d4 100644
--- a/IkiWiki/Plugin/postsparkline.pm
+++ b/IkiWiki/Plugin/postsparkline.pm
@@ -48,7 +48,7 @@ sub preprocess (@) {
error gettext("unknown formula");
}
- add_depends($params{page}, $params{pages}, content => 0);
+ add_depends($params{page}, $params{pages}, presence => 1);
my @list=sort { $params{timehash}->{$b} <=> $params{timehash}->{$a} }
pagespec_match_list(
diff --git a/IkiWiki/Plugin/progress.pm b/IkiWiki/Plugin/progress.pm
index 3b664f4cb..26c537a84 100644
--- a/IkiWiki/Plugin/progress.pm
+++ b/IkiWiki/Plugin/progress.pm
@@ -36,8 +36,8 @@ sub preprocess (@) {
$fill.="%";
}
elsif (defined $params{totalpages} and defined $params{donepages}) {
- add_depends($params{page}, $params{totalpages}, content => 0);
- add_depends($params{page}, $params{donepages}, content => 0);
+ add_depends($params{page}, $params{totalpages}, presence => 1);
+ add_depends($params{page}, $params{donepages}, presence => 1);
my @pages=keys %pagesources;
my $totalcount=0;
diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm
index 3fc750925..cf0c3fe08 100644
--- a/IkiWiki/Render.pm
+++ b/IkiWiki/Render.pm
@@ -473,13 +473,11 @@ sub refresh () {
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}) {
- $reason = $d;
- last;
- }
- }
- elsif (exists $lc_changed{$d}) {
+ if (($depends_simple{$p}{$d} & $IkiWiki::DEPEND_CONTENT &&
+ exists $lc_changed{$d})
+ ||
+ ($depends_simple{$p}{$d} & $IkiWiki::DEPEND_PRESENCE &&
+ exists $lc_exists_changed{$d})) {
$reason = $d;
last;
}
@@ -492,22 +490,22 @@ sub refresh () {
next if $@ || ! defined $sub;
my @candidates;
- if ($depends{$p}{$d} == $IkiWiki::DEPEND_EXISTS) {
- @candidates=@exists_changed;
- }
- else {
+ if ($depends_simple{$p}{$d} & $IkiWiki::DEPEND_CONTENT) {
@candidates=@changed;
}
+ elsif ($depends{$p}{$d} & $IkiWiki::DEPEND_PRESENCE) {
+ @candidates=@exists_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;
- }
- else {
+ if ($depends_simple{$p}{$d} & $IkiWiki::DEPEND_CONTENT) {
push @candidates, @internal, @internal_change;
}
+ elsif ($depends{$p}{$d} & $IkiWiki::DEPEND_PRESENCE) {
+ push @candidates, @internal;
+ }
}
foreach my $file (@candidates) {
diff --git a/doc/plugins/write.mdwn b/doc/plugins/write.mdwn
index c244c1f2f..73db6f12a 100644
--- a/doc/plugins/write.mdwn
+++ b/doc/plugins/write.mdwn
@@ -613,12 +613,15 @@ generating a link to a page.
Makes the specified page depend on the specified [[ikiwiki/PageSpec]].
-Additional named parameters can be passed, to indicate what type of
-dependency this is.
-
-Currently, only a "content" parameter is specified. If set to 0, the
-dependency does not involve the content of pages matching the PageSpec, but
-only their existence.
+By default, dependencies are full content dependencies, meaning that the
+page will be updated whenever anything matching the PageSpec is modified.
+This default can be overridden by additional named parameters, which can be
+used to indicate weaker types of dependencies:
+
+* `presence` if set to true, only the presence of a matching page triggers
+ the dependency.
+* `links` if set to true, any change in the text of links on a matching page
+ triggers the dependency
#### `pagespec_match($$;@)`
diff --git a/ikiwiki-transition b/ikiwiki-transition
index c50a748e8..1bebb1176 100755
--- a/ikiwiki-transition
+++ b/ikiwiki-transition
@@ -299,7 +299,7 @@ sub oldloadindex {
$pagemtime{$page}=$items{mtime}[0];
$oldlinks{$page}=[@{$items{link}}];
$links{$page}=[@{$items{link}}];
- $depends{$page}={ $items{depends}[0] => $IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_EXISTS } if exists $items{depends};
+ $depends{$page}={ $items{depends}[0] => $IkiWiki::DEPEND_CONTENT } if exists $items{depends};
$destsources{$_}=$page foreach @{$items{dest}};
$renderedfiles{$page}=[@{$items{dest}}];
$pagecase{lc $page}=$page;
--
cgit v1.2.3
From 4002d7c1a4657e769b036c6e76106991ec5c3897 Mon Sep 17 00:00:00 2001
From: Joey Hess
Date: Wed, 7 Oct 2009 20:31:13 -0400
Subject: add influence info to match_*
Also update docs, test suite.
---
IkiWiki.pm | 24 ++++++++++++------------
IkiWiki/Plugin/meta.pm | 8 ++++----
debian/changelog | 2 ++
doc/plugins/write.mdwn | 7 +++++++
t/pagespec_match.t | 15 +++++++++++++--
5 files changed, 38 insertions(+), 18 deletions(-)
(limited to 'IkiWiki/Plugin/meta.pm')
diff --git a/IkiWiki.pm b/IkiWiki.pm
index 73d2a9763..9c386e154 100644
--- a/IkiWiki.pm
+++ b/IkiWiki.pm
@@ -2039,7 +2039,7 @@ use overload (
sub new {
my $class = shift;
my $value = shift;
- return bless [$value, {@_}], $class;
+ return bless [$value, {map { $_ => 1 } @_}], $class;
}
sub influences {
@@ -2099,23 +2099,23 @@ sub match_link ($$;@) {
my $from=exists $params{location} ? $params{location} : '';
my $links = $IkiWiki::links{$page};
- return IkiWiki::FailReason->new("$page has no links") unless $links && @{$links};
+ return IkiWiki::FailReason->new("$page has no links", $link) unless $links && @{$links};
my $bestlink = IkiWiki::bestlink($from, $link);
foreach my $p (@{$links}) {
if (length $bestlink) {
- return IkiWiki::SuccessReason->new("$page links to $link")
+ return IkiWiki::SuccessReason->new("$page links to $link", $page)
if $bestlink eq IkiWiki::bestlink($page, $p);
}
else {
- return IkiWiki::SuccessReason->new("$page links to page $p matching $link")
+ return IkiWiki::SuccessReason->new("$page links to page $p matching $link", $page)
if match_glob($p, $link, %params);
my ($p_rel)=$p=~/^\/?(.*)/;
$link=~s/^\///;
- return IkiWiki::SuccessReason->new("$page links to page $p_rel matching $link")
+ return IkiWiki::SuccessReason->new("$page links to page $p_rel matching $link", $page)
if match_glob($p_rel, $link, %params);
}
}
- return IkiWiki::FailReason->new("$page does not link to $link");
+ return IkiWiki::FailReason->new("$page does not link to $link", $page);
}
sub match_backlink ($$;@) {
@@ -2131,14 +2131,14 @@ sub match_created_before ($$;@) {
if (exists $IkiWiki::pagectime{$testpage}) {
if ($IkiWiki::pagectime{$page} < $IkiWiki::pagectime{$testpage}) {
- return IkiWiki::SuccessReason->new("$page created before $testpage");
+ return IkiWiki::SuccessReason->new("$page created before $testpage", $testpage);
}
else {
- return IkiWiki::FailReason->new("$page not created before $testpage");
+ return IkiWiki::FailReason->new("$page not created before $testpage", $testpage);
}
}
else {
- return IkiWiki::ErrorReason->new("$testpage does not exist");
+ return IkiWiki::ErrorReason->new("$testpage does not exist", $testpage);
}
}
@@ -2151,14 +2151,14 @@ sub match_created_after ($$;@) {
if (exists $IkiWiki::pagectime{$testpage}) {
if ($IkiWiki::pagectime{$page} > $IkiWiki::pagectime{$testpage}) {
- return IkiWiki::SuccessReason->new("$page created after $testpage");
+ return IkiWiki::SuccessReason->new("$page created after $testpage", $testpage);
}
else {
- return IkiWiki::FailReason->new("$page not created after $testpage");
+ return IkiWiki::FailReason->new("$page not created after $testpage", $testpage);
}
}
else {
- return IkiWiki::ErrorReason->new("$testpage does not exist");
+ return IkiWiki::ErrorReason->new("$testpage does not exist", $testpage);
}
}
diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm
index 9b041a748..a8ee5bc85 100644
--- a/IkiWiki/Plugin/meta.pm
+++ b/IkiWiki/Plugin/meta.pm
@@ -291,21 +291,21 @@ sub match {
if (defined $val) {
if ($val=~/^$re$/i) {
- return IkiWiki::SuccessReason->new("$re matches $field of $page");
+ return IkiWiki::SuccessReason->new("$re matches $field of $page", $page);
}
else {
- return IkiWiki::FailReason->new("$re does not match $field of $page");
+ return IkiWiki::FailReason->new("$re does not match $field of $page", $page);
}
}
else {
- return IkiWiki::FailReason->new("$page does not have a $field");
+ return IkiWiki::FailReason->new("$page does not have a $field", $page);
}
}
package IkiWiki::PageSpec;
sub match_title ($$;@) {
- IkiWiki::Plugin::meta::match("title", @_);
+ IkiWiki::Plugin::meta::match("title", @_);
}
sub match_author ($$;@) {
diff --git a/debian/changelog b/debian/changelog
index dc6ee0a81..565a0cffa 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -32,6 +32,8 @@ ikiwiki (3.14159266) UNRELEASED; urgency=low
* Transitive dependencies are now correctly supported.
* Rebuild wikis on upgrade to this version to get improved dependency
info.
+ * Plugins providing PageSpec `match_*` functions should pass additional
+ influence information when creating result objects.
-- Joey Hess Sun, 27 Sep 2009 17:40:03 -0400
diff --git a/doc/plugins/write.mdwn b/doc/plugins/write.mdwn
index 8e8c3311e..6b47033e5 100644
--- a/doc/plugins/write.mdwn
+++ b/doc/plugins/write.mdwn
@@ -982,6 +982,13 @@ an IkiWiki::FailReason object if the match fails. If the match cannot be
attempted at all, for any page, it can instead return an
IkiWiki::ErrorReason object explaining why.
+When constructing these objects, you should also include a list of any
+pages whose contents or other metadata influenced the result of the match.
+For example, "backlink(foo)" is influenced by the contents of page foo;
+"link(foo)" and "title(bar)" are influenced by the contents of any
+page they match; "created_before(foo)" is influenced by the metadata of
+foo; while "glob(*)" is not influenced by the contents of any page.
+
### Setup plugins
The ikiwiki setup file is loaded using a pluggable mechanism. If you look
diff --git a/t/pagespec_match.t b/t/pagespec_match.t
index a1fcba7c8..f73bfdfe1 100755
--- a/t/pagespec_match.t
+++ b/t/pagespec_match.t
@@ -1,7 +1,7 @@
#!/usr/bin/perl
use warnings;
use strict;
-use Test::More tests => 56;
+use Test::More tests => 61;
BEGIN { use_ok("IkiWiki"); }
@@ -89,6 +89,17 @@ my $ret=pagespec_match("foo", "(invalid");
ok(! $ret, "syntax error");
ok($ret =~ /syntax error/, "error message");
-my $ret=pagespec_match("foo", "bar or foo");
+$ret=pagespec_match("foo", "bar or foo");
ok($ret, "simple match");
is($ret, "foo matches foo", "stringified return");
+
+$ret=pagespec_match("foo", "link(bar)");
+is(join(",", $ret->influences), 'foo', "link is influenced by the page with the link");
+$ret=pagespec_match("bar", "backlink(foo)");
+is(join(",", $ret->influences), 'foo', "backlink is influenced by the page with the link");
+$ret=pagespec_match("bar", "backlink(foo)");
+is(join(",", $ret->influences), 'foo', "backlink is influenced by the page with the link");
+$ret=pagespec_match("bar", "created_before(foo)");
+is(join(",", $ret->influences), 'foo', "created_before is influenced by the comparison page");
+$ret=pagespec_match("bar", "created_after(foo)");
+is(join(",", $ret->influences), 'foo', "created_after is influenced by the comparison page");
--
cgit v1.2.3
From 5f9860e65c65aa769f11e550e63cc164b1519710 Mon Sep 17 00:00:00 2001
From: Joey Hess
Date: Wed, 7 Oct 2009 21:48:03 -0400
Subject: add type info to influence information
---
IkiWiki.pm | 49 ++++++++++++++++++++++++++++++-------------------
IkiWiki/Plugin/meta.pm | 6 +++---
doc/plugins/write.mdwn | 6 +++---
docwiki.setup | 2 +-
t/add_depends.t | 14 +++++++-------
t/pagespec_match.t | 32 ++++++++++++++++----------------
6 files changed, 60 insertions(+), 49 deletions(-)
(limited to 'IkiWiki/Plugin/meta.pm')
diff --git a/IkiWiki.pm b/IkiWiki.pm
index 7adc63139..39a43ddbe 100644
--- a/IkiWiki.pm
+++ b/IkiWiki.pm
@@ -1795,8 +1795,10 @@ sub add_depends ($$;@) {
return if $@;
foreach my $p (keys %pagesources) {
my $r=$sub->($p, location => $page );
- map { $depends_simple{$page}{lc $_} |= $DEPEND_CONTENT } $r->influences
- if $r;
+ my %i=$r->influences;
+ foreach my $i (keys %i) {
+ $depends_simple{$page}{lc $i} |= $i{$i};
+ }
}
$depends{$page}{$pagespec} |= $deptype;
@@ -1998,8 +2000,8 @@ use overload (
'""' => sub { $_[0][0] },
'0+' => sub { 0 },
'!' => sub { bless $_[0], 'IkiWiki::SuccessReason'},
- '&' => sub { $_[0][1]={%{$_[0][1]}, %{$_[1][1]}}; $_[0] },
- '|' => sub { $_[1][1]={%{$_[0][1]}, %{$_[1][1]}}; $_[1] },
+ '&' => sub { $_[0]->merge_influences($_[1]); $_[0] },
+ '|' => sub { $_[1]->merge_influences($_[0]); $_[1] },
fallback => 1,
);
@@ -2011,19 +2013,27 @@ use overload (
'""' => sub { $_[0][0] },
'0+' => sub { 1 },
'!' => sub { bless $_[0], 'IkiWiki::FailReason'},
- '&' => sub { $_[1][1]={%{$_[0][1]}, %{$_[1][1]}}; $_[1] },
- '|' => sub { $_[0][1]={%{$_[0][1]}, %{$_[1][1]}}; $_[0] },
+ '&' => sub { $_[1]->merge_influences($_[0]); $_[1] },
+ '|' => sub { $_[0]->merge_influences($_[1]); $_[0] },
fallback => 1,
);
sub new {
my $class = shift;
my $value = shift;
- return bless [$value, {map { $_ => 1 } @_}], $class;
+ return bless [$value, {@_}], $class;
}
sub influences {
- return keys %{$_[0][1]};
+ return %{$_[0][1]};
+}
+
+sub merge_influences {
+ my $this=shift;
+ my $other=shift;
+ foreach my $influence (keys %{$other->[1]}) {
+ $this->[1]{$influence} |= $other->[1]{$influence};
+ }
}
package IkiWiki::ErrorReason;
@@ -2079,23 +2089,24 @@ sub match_link ($$;@) {
my $from=exists $params{location} ? $params{location} : '';
my $links = $IkiWiki::links{$page};
- return IkiWiki::FailReason->new("$page has no links", $page) unless $links && @{$links};
+ return IkiWiki::FailReason->new("$page has no links", $page => $IkiWiki::DEPEND_LINKS)
+ unless $links && @{$links};
my $bestlink = IkiWiki::bestlink($from, $link);
foreach my $p (@{$links}) {
if (length $bestlink) {
- return IkiWiki::SuccessReason->new("$page links to $link", $page)
+ return IkiWiki::SuccessReason->new("$page links to $link", $page => $IkiWiki::DEPEND_LINKS)
if $bestlink eq IkiWiki::bestlink($page, $p);
}
else {
- return IkiWiki::SuccessReason->new("$page links to page $p matching $link", $page)
+ return IkiWiki::SuccessReason->new("$page links to page $p matching $link", $page => $IkiWiki::DEPEND_LINKS)
if match_glob($p, $link, %params);
my ($p_rel)=$p=~/^\/?(.*)/;
$link=~s/^\///;
- return IkiWiki::SuccessReason->new("$page links to page $p_rel matching $link", $page)
+ return IkiWiki::SuccessReason->new("$page links to page $p_rel matching $link", $page => $IkiWiki::DEPEND_LINKS)
if match_glob($p_rel, $link, %params);
}
}
- return IkiWiki::FailReason->new("$page does not link to $link", $page);
+ return IkiWiki::FailReason->new("$page does not link to $link", $page => $IkiWiki::DEPEND_LINKS);
}
sub match_backlink ($$;@) {
@@ -2111,14 +2122,14 @@ sub match_created_before ($$;@) {
if (exists $IkiWiki::pagectime{$testpage}) {
if ($IkiWiki::pagectime{$page} < $IkiWiki::pagectime{$testpage}) {
- return IkiWiki::SuccessReason->new("$page created before $testpage", $testpage);
+ return IkiWiki::SuccessReason->new("$page created before $testpage", $testpage => $IkiWiki::DEPEND_PRESENCE);
}
else {
- return IkiWiki::FailReason->new("$page not created before $testpage", $testpage);
+ return IkiWiki::FailReason->new("$page not created before $testpage", $testpage => $IkiWiki::DEPEND_PRESENCE);
}
}
else {
- return IkiWiki::ErrorReason->new("$testpage does not exist", $testpage);
+ return IkiWiki::ErrorReason->new("$testpage does not exist", $testpage => $IkiWiki::DEPEND_PRESENCE);
}
}
@@ -2131,14 +2142,14 @@ sub match_created_after ($$;@) {
if (exists $IkiWiki::pagectime{$testpage}) {
if ($IkiWiki::pagectime{$page} > $IkiWiki::pagectime{$testpage}) {
- return IkiWiki::SuccessReason->new("$page created after $testpage", $testpage);
+ return IkiWiki::SuccessReason->new("$page created after $testpage", $testpage => $IkiWiki::DEPEND_PRESENCE);
}
else {
- return IkiWiki::FailReason->new("$page not created after $testpage", $testpage);
+ return IkiWiki::FailReason->new("$page not created after $testpage", $testpage => $IkiWiki::DEPEND_PRESENCE);
}
}
else {
- return IkiWiki::ErrorReason->new("$testpage does not exist", $testpage);
+ return IkiWiki::ErrorReason->new("$testpage does not exist", $testpage => $IkiWiki::DEPEND_PRESENCE);
}
}
diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm
index a8ee5bc85..c160e7eba 100644
--- a/IkiWiki/Plugin/meta.pm
+++ b/IkiWiki/Plugin/meta.pm
@@ -291,14 +291,14 @@ sub match {
if (defined $val) {
if ($val=~/^$re$/i) {
- return IkiWiki::SuccessReason->new("$re matches $field of $page", $page);
+ 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);
+ return IkiWiki::FailReason->new("$re does not match $field of $page", $page => $IkiWiki::DEPEND_CONTENT);
}
}
else {
- return IkiWiki::FailReason->new("$page does not have a $field", $page);
+ return IkiWiki::FailReason->new("$page does not have a $field", $page => $IkiWiki::DEPEND_CONTENT);
}
}
diff --git a/doc/plugins/write.mdwn b/doc/plugins/write.mdwn
index 6b47033e5..232430079 100644
--- a/doc/plugins/write.mdwn
+++ b/doc/plugins/write.mdwn
@@ -982,9 +982,9 @@ an IkiWiki::FailReason object if the match fails. If the match cannot be
attempted at all, for any page, it can instead return an
IkiWiki::ErrorReason object explaining why.
-When constructing these objects, you should also include a list of any
-pages whose contents or other metadata influenced the result of the match.
-For example, "backlink(foo)" is influenced by the contents of page foo;
+When constructing these objects, you should also include information about
+of any pages whose contents or other metadata influenced the result of the
+match. For example, "backlink(foo)" is influenced by the contents of page foo;
"link(foo)" and "title(bar)" are influenced by the contents of any
page they match; "created_before(foo)" is influenced by the metadata of
foo; while "glob(*)" is not influenced by the contents of any page.
diff --git a/docwiki.setup b/docwiki.setup
index 52421e501..41c07f024 100644
--- a/docwiki.setup
+++ b/docwiki.setup
@@ -16,5 +16,5 @@ use IkiWiki::Setup::Standard {
userdir => "users",
usedirs => 0,
prefix_directives => 1,
- add_plugins => [qw{goodstuff version haiku polygen fortune}],
+ add_plugins => [qw{linkmap goodstuff version haiku polygen fortune}],
}
diff --git a/t/add_depends.t b/t/add_depends.t
index d49aa74ce..9f426187b 100755
--- a/t/add_depends.t
+++ b/t/add_depends.t
@@ -57,17 +57,17 @@ ok($IkiWiki::depends{foo0}{"*"} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_L
ok(! ($IkiWiki::depends{foo0}{"*"} & $IkiWiki::DEPEND_PRESENCE));
# Adding a pagespec that requires page metadata should add the influence
-# as an explicit content dependency.
+# as an explicit dependency. In the case of a link, a links dependency.
$links{foo0}=$links{foo9}=[qw{bar baz}];
foreach my $spec ("* and ! link(bar)", "* or link(bar)") {
ok(add_depends("foo3", $spec, presence => 1));
ok($IkiWiki::depends{foo3}{$spec} & $IkiWiki::DEPEND_PRESENCE);
ok(! ($IkiWiki::depends{foo3}{$spec} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS)));
- ok($IkiWiki::depends_simple{foo3}{foo3} == $IkiWiki::DEPEND_CONTENT);
+ ok($IkiWiki::depends_simple{foo3}{foo3} == $IkiWiki::DEPEND_LINKS);
ok(add_depends("foo4", $spec, links => 1));
ok($IkiWiki::depends{foo4}{$spec} & $IkiWiki::DEPEND_LINKS);
ok(! ($IkiWiki::depends{foo4}{$spec} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_PRESENCE)));
- ok($IkiWiki::depends_simple{foo4}{foo4} == $IkiWiki::DEPEND_CONTENT);
+ ok($IkiWiki::depends_simple{foo4}{foo4} == $IkiWiki::DEPEND_LINKS);
}
# a pagespec with backlinks() will add as an influence the page with the links
@@ -76,20 +76,20 @@ foreach my $spec ("bugs or (backlink(foo0) and !*.png)", "backlink(foo)") {
ok(add_depends("foo5", $spec, presence => 1));
ok($IkiWiki::depends{foo5}{$spec} & $IkiWiki::DEPEND_PRESENCE);
ok(! ($IkiWiki::depends{foo5}{$spec} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS)));
- ok($IkiWiki::depends_simple{foo5}{foo0} == $IkiWiki::DEPEND_CONTENT);
+ ok($IkiWiki::depends_simple{foo5}{foo0} == $IkiWiki::DEPEND_LINKS);
ok(add_depends("foo6", $spec, links => 1));
ok($IkiWiki::depends{foo6}{$spec} & $IkiWiki::DEPEND_LINKS);
ok(! ($IkiWiki::depends{foo6}{$spec} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_CONTENT)));
- ok($IkiWiki::depends_simple{foo5}{foo0} == $IkiWiki::DEPEND_CONTENT);
+ ok($IkiWiki::depends_simple{foo5}{foo0} == $IkiWiki::DEPEND_LINKS);
ok(add_depends("foo7", $spec, presence => 1, links => 1));
ok($IkiWiki::depends{foo7}{$spec} & $IkiWiki::DEPEND_PRESENCE);
ok($IkiWiki::depends{foo7}{$spec} & $IkiWiki::DEPEND_LINKS);
ok(! ($IkiWiki::depends{foo7}{$spec} & $IkiWiki::DEPEND_CONTENT));
- ok($IkiWiki::depends_simple{foo7}{foo0} == $IkiWiki::DEPEND_CONTENT);
+ ok($IkiWiki::depends_simple{foo7}{foo0} == $IkiWiki::DEPEND_LINKS);
ok(add_depends("foo8", $spec));
ok($IkiWiki::depends{foo8}{$spec} & $IkiWiki::DEPEND_CONTENT);
ok(! ($IkiWiki::depends{foo8}{$spec} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS)));
- ok($IkiWiki::depends_simple{foo8}{foo0} == $IkiWiki::DEPEND_CONTENT);
+ ok($IkiWiki::depends_simple{foo8}{foo0} == $IkiWiki::DEPEND_LINKS);
}
# content is the default if unknown types are entered
diff --git a/t/pagespec_match.t b/t/pagespec_match.t
index 1a0db1cef..36fa04370 100755
--- a/t/pagespec_match.t
+++ b/t/pagespec_match.t
@@ -93,19 +93,19 @@ $ret=pagespec_match("foo", "bar or foo");
ok($ret, "simple match");
is($ret, "foo matches foo", "stringified return");
-$ret=pagespec_match("foo", "link(bar)");
-is(join(",", $ret->influences), 'foo', "link is influenced by the page with the link");
-$ret=pagespec_match("bar", "backlink(foo)");
-is(join(",", $ret->influences), 'foo', "backlink is influenced by the page with the link");
-$ret=pagespec_match("bar", "backlink(foo)");
-is(join(",", $ret->influences), 'foo', "backlink is influenced by the page with the link");
-$ret=pagespec_match("bar", "created_before(foo)");
-is(join(",", $ret->influences), 'foo', "created_before is influenced by the comparison page");
-$ret=pagespec_match("bar", "created_after(foo)");
-is(join(",", $ret->influences), 'foo', "created_after is influenced by the comparison page");
-$ret=pagespec_match("bar", "link(quux) and created_after(foo)");
-is(join(",", sort $ret->influences), 'foo,quux', "influences add up over AND");
-$ret=pagespec_match("bar", "link(quux) and created_after(foo)");
-is(join(",", sort $ret->influences), 'foo,quux', "influences add up over OR");
-$ret=pagespec_match("bar", "!link(quux) and !created_after(foo)");
-is(join(",", sort $ret->influences), 'foo,quux', "influences unaffected by negation");
+my %i=pagespec_match("foo", "link(bar)")->influences;
+is(join(",", keys %i), 'foo', "link is influenced by the page with the link");
+%i=pagespec_match("bar", "backlink(foo)")->influences;
+is(join(",", keys %i), 'foo', "backlink is influenced by the page with the link");
+%i=pagespec_match("bar", "backlink(foo)")->influences;
+is(join(",", keys %i), 'foo', "backlink is influenced by the page with the link");
+%i=pagespec_match("bar", "created_before(foo)")->influences;
+is(join(",", keys %i), 'foo', "created_before is influenced by the comparison page");
+%i=pagespec_match("bar", "created_after(foo)")->influences;
+is(join(",", keys %i), 'foo', "created_after is influenced by the comparison page");
+%i=pagespec_match("bar", "link(quux) and created_after(foo)")->influences;
+is(join(",", sort keys %i), 'bar,foo', "influences add up over AND");
+%i=pagespec_match("bar", "link(quux) and created_after(foo)")->influences;
+is(join(",", sort keys %i), 'bar,foo', "influences add up over OR");
+%i=pagespec_match("bar", "!link(quux) and !created_after(foo)")->influences;
+is(join(",", sort keys %i), 'bar,foo', "influences unaffected by negation");
--
cgit v1.2.3
From f2b3d1341447cbf29189ab490daae418fbe5d02d Mon Sep 17 00:00:00 2001
From: Joey Hess
Date: Thu, 8 Oct 2009 13:38:46 -0400
Subject: fix handling of influences of pagespecs that fail to match
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 | 21 ++++++++++++++-------
IkiWiki/Plugin/meta.pm | 4 ++--
2 files changed, 16 insertions(+), 9 deletions(-)
(limited to 'IkiWiki/Plugin/meta.pm')
diff --git a/IkiWiki.pm b/IkiWiki.pm
index c250d50ad..2064c881a 100644
--- a/IkiWiki.pm
+++ b/IkiWiki.pm
@@ -1789,13 +1789,12 @@ sub add_depends ($$;@) {
}
# 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 );
- next unless $r;
my %i=$r->influences;
foreach my $i (keys %i) {
$depends_simple{$page}{lc $i} |= $i{$i};
@@ -2026,7 +2025,13 @@ sub new {
}
sub influences {
- return %{$_[0][1]};
+ my $this=shift;
+ if (! @_) {
+ return %{$this->[1]};
+ }
+ else {
+ $this->[1]={@_};
+ }
}
sub merge_influences {
@@ -2090,7 +2095,7 @@ sub match_link ($$;@) {
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}) {
@@ -2107,11 +2112,13 @@ sub match_link ($$;@) {
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 ($$;@) {
- return match_link($_[1], $_[0], @_);
+ my $ret=match_link($_[1], $_[0], @_);
+ $ret->influences($_[1] => $IkiWiki::DEPEND_LINKS);
+ return $ret;
}
sub match_created_before ($$;@) {
diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm
index c160e7eba..da3e62233 100644
--- a/IkiWiki/Plugin/meta.pm
+++ b/IkiWiki/Plugin/meta.pm
@@ -294,11 +294,11 @@ sub match {
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 {
- return IkiWiki::FailReason->new("$page does not have a $field", $page => $IkiWiki::DEPEND_CONTENT);
+ return IkiWiki::FailReason->new("$page does not have a $field");
}
}
--
cgit v1.2.3
From c57908b9d073500608d656adaf2bd3048c8cef67 Mon Sep 17 00:00:00 2001
From: Joey Hess
Date: Thu, 8 Oct 2009 16:49:03 -0400
Subject: change how dependency types are specified to add_depends
Also, this fixes 2 bugs in dependency info.
---
IkiWiki/Plugin/brokenlinks.pm | 2 +-
IkiWiki/Plugin/calendar.pm | 17 +++++++++--------
IkiWiki/Plugin/edittemplate.pm | 2 +-
IkiWiki/Plugin/inline.pm | 7 ++++++-
IkiWiki/Plugin/linkmap.pm | 2 +-
IkiWiki/Plugin/listdirectives.pm | 2 +-
IkiWiki/Plugin/map.pm | 3 ++-
IkiWiki/Plugin/meta.pm | 2 +-
IkiWiki/Plugin/orphans.pm | 4 ++--
IkiWiki/Plugin/pagecount.pm | 2 +-
IkiWiki/Plugin/pagestats.pm | 4 ++--
IkiWiki/Plugin/postsparkline.pm | 2 +-
IkiWiki/Plugin/progress.pm | 4 ++--
13 files changed, 30 insertions(+), 23 deletions(-)
(limited to 'IkiWiki/Plugin/meta.pm')
diff --git a/IkiWiki/Plugin/brokenlinks.pm b/IkiWiki/Plugin/brokenlinks.pm
index 9e65f52c6..62a0a42f4 100644
--- a/IkiWiki/Plugin/brokenlinks.pm
+++ b/IkiWiki/Plugin/brokenlinks.pm
@@ -24,7 +24,7 @@ sub preprocess (@) {
$params{pages}="*" unless defined $params{pages};
# Needs to update whenever the links on a page change.
- add_depends($params{page}, $params{pages}, links => 1);
+ add_depends($params{page}, $params{pages}, deptype("links"));
my @broken;
foreach my $link (keys %IkiWiki::brokenlinks) {
diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm
index ec8e232e1..c99170f92 100644
--- a/IkiWiki/Plugin/calendar.pm
+++ b/IkiWiki/Plugin/calendar.pm
@@ -105,21 +105,21 @@ sub format_month (@) {
linktext => " $monthname ");
}
add_depends($params{page}, "$archivebase/$year/".sprintf("%02d", $month),
- presence => 1);
+ deptype("presence"));
if (exists $cache{$pagespec}{"$pyear/$pmonth"}) {
$purl = htmllink($params{page}, $params{destpage},
"$archivebase/$pyear/" . sprintf("%02d", $pmonth),
linktext => " $pmonthname ");
}
add_depends($params{page}, "$archivebase/$pyear/".sprintf("%02d", $pmonth),
- presence => 1);
+ deptype("presence"));
if (exists $cache{$pagespec}{"$nyear/$nmonth"}) {
$nurl = htmllink($params{page}, $params{destpage},
"$archivebase/$nyear/" . sprintf("%02d", $nmonth),
linktext => " $nmonthname ");
}
add_depends($params{page}, "$archivebase/$nyear/".sprintf("%02d", $nmonth),
- presence => 1);
+ deptype("presence"));
# Start producing the month calendar
$calendar=< 1);
+ add_depends($params{page}, $params{pages}, deptype("presence"));
return $calendar;
}
@@ -244,19 +244,19 @@ sub format_year (@) {
"$archivebase/$year",
linktext => "$year");
}
- add_depends($params{page}, "$archivebase/$year", presence => 1);
+ add_depends($params{page}, "$archivebase/$year", deptype("presence");
if (exists $cache{$pagespec}{"$pyear"}) {
$purl = htmllink($params{page}, $params{destpage},
"$archivebase/$pyear",
linktext => "\←");
}
- add_depends($params{page}, "$archivebase/$pyear", presence => 1);
+ add_depends($params{page}, "$archivebase/$pyear", deptype("presence"));
if (exists $cache{$pagespec}{"$nyear"}) {
$nurl = htmllink($params{page}, $params{destpage},
"$archivebase/$nyear",
linktext => "\→");
}
- add_depends($params{page}, "$archivebase/$nyear", presence => 1);
+ add_depends($params{page}, "$archivebase/$nyear", deptype("presence"));
# Start producing the year calendar
$calendar=<$monthabbr\n};
}
- add_depends($params{page}, "$archivebase/$year/$mtag", presence => 1);
+ add_depends($params{page}, "$archivebase/$year/$mtag",
+ deptype("presence"));
$calendar.=qq{\t\n} if ($month % $params{months_per_row} == 0);
}
diff --git a/IkiWiki/Plugin/edittemplate.pm b/IkiWiki/Plugin/edittemplate.pm
index 2dd1dbe68..7d2eba194 100644
--- a/IkiWiki/Plugin/edittemplate.pm
+++ b/IkiWiki/Plugin/edittemplate.pm
@@ -58,7 +58,7 @@ sub preprocess (@) {
$pagestate{$params{page}}{edittemplate}{$params{match}}=$link;
return "" if ($params{silent} && IkiWiki::yesno($params{silent}));
- add_depends($params{page}, $link, presence => 1);
+ add_depends($params{page}, $link, deptype("presence"));
return sprintf(gettext("edittemplate %s registered for %s"),
htmllink($params{page}, $params{destpage}, $link),
$params{match});
diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm
index fc4e00a83..be1781520 100644
--- a/IkiWiki/Plugin/inline.pm
+++ b/IkiWiki/Plugin/inline.pm
@@ -195,9 +195,14 @@ sub preprocess_inline (@) {
@list = map { bestlink($params{page}, $_) }
split ' ', $params{pagenames};
+
+ foreach my $p (@list) {
+ add_depends($params{page}, $p, deptype($quick ? "presence" : "content"));
+ }
}
else {
- add_depends($params{page}, $params{pages}, presence => $quick);
+ add_depends($params{page}, $params{pages},
+ deptype($quick ? "presence" : "content"));
@list = pagespec_match_list(
[ grep { $_ ne $params{page} } keys %pagesources ],
diff --git a/IkiWiki/Plugin/linkmap.pm b/IkiWiki/Plugin/linkmap.pm
index 3d20a6521..28e4cfa13 100644
--- a/IkiWiki/Plugin/linkmap.pm
+++ b/IkiWiki/Plugin/linkmap.pm
@@ -30,7 +30,7 @@ sub preprocess (@) {
# Needs to update whenever a relevant page is added, or removed, or
# its links change.
- add_depends($params{page}, $params{pages}, presence => 1, links => 1);
+ add_depends($params{page}, $params{pages}, deptype("presence", "links"));
# Can't just return the linkmap here, since the htmlscrubber
# scrubs out all