summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--IkiWiki.pm52
-rwxr-xr-xt/add_depends.t86
2 files changed, 62 insertions, 76 deletions
diff --git a/IkiWiki.pm b/IkiWiki.pm
index 9c386e154..7adc63139 100644
--- a/IkiWiki.pm
+++ b/IkiWiki.pm
@@ -1772,52 +1772,32 @@ sub add_depends ($$;@) {
my $page=shift;
my $pagespec=shift;
- # Is the pagespec a simple page name?
- my $simple=$pagespec =~ /$config{wiki_file_regexp}/ &&
- $pagespec !~ /[\s*?()!]/;
-
my $deptype=0;
if (@_) {
my %params=@_;
- if ($params{presence}) {
- # Is the pagespec limited to terms that will continue
- # to match pages as long as those pages exist?
- my $presence_limited=1;
- while ($presence_limited && $pagespec=~m/(\w+)\([^\)]*\)/g) {
- $presence_limited = $1 =~ /^(glob|internal|creation_month|creation_day|creation_year|created_before|created_after)$/;
- }
- if ($presence_limited) {
- $deptype=$deptype | $DEPEND_PRESENCE;
- }
- else {
- $deptype=$deptype | $DEPEND_CONTENT;
- }
- }
- if ($params{links}) {
- # Is the pagespec limited to terms that will continue
- # to match pages as long as those pages exist and
- # link to the same places?
- my $links_limited=1;
- while ($links_limited && $pagespec=~m/(\w+)\([^\)]*\)/g) {
- $links_limited = $1 =~ /^(glob|internal|creation_month|creation_day|creation_year|created_before|created_after|backlink)$/;
- }
- if ($links_limited) {
- $deptype=$deptype | $DEPEND_LINKS;
- }
- else {
- $deptype=$deptype | $DEPEND_CONTENT;
- }
- }
+ $deptype=$deptype | $DEPEND_PRESENCE if $params{presence};
+ $deptype=$deptype | $DEPEND_LINKS if $params{links};
}
$deptype=$DEPEND_CONTENT unless $deptype;
- if ($simple) {
+ # Is the pagespec a simple page name?
+ if ($pagespec =~ /$config{wiki_file_regexp}/ &&
+ $pagespec !~ /[\s*?()!]/) {
$depends_simple{$page}{lc $pagespec} |= $deptype;
return 1;
}
- return unless pagespec_valid($pagespec);
+ # Analyse the pagespec, and match it against all pages
+ # to get a list of influences, and add explicit
+ # content dependencies for those.
+ my $sub=pagespec_translate($pagespec);
+ return if $@;
+ foreach my $p (keys %pagesources) {
+ my $r=$sub->($p, location => $page );
+ map { $depends_simple{$page}{lc $_} |= $DEPEND_CONTENT } $r->influences
+ if $r;
+ }
$depends{$page}{$pagespec} |= $deptype;
return 1;
@@ -2099,7 +2079,7 @@ sub match_link ($$;@) {
my $from=exists $params{location} ? $params{location} : '';
my $links = $IkiWiki::links{$page};
- return IkiWiki::FailReason->new("$page has no links", $link) unless $links && @{$links};
+ return IkiWiki::FailReason->new("$page has no links", $page) unless $links && @{$links};
my $bestlink = IkiWiki::bestlink($from, $link);
foreach my $p (@{$links}) {
if (length $bestlink) {
diff --git a/t/add_depends.t b/t/add_depends.t
index 2d686a17d..d49aa74ce 100755
--- a/t/add_depends.t
+++ b/t/add_depends.t
@@ -8,25 +8,27 @@ BEGIN { use_ok("IkiWiki"); }
$config{srcdir}=$config{destdir}="/dev/null";
IkiWiki::checkconfig();
+$pagesources{"foo$_"}="foo$_.mdwn" for 0..9;
+
# avoids adding an unparseable pagespec
-ok(! add_depends("foo", "foo and (bar"));
-ok(! add_depends("foo", "foo another"));
+ok(! add_depends("foo0", "foo and (bar"));
+ok(! add_depends("foo0", "foo another"));
# simple and not-so-simple dependencies split
-ok(add_depends("foo", "*"));
-ok(add_depends("foo", "bar"));
-ok(add_depends("foo", "BAZ"));
-ok(exists $IkiWiki::depends_simple{foo}{"bar"});
-ok(exists $IkiWiki::depends_simple{foo}{"baz"}); # lowercase
-ok(! exists $IkiWiki::depends_simple{foo}{"*"});
-ok(! exists $IkiWiki::depends{foo}{"bar"});
-ok(! exists $IkiWiki::depends{foo}{"baz"});
+ok(add_depends("foo0", "*"));
+ok(add_depends("foo0", "bar"));
+ok(add_depends("foo0", "BAZ"));
+ok(exists $IkiWiki::depends_simple{foo0}{"bar"});
+ok(exists $IkiWiki::depends_simple{foo0}{"baz"}); # lowercase
+ok(! exists $IkiWiki::depends_simple{foo0}{"*"});
+ok(! exists $IkiWiki::depends{foo0}{"bar"});
+ok(! exists $IkiWiki::depends{foo0}{"baz"});
# default dependencies are content dependencies
-ok($IkiWiki::depends{foo}{"*"} & $IkiWiki::DEPEND_CONTENT);
-ok(! ($IkiWiki::depends{foo}{"*"} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS)));
-ok($IkiWiki::depends_simple{foo}{"bar"} & $IkiWiki::DEPEND_CONTENT);
-ok(! ($IkiWiki::depends_simple{foo}{"bar"} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS)));
+ok($IkiWiki::depends{foo0}{"*"} & $IkiWiki::DEPEND_CONTENT);
+ok(! ($IkiWiki::depends{foo0}{"*"} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS)));
+ok($IkiWiki::depends_simple{foo0}{"bar"} & $IkiWiki::DEPEND_CONTENT);
+ok(! ($IkiWiki::depends_simple{foo0}{"bar"} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS)));
# adding other dep types standalone
ok(add_depends("foo2", "*", presence => 1));
@@ -50,43 +52,47 @@ ok(($IkiWiki::depends_simple{foo2}{"baz"} & $IkiWiki::DEPEND_CONTENT));
ok(add_depends("foo2", "bar", presence => 1)); # had only links before
ok($IkiWiki::depends_simple{foo2}{"bar"} & ($IkiWiki::DEPEND_LINKS | $IkiWiki::DEPEND_PRESENCE));
ok(! ($IkiWiki::depends_simple{foo2}{"bar"} & $IkiWiki::DEPEND_CONTENT));
-ok(add_depends("foo", "bar", links => 1)); # had only content before
-ok($IkiWiki::depends{foo}{"*"} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS));
-ok(! ($IkiWiki::depends{foo}{"*"} & $IkiWiki::DEPEND_PRESENCE));
+ok(add_depends("foo0", "bar", links => 1)); # had only content before
+ok($IkiWiki::depends{foo0}{"*"} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS));
+ok(! ($IkiWiki::depends{foo0}{"*"} & $IkiWiki::DEPEND_PRESENCE));
-# adding a pagespec that requires page metadata should cause a fallback to
-# a content dependency
-foreach my $spec ("* and ! link(bar)", "* or link(bar)", "unknownspec()",
- "title(hi)",
- "* or unknown(yo)", # this one could actually be acceptably be
- # detected to not need a content dep .. in
- # theory!
- ) {
+# Adding a pagespec that requires page metadata should add the influence
+# as an explicit content 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_CONTENT);
- ok(! ($IkiWiki::depends{foo3}{$spec} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS)));
+ 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(add_depends("foo4", $spec, links => 1));
- ok($IkiWiki::depends{foo3}{$spec} & $IkiWiki::DEPEND_CONTENT);
- ok(! ($IkiWiki::depends{foo3}{$spec} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS)));
+ 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);
}
-# a pagespec with backlinks() in it is acceptable for a links dependency,
-# but not a presence dependency
-foreach my $spec ("index or (backlink(index) and !*.png)", "backlink(foo)") {
+# a pagespec with backlinks() will add as an influence the page with the links
+$links{foo0}=[qw{foo5 foo7}];
+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_CONTENT);
- ok(! ($IkiWiki::depends{foo5}{$spec} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS)));
+ 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(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)));
- # combining both ends up with a content+links dependency
+ ok($IkiWiki::depends_simple{foo5}{foo0} == $IkiWiki::DEPEND_CONTENT);
ok(add_depends("foo7", $spec, presence => 1, links => 1));
- ok($IkiWiki::depends{foo7}{$spec} & $IkiWiki::DEPEND_CONTENT);
+ ok($IkiWiki::depends{foo7}{$spec} & $IkiWiki::DEPEND_PRESENCE);
ok($IkiWiki::depends{foo7}{$spec} & $IkiWiki::DEPEND_LINKS);
- ok(! ($IkiWiki::depends{foo7}{$spec} & $IkiWiki::DEPEND_PRESENCE));
+ ok(! ($IkiWiki::depends{foo7}{$spec} & $IkiWiki::DEPEND_CONTENT));
+ ok($IkiWiki::depends_simple{foo7}{foo0} == $IkiWiki::DEPEND_CONTENT);
+ 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);
}
# content is the default if unknown types are entered
-ok(add_depends("foo8", "*", presenCe => 1));
-ok($IkiWiki::depends{foo8}{"*"} & $IkiWiki::DEPEND_CONTENT);
-ok(! ($IkiWiki::depends{foo8}{"*"} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS)));
+ok(add_depends("foo9", "*", presenCe => 1));
+ok($IkiWiki::depends{foo9}{"*"} & $IkiWiki::DEPEND_CONTENT);
+ok(! ($IkiWiki::depends{foo9}{"*"} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS)));