]> sipb.mit.edu Git - ikiwiki.git/commitdiff
rework dependency types code
authorJoey Hess <joey@gnu.kitenet.net>
Mon, 5 Oct 2009 00:30:21 +0000 (20:30 -0400)
committerJoey Hess <joey@gnu.kitenet.net>
Mon, 5 Oct 2009 00:30:21 +0000 (20:30 -0400)
Simplify, change default content depends number to 1,
change interface to make more sense.

IkiWiki.pm
IkiWiki/Plugin/calendar.pm
IkiWiki/Plugin/edittemplate.pm
IkiWiki/Plugin/listdirectives.pm
IkiWiki/Plugin/meta.pm
IkiWiki/Plugin/pagecount.pm
IkiWiki/Plugin/postsparkline.pm
IkiWiki/Plugin/progress.pm
IkiWiki/Render.pm
doc/plugins/write.mdwn
ikiwiki-transition

index 5e5dc739d2696cce58374c2717b453d104521f11..c1d07531ee3488ba15f317ca84045adcd1c46d5d 100644 (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;
index a5cc208821691d6574d77a985b09673b0fd7f70a..a1117992a865ed3a5cd5a7a8ded409d3b8ace33e 100644 (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);
        }
index 89d45072540bb78fcf40eb9a2171138bcfb70fb0..2dd1dbe682c2567e4bf879e0708e0ea9e2fcb8c0 100644 (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});
index 96150f986dabd8c1e25b0fd708b18a9d44e5e6fd..4023ed7d75fd4b2582b7fe00265a5ac6a449619c 100644 (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>';
        }
index eef3013a0caf7a1f9008772b7c5ef46ee27ce20b..9b041a748c35590820f89f17a65b6e183dbcf59c 100644 (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;
index 17eda06181ac19fe00ee2de2b2f52fb336980d49..80561350b5fe44d7d282fb5fac6b5c9ac8e295ea 100644 (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 "*") {
index 694d3957562e2d69d017a16470aa08bd028f62ce..3205958d40dcb5f8b0a510b58d14fba95423c1ff 100644 (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(
index 3b664f4cb29ecc4df553db0cf6722de7d00ce585..26c537a84022ae51001beb9be86db90b1da25e0a 100644 (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;
index 3fc750925defe4cd67c26a0a053a73cee0eb4827..cf0c3fe0822a8d9ee0c7d47076c35d25e315baff 100644 (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) {
index c244c1f2fd68a92eb325d3b209594b3b35f85768..73db6f12abfc5432d132a1a77ba2023b05ee79b9 100644 (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.
-
-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($$;@)`
 
index c50a748e87410da8c40f6e905f07d87db059033f..1bebb1176d99569341a6735e83c4cb51c14e1ffc 100755 (executable)
@@ -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;