]> sipb.mit.edu Git - ikiwiki.git/blob - doc/bugs/Monotone_rcs_support.mdwn
web commit by http://harningt.myopenid.com/: IRC discussion about usage semantics
[ikiwiki.git] / doc / bugs / Monotone_rcs_support.mdwn
1 #Ikiwiki plugin for the Monotone revision control system.
2
3 I've just made a patch to the ikiwiki code that allows it to use the [[rcs/Monotone]] revision control system.  It is available at:
4
5 <http://www.cse.unsw.edu.au/~willu/monotone-ikiwiki.diff>
6
7 At the moment it is basically complete.  At present rcs_notify() is implemeted but untested, the rest is implemented and tested.
8
9 The current version of the patch handles conflicts through the web interface.  It is still not perfect as it will break if there is a rename that conflicts with a web change (but so will the other Rcs plugins I think).  It also commits a revision with conflict markers if there is a conflict requiring such markers... ick.
10
11 Note: This patch requires a rather recent Monotone perl module (18 August 2007 or later).  It is available from the monotone repository here: <http://viewmtn.angrygoats.net/branch/changes/net.venge.monotone>.
12
13 > The setup instructions to add 40 lines of code to monotonerc is pretty frightning stuff.
14 > Is there some way this can be automated? --[[Joey]]
15
16 >> I've committed a bunch of this to monotone so that in future it could be removed.
17 >> I've also just fixed this so it is in a separate, automagically generated, rc file.
18
19 >>> Fair enough. Didn't realize you were a monotone committer. :-)
20
21 >>>> I am, but still a little newish.  Feedback is good.  In particular, this is my first major bit of PERL.
22
23 > Having rcs_commit return a warning message when there's an unresolved conflict
24 > isn't right; that message will populate the page edit box. You might want
25 > to use the error() function here?
26
27 >> It should never reach that case, so I have changed that to error.
28
29 > There'an incomplete comment ending with "note, this relies on the fact that"
30
31 >> erg... sorry, fixed.
32
33 [[tag patch]]
34
35 >> I've [[accepted|done]] this patch, thank you! 
36
37 >>> Thanks for committing it.  I hate keeping my own diffs. :)
38
39 >> I did make a few changes. Please review, and make sure it still works
40 >> (a test case like we have for some of the other RCSes would be nice..)
41
42 >>> Tested.  It still works at least as well as it did.  I'll try to get to a test case soon.
43 >>> In checking the source I noticed a few bogus comments I left in when editing,
44 >>> and a bug in page adding.
45 >>> Here is a small patch for them:
46
47 >>>> applied
48
49 Here is another patch.  It fixes a FIXME you added.  I was using $file within backticks because
50 I was getting an error trying to do it right.  I've figured out the error, and now do it right.  This
51 should also speed things up (very slightly)
52
53 > applied
54
55 >> BTW, will all the monotone output parsing work if LANG != C?
56
57 >>> It should (he says crossing fingers).
58 >>> In the places where I do any complex parsing I'm using a special
59 >>> version of the mtn commands designed for scripting.  They have a
60 >>> stable, easy to parse, output that doesn't get translated (I think).
61
62 >> Do monotone post-commit hooks actually use REV?
63
64 >>> Monotone post-commit hooks are written in Lua and can do
65 >>> what they please.  Setting the REV environment var before
66 >>> calling Ikiwiki seems reasonable, but I've not written the
67 >>> Lua hook.
68
69 >>>> So the rcs_notify support is not just untested, but can't work
70 >>>> at all w/o further development.
71
72 I've just done this further development...  The following patch adds support for diffurls.
73 I've also partially tested the commit message support.  I was unable to get Ikiwiki to send
74 change emails at all (cgi or otherwise), so I tested by adding warn() calls.  There were a
75 few things that needed to be fixed.  Support is much closer now (including a simple default
76 monotone lua hook).
77
78 When I stick this diff inline into the page, I have to indent it by four spaces, and that's fine.
79 But markdown seems to still be interpreting parts of it (e.g. the diff url) in strange ways.  I
80 think it is the square brackets.
81
82     Index: IkiWiki/Rcs/monotone.pm
83     ===================================================================
84     --- IkiWiki/Rcs/monotone.pm (revision 4252)
85     +++ IkiWiki/Rcs/monotone.pm (working copy)
86     @@ -186,8 +186,9 @@
87         check_config();
88      
89         if (defined($config{mtnsync}) && $config{mtnsync}) {
90     +           check_mergerc();
91                 if (system("mtn", "--root=$config{mtnrootdir}", "sync",
92     -                      "--quiet", "--ticker=none", 
93     +                      "--quiet", "--ticker=none", "--rcfile", $config{mtnmergerc},
94                            "--key", $config{mtnkey}) != 0) {
95                         debug("monotone sync failed before update");
96                 }
97     @@ -342,10 +343,10 @@
98                 return $conflict;
99         }
100         if (defined($config{mtnsync}) && $config{mtnsync}) {
101     -           if (system("mtn", "--root=$config{mtnrootdir}", "sync",
102     +           if (system("mtn", "--root=$config{mtnrootdir}", "push",
103                            "--quiet", "--ticker=none", "--key",
104                            $config{mtnkey}) != 0) {
105     -                   debug("monotone sync failed");
106     +                   debug("monotone push failed");
107                 }
108         }
109      
110     @@ -431,10 +432,28 @@
111                 my @changed_files = get_changed_files($automator, $rev);
112                 my $file;
113                 
114     +           my ($out, $err) = $automator->call("parents", $rev);
115     +           my @parents = ($out =~ m/^($sha1_pattern)$/);
116     +           my $parent = $parents[0];
117     +           
118                 foreach $file (@changed_files) {
119     -                   push @pages, {
120     -                           page => pagename($file),
121     -                   } if length $file;
122     +                   if (length($file)) {
123     +                           if (defined $config{diffurl} and (@parents == 1)) {
124     +                                   my $diffurl=$config{diffurl};
125     +                                   $diffurl=~s/\[\[r1\]\]/$parent/g;
126     +                                   $diffurl=~s/\[\[r2\]\]/$rev/g;
127     +                                   $diffurl=~s/\[\[file\]\]/$file/g;
128     +                                   push @pages, {
129     +                                           page => pagename($file),
130     +                                           diffurl => $diffurl,
131     +                                   };
132     +                           }
133     +                           else {
134     +                                   push @pages, {
135     +                                           page => pagename($file),
136     +                                   };
137     +                           }
138     +                   }
139                 }
140                 
141                 push @ret, {
142     @@ -487,6 +506,18 @@
143                 
144         my @changed_pages = get_changed_files($automator, $rev);
145         
146     +   my ($out, $err) = $automator->call("parents", $rev);
147     +   my @parents = ($out =~ m/^($sha1_pattern)$/);
148     +   my $parent = $parents[0];
149     +   
150     +   my $diff;
151     +   
152     +   if (@parents == 1) {
153     +           $automator->setOpts("r", $parent, "r", $rev);
154     +           ($out, $err) = $automator->call("content_diff");
155     +           $diff = $out;
156     +   }
157     +   
158         $automator->close();
159         
160         require IkiWiki::UserInfo;
161     @@ -495,7 +526,7 @@
162                         return $message;
163                 },
164                 sub {
165     -                   `mtn --root=$config{mtnrootdir} au content_diff -r $rev`;
166     +                   return $diff;
167                 },
168                 $user, @changed_pages);
169      } #}}}
170     @@ -604,4 +635,9 @@
171                    return true
172               end
173         }
174     +   function note_netsync_revision_received(new_id, revision, certs, session_id)
175     +       if (program_exists_in_path("ikiwiki-netsync-hook")) then
176     +           execute("ikiwiki-netsync-hook", new_id)
177     +       end
178     +   end
179      EOF
180     Index: IkiWiki/Wrapper.pm
181     ===================================================================
182     --- IkiWiki/Wrapper.pm      (revision 4252)
183     +++ IkiWiki/Wrapper.pm      (working copy)
184     @@ -46,6 +46,16 @@
185                 addenv("REV", s);
186      EOF
187         }
188     +   if ($config{rcs} eq "monotone" && $config{notify}) {
189     +           # Support running directly as hooks/post-commit by passing
190     +           # $1 in REV in the environment.
191     +           $envsave.=<<"EOF"
192     +   if (argc == 2)
193     +           addenv("REV", argv[1]);
194     +   else if ((s=getenv("REV")))
195     +           addenv("REV", s);
196     +EOF
197     +   }
198         if ($config{rcs} eq "tla" && $config{notify}) {
199                 $envsave.=<<"EOF"
200         if ((s=getenv("ARCH_VERSION")))
201     Index: doc/rcs/monotone.mdwn
202     ===================================================================
203     --- doc/rcs/monotone.mdwn   (revision 4252)
204     +++ doc/rcs/monotone.mdwn   (working copy)
205     @@ -1,16 +1,13 @@
206     -[monotone](http://monotone.ca/) is a distributed revision control system.
207     -Ikiwiki supports storing a wiki in Monotone and editing it using the [[cgi]] interface.
208     +[Monotone](http://monotone.ca/) is a distributed revision control system.
209     +Ikiwiki supports storing a wiki in a Monotone repository and editing it using the [[cgi]] interface.
210      It will use the Monotone logs to generate the [[RecentChanges]] page.
211      
212     -The monotone support requires the Monotone perl module (from the contrib/ directory
213     -in the monotone source) to be installed. In particular, it needs version 0.03 or higher of that module.
214     +The monotone support in Ikiwiki requires the Monotone perl module to be installed
215     +(available from the contrib/ directory in the monotone source).
216     +In particular, it needs version 0.03 or higher of that module.
217      The module is available from the monotone source repository at:
218      <http://viewmtn.angrygoats.net/branch/changes/net.venge.monotone>
219      
220     -Monotone support works, but there are still a few minor missing bits (listed here so they are not forgotten):
221     +At present the [[post-commit]] hook support is implemented but only partially tested.
222      
223     -* At the moment there are no links to display diffs between revisions.  It shouldn't be hard to add links to a [ViewMTN](http://grahame.angrygoats.net/moinmoin/ViewMTN) instance, but it hasn't been done yet.
224     -* The [[post-commit]] hook support, so that Ikiwiki sends change notifications when people commit using Monotone rather than the web interface, is partially implemented and untested.
225     -* Documentation (this page) could be improved.
226     -
227      There is also a mismatch between the way Ikiwiki handles conflicts and the way Monotone handles conflicts.  At present, if there is a conflict, then Ikiwiki will commit a revision with conflict markers before presenting it to the user.  This is ugly, but there is no clean way to fix it at present.
228     Index: doc/ikiwiki.setup
229     ===================================================================
230     --- doc/ikiwiki.setup       (revision 4252)
231     +++ doc/ikiwiki.setup       (working copy)
232     @@ -46,6 +46,8 @@
233         # Monotone stuff
234         #rcs => "monotone",
235         #mtnkey => "web\@machine.company.com",
236     +   #historyurl => "http://viewmtn.company.com/",
237     +   #diffurl => "http://viewmtn.company.com/revision/diff/[[r1]]/with/[[r2]]/[[file]]",
238         # Set if you want the wiki to sync on update and commit.
239         #mtnsync => 0,
240         # The path to your workspace (defaults to the srcdir itself)
241     @@ -88,6 +90,16 @@
242                 #       # Enable mail notifications of commits.
243                 #       notify => 1,
244                 #},
245     +           #{
246     +           #       # The monotone netsync revision received wrapper.
247     +           #       # Note that you also need to install a lua
248     +           #       # hook into monotone to make this work
249     +           #       # see: http://ikiwiki.info/rcs/monotone/
250     +           #       wrapper => "/usr/local/bin/ikiwiki-netsync-hook",
251     +           #       wrappermode => "04755",
252     +           #       # Enable mail notifications of commits.
253     +           #       notify => 1,
254     +           #},
255         ],
256      
257         # Generate rss feeds for blogs?
258