rework dependency types code

Simplify, change default content depends number to 1,
change interface to make more sense.
master
Joey Hess 2009-10-04 20:30:21 -04:00
parent b4c8cc9072
commit be032a7b87
11 changed files with 54 additions and 58 deletions

View File

@ -29,8 +29,8 @@ our $version='unknown'; # VERSION_AUTOREPLACE done by Makefile, DNE
our $installdir='/usr'; # INSTALLDIR_AUTOREPLACE done by Makefile, DNE
# Page dependency types.
our $DEPEND_EXISTS=1;
our $DEPEND_CONTENT=2;
our $DEPEND_CONTENT=1;
our $DEPEND_PRESENCE=2;
# Optimisation.
use Memoize;
@ -1540,13 +1540,13 @@ sub loadindex () {
if (exists $d->{dependslist}) {
# old format
$depends{$page}={
map { $_ => $DEPEND_CONTENT | $DEPEND_EXISTS }
map { $_ => $DEPEND_CONTENT }
@{$d->{dependslist}}
};
}
elsif (exists $d->{depends} && ! ref $d->{depends}) {
# old format
$depends{$page}={$d->{depends} => $DEPEND_CONTENT | $DEPEND_EXISTS};
$depends{$page}={$d->{depends} => $DEPEND_CONTENT };
}
elsif (exists $d->{depends}) {
$depends{$page}=$d->{depends};
@ -1771,16 +1771,23 @@ 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=$DEPEND_CONTENT | $DEPEND_EXISTS;
my $deptype=$DEPEND_CONTENT;
if (@_) {
my %params=@_;
if (defined $params{content} && $params{content} == 0 &&
($simple || pagespec_contentless($pagespec))) {
$deptype=$deptype & ~$DEPEND_CONTENT;
# Is the pagespec limited to terms that will continue
# to match pages as long as those pages exist?
my $limited=1;
while ($limited && $pagespec=~m/(\w+)\([^\)]*\)/g) {
$limited = $1 =~ /^(glob|internal|creation_month|creation_day|creation_year|created_before|created_after)$/;
}
$deptype=$deptype & ~$DEPEND_CONTENT & $DEPEND_PRESENCE
if $params{presence} && $limited;
}
if ($simple) {
@ -1976,18 +1983,6 @@ sub pagespec_valid ($) {
return ! $@;
}
sub pagespec_contentless ($) {
my $spec=shift;
while ($spec=~m{
(\w+)\([^\)]*\) # only match pagespec functions
}igx) {
return 0 unless $1=~/^(glob|internal|creation_month|creation_day|creation_year|created_before|created_after)$/;
}
return 1;
}
sub glob2re ($) {
my $re=quotemeta(shift);
$re=~s/\\\*/.*/g;

View File

@ -105,21 +105,21 @@ sub format_month (@) {
linktext => " $monthname ");
}
add_depends($params{page}, "$archivebase/$year/".sprintf("%02d", $month),
content => 0);
presence => 1);
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),
content => 0);
presence => 1);
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),
content => 0);
presence => 1);
# Start producing the month calendar
$calendar=<<EOF;
@ -212,11 +212,11 @@ EOF
# Add dependencies to update the calendar whenever pages
# matching the pagespec are added or removed.
add_depends($params{page}, $params{pages}, content => 0);
add_depends($params{page}, $params{pages}, presence => 1);
# Explicitly add all currently linked pages as dependencies, so
# that if they are removed, the calendar will be sure to be updated.
foreach my $p (@list) {
add_depends($params{page}, $p, content => 0);
add_depends($params{page}, $p, presence => 1);
}
return $calendar;
@ -249,19 +249,19 @@ sub format_year (@) {
"$archivebase/$year",
linktext => "$year");
}
add_depends($params{page}, "$archivebase/$year", content => 0);
add_depends($params{page}, "$archivebase/$year", presence => 1);
if (exists $cache{$pagespec}{"$pyear"}) {
$purl = htmllink($params{page}, $params{destpage},
"$archivebase/$pyear",
linktext => "\&larr;");
}
add_depends($params{page}, "$archivebase/$pyear", content => 0);
add_depends($params{page}, "$archivebase/$pyear", presence => 1);
if (exists $cache{$pagespec}{"$nyear"}) {
$nurl = htmllink($params{page}, $params{destpage},
"$archivebase/$nyear",
linktext => "\&rarr;");
}
add_depends($params{page}, "$archivebase/$nyear", content => 0);
add_depends($params{page}, "$archivebase/$nyear", presence => 1);
# Start producing the year calendar
$calendar=<<EOF;
@ -313,7 +313,7 @@ EOF
else {
$calendar.=qq{\t<td class="$tag">$monthabbr</td>\n};
}
add_depends($params{page}, "$archivebase/$year/$mtag", content => 0);
add_depends($params{page}, "$archivebase/$year/$mtag", presence => 1);
$calendar.=qq{\t</tr>\n} if ($month % $params{months_per_row} == 0);
}

View File

@ -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, content => 0);
add_depends($params{page}, $link, presence => 1);
return sprintf(gettext("edittemplate %s registered for %s"),
htmllink($params{page}, $params{destpage}, $link),
$params{match});

View File

@ -84,7 +84,7 @@ sub preprocess (@) {
foreach my $plugin (@pluginlist) {
$result .= '<li class="listdirectives">';
my $link=linkpage($config{directive_description_dir}."/".$plugin);
add_depends($params{page}, $link, content => 0);
add_depends($params{page}, $link, presence => 1);
$result .= htmllink($params{page}, $params{destpage}, $link);
$result .= '</li>';
}

View File

@ -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;

View File

@ -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 "*") {

View File

@ -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(

View File

@ -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;

View File

@ -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) {

View File

@ -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.
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:
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.
* `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($$;@)`

View File

@ -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;