]> sipb.mit.edu Git - ikiwiki.git/blob - doc/todo/tracking_bugs_with_dependencies.mdwn
cd5f5e3728c12cdaf0263581e333fad8c3c7d4cd
[ikiwiki.git] / doc / todo / tracking_bugs_with_dependencies.mdwn
1 I like the idea of [[tips/integrated_issue_tracking_with_ikiwiki]], and I do so on several wikis.  However, as far as I can tell, ikiwiki has no functionality which can represent dependencies between bugs and allow pagespecs to select based on dependencies.  For instance, I can't write a pagespec which selects all bugs with no dependencies on bugs not marked as done.  --[[JoshTriplett]]
2
3 > I started having a think about this.  I'm going to start with the idea that expanding
4 > the pagespec syntax is the way to attack this.  It seems that any pagespec that is going
5 > to represent "all bugs with no dependencies on bugs not marked as done" is going to
6 > need some way to represent "bugs not marked as done" as a collection of pages, and
7 > then represent "bugs which do not link to pages in the previous collection".
8 >
9 > One way to do this would be to introduce variables into the pagespec, along with
10 > universal and/or existential [[!wikipedia Quantification]].  That looks quite complex.
11 >
12 >> I thought about this briefly, and got about that far.. glad you got
13 >> further. :-) --[[Joey]]
14
15 > Another option would be go with a more functional syntax.  The concept here would
16 > be to allow a pagespec to appear in a 'pagespec function' anywhere a page can.  e.g.
17 > I could pass a pagespec to `link()` and that would return true if there is a link to any
18 > page matching the pagespec.  This makes the variables and existential quantification
19 > implicit.  It would allow the example requested above:
20 >
21 >> `bugs/* and !*/Discussion and !link(bugs/* and !*/Discussion and !link(done))`
22 >
23 > Unfortunately, this is also going to make the pagespec parsing more complex because
24 > we now need to parse nested sets of parentheses to know when the nested pagespec
25 > ends, and that isn't a regular language (we can't use regular expression matching for
26 > easy parsing).
27 >
28 >> Also, it may cause ambiguities with page names that contain parens
29 >> (though some such ambigutities already exist with the pagespec syntax).
30 >
31 > One simplification of that would be to introduce some pagespec [[shortcuts]].  We could
32 > then allow pagespec functions to take either pages, or named pagespec shortcuts.  The
33 > pagespec shortcuts would just be listed on a special page, like current [[shortcuts]].
34 > (It would probably be a good idea to require that shortcuts on that page can only refer
35 > to named pagespecs higher up that page than themselves.  That would stop some
36 > looping issues...)  These shortcuts would be used as follows: when trying to match
37 > a page (without globs) you look to see if the page exists.  If it does then you have a
38 > match.  If it doesn't, then you look to see if a similarly named pagespec shortcut
39 > exists.  If it does, then you check that pagespec recursively to see if you have a match.
40 > The ordering requirement on named pagespecs stops infinite recursion.
41 >
42 > Does that seem like a reasonable first approach?
43 >
44 > -- [[Will]]
45
46 >> Having a separate page for the shortcuts feels unwieldly.. perhaps
47 >> instead the shortcut could be defined earlier in the scope of the same
48 >> pagespec that uses it?
49 >> 
50 >> Example: `define(~bugs, bugs/* and !*/Discussion) and define(~openbugs, ~bugs and !link(done)) and ~openbugs and !link(~openbugs)`
51 >>
52 >> Note that I made the "~" explicit, not implicit, so it could be left out. In the case of ambiguity between
53 >> a definition and a page name, the definition would win.
54 >>
55 >> So, equivilant example: `define(bugs, bugs/* and !*/Discussion) and define(openbugs, bugs and !link(done)) and openbugs and !link(openbugs)`
56 >> 
57 >> Re recursion, it is avoided.. but building a pagespec that is O(N^X) where N is the
58 >> number of pages in the wiki is not avoided. Probably need to add DOS prevention.
59 >>  --[[Joey]]
60
61 > One quick further thought.  All the above discussion assumes that 'dependency' is the
62 > same as 'links to', which is not really true.  For example, you'd like to be able to say
63 > "This bug does not depend upon [ [ link to other bug ] ]" and not have a dependency.
64 > Without having different types of links, I don't see how this would be possible.
65 >
66 > -- [[Will]]
67
68 Okie - I've had a quick attempt at this.  Initial patch attached.  This one doesn't quite work.
69 And there is still a lot of debugging stuff in there.
70
71 At the moment I've added a new preprocessor plugin, `definepagespec`, which is like
72 shortcut for pagespecs.  To reference a named pagespec, use `~` like this:
73
74     [ [!definepagespec name="bugs" spec="bugs/* and !*/Discussion"]]
75     [ [!definepagespec name="openbugs" spec="~bugs and !link(done)"]]
76     [ [!definepagespec name="readybugs" spec="~openbugs and !link(~openbugs)"]]
77
78 At the moment the problem is in `match_link()` when we're trying to find a sub-page that
79 matches the appropriate page spec.  There is no good list of pages available to iterate over.
80
81     foreach my $nextpage (keys %IkiWiki::pagesources)
82
83 does not give me a good list of pages.  I found the same thing when I was working on
84 this todo [[todo/Add_a_plugin_to_list_available_pre-processor_commands]].
85
86 > I'm not sure why iterating over `%pagesources` wouldn't work here, it's the same method
87 > used by anything that needs to match a pagespec against all pages..? --[[Joey]]
88
89 Immediately below is a patch for IkiWiki.pm.  Below that is a new plugin `definepagespec `
90 which behaves like `shortcut` for pagespecs.
91
92 ----
93
94 diff --git a/IkiWiki.pm b/IkiWiki.pm
95 index e476521..1d2d48c 100644
96 --- a/IkiWiki.pm
97 +++ b/IkiWiki.pm
98 @@ -14,7 +14,7 @@ use open qw{:utf8 :std};
99  use vars qw{%config %links %oldlinks %pagemtime %pagectime %pagecase
100             %pagestate %renderedfiles %oldrenderedfiles %pagesources
101             %destsources %depends %hooks %forcerebuild $gettext_obj
102 -           %loaded_plugins};
103 +           %loaded_plugins %named_pagespec};
104  
105  use Exporter q{import};
106  our @EXPORT = qw(hook debug error template htmlpage add_depends pagespec_match
107 @@ -22,7 +22,7 @@ our @EXPORT = qw(hook debug error template htmlpage add_depends pagespec_match
108                   displaytime will_render gettext urlto targetpage
109                  add_underlay
110                   %config %links %pagestate %renderedfiles
111 -                 %pagesources %destsources);
112 +                 %pagesources %destsources %named_pagespec);
113  our $VERSION = 2.00; # plugin interface version, next is ikiwiki version
114  our $version='unknown'; # VERSION_AUTOREPLACE done by Makefile, DNE
115  my $installdir=''; # INSTALLDIR_AUTOREPLACE done by Makefile, DNE
116 @@ -1271,7 +1271,7 @@ sub loadindex () { #{{{
117         %oldrenderedfiles=%pagectime=();
118         if (! $config{rebuild}) {
119                 %pagesources=%pagemtime=%oldlinks=%links=%depends=
120 -               %destsources=%renderedfiles=%pagecase=%pagestate=();
121 +               %destsources=%renderedfiles=%pagecase=%pagestate=%named_pagespec=();
122         }
123         my $in;
124         if (! open ($in, "<", "$config{wikistatedir}/indexdb")) {
125 @@ -1729,6 +1729,8 @@ sub match_glob ($$;@) { #{{{
126         
127         my $from=exists $params{location} ? $params{location} : '';
128         
129 +       print "Matching glob $glob \n";
130 +       
131         # relative matching
132         if ($glob =~ m!^\./!) {
133                 $from=~s#/?[^/]+$##;
134 @@ -1736,6 +1738,18 @@ sub match_glob ($$;@) { #{{{
135                 $glob="$from/$glob" if length $from;
136         }
137  
138 +       if (substr($glob, 0, 1) eq '~') {
139 +               my $specname = substr($glob, 1);
140 +               print "Checking for pagespec named $specname \n";
141 +               if (exists $IkiWiki::named_pagespec{$specname}) {
142 +                       my $spec = $IkiWiki::named_pagespec{$specname};
143 +                       return IkiWiki::pagespec_match($page, $spec, %params);
144 +               } else {
145 +                       print "Couldn't find pagespec\n";
146 +                       return IkiWiki::FailReason->new("Page spec $specname referenced on page $page does not exist");
147 +               }
148 +       }
149 +
150         my $regexp=IkiWiki::glob2re($glob);
151         if ($page=~/^$regexp$/i) {
152                 if (! IkiWiki::isinternal($page) || $params{internal}) {
153 @@ -1756,11 +1770,36 @@ sub match_internal ($$;@) { #{{{
154  
155  sub match_link ($$;@) { #{{{
156         my $page=shift;
157 -       my $link=lc(shift);
158 +       my $fulllink=shift;
159 +       my $link=lc($fulllink);
160         my %params=@_;
161  
162 +       print "Matching link $fulllink \n";
163 +       
164         my $from=exists $params{location} ? $params{location} : '';
165  
166 +       if (substr($fulllink, 0, 1) eq '~') {
167 +               my $specname = substr($fulllink, 1);
168 +               print "Checking link pagespec $specname \n";
169 +               if (exists $IkiWiki::named_pagespec{$specname}) {
170 +                       my $spec = $IkiWiki::named_pagespec{$specname};
171 +                       
172 +                       print "Checking all pages against $spec\n";
173 +                       
174 +                       foreach my $nextpage (keys %IkiWiki::pagesources) {
175 +                               print "Checking $nextpage against $spec\n";
176 +                               if (pagespec_match($nextpage, $spec, %params) && IkiWiki::PageSpec::match_link($page, $nextpage, %params)) {
177 +                                       return IkiWiki::SuccessReason->new("$page links to page $nextpage matching $link")
178 +                               }
179 +                       }
180 +                       
181 +                       return IkiWiki::FailReason->new("$page has no links to any pages that match $spec");
182 +               } else {
183 +                       print "Pagespec $specname not found\n";
184 +                       return IkiWiki::FailReason->new("$page cannot link to nonexistent spec name $specname");
185 +               }
186 +       }
187 +
188         # relative matching
189         if ($link =~ m!^\.! && defined $from) {
190                 $from=~s#/?[^/]+$##;
191
192 ----
193
194 #!/usr/bin/perl
195 package IkiWiki::Plugin::definepagespec;
196
197 use warnings;
198 use strict;
199 use IkiWiki 2.00;
200
201 sub import { #{{{
202         hook(type => "getsetup", id => "definepagespec", call => \&getsetup);
203         hook(type => "refresh", id => "definepagespec", call => \&refresh);
204         hook(type => "preprocess", id => "definepagespec", call => \&preprocess);
205 } #}}}
206
207 sub getsetup () { #{{{
208         return
209                 plugin => {
210                         safe => 1,
211                         rebuild => undef,
212                 },
213 } #}}}
214
215 sub refresh () { #{{{
216         # Preprocess the shortcuts page to get all the available shortcuts
217         # defined before other pages are rendered.
218         my $srcfile=srcfile("pagespecs.mdwn", 1);
219         if (! defined $srcfile) {
220                 error(gettext("definepagespec plugin will not work without a pagespecs.mdwn"));
221         }
222         IkiWiki::preprocess("pagespecs", "pagespecs", readfile($srcfile));
223 } # }}}
224
225 sub preprocess (@) { #{{{
226         my %params=@_;
227
228         if (! defined $params{name} || ! defined $params{spec}) {
229                 error gettext("missing name or spec parameter");
230         }
231
232         $IkiWiki::named_pagespec{$params{name}} = $params{spec};
233
234         #translators: This is used to display what shortcuts are defined.
235         #translators: First parameter is the name of the shortcut, the second
236         #translators: is an URL.
237         return sprintf(gettext("pagespec %s refers to <i>%s</i>"), $params{name}, $params{spec});
238 } # }}}
239
240 1