1 A few bits about the RCS backends
7 ``web-edit'' means that a page is edited by using the web (CGI) interface
8 as opposed to using a editor and the RCS interface.
13 Subversion was the first RCS to be supported by ikiwiki.
15 ### How does it work internally?
19 RCS commits from the outside are installed into M.
21 There is a working copy of M (a checkout of M): W.
23 HTML is generated from W. rcs_update() will update from M to W.
25 CGI operates on W. rcs_commit() will commit from W to M.
27 For all the gory details of how ikiwiki handles this behind the scenes,
28 see [[commit-internals]].
30 You browse and web-edit the wiki on W.
32 W "belongs" to ikiwiki and should not be edited directly.
35 ## [darcs](http://darcs.net/) (not yet included)
37 Support for using darcs as a backend is being worked on by [Thomas
38 Schwinge](mailto:tschwinge@gnu.org), although development is on hold curretly.
39 There is a patch in [[todo/darcs]].
41 ### How will it work internally?
43 ``Master'' repository R1.
45 RCS commits from the outside are installed into R1.
47 HTML is generated from R1. HTML is automatically generated (by using a
48 ``post-hook'') each time a new change is installed into R1. It follows
49 that rcs_update() is not needed.
51 There is a working copy of R1: R2.
53 CGI operates on R2. rcs_commit() will push from R2 to R1.
55 You browse the wiki on R1 and web-edit it on R2. This means for example
56 that R2 needs to be updated from R1 if you are going to web-edit a page,
57 as the user otherwise might be irritated otherwise...
59 How do changes get from R1 to R2? Currently only internally in
60 rcs\_commit(). Is rcs\_prepedit() suitable?
62 It follows that the HTML rendering and the CGI handling can be completely
63 separated parts in ikiwiki.
65 What repository should [[RecentChanges]] and History work on? R1?
67 #### Rationale for doing it differently than in the Subversion case
69 darcs is a distributed RCS, which means that every checkout of a
70 repository is equal to the repository it was checked-out from. There is
73 R1 is nevertheless called the master repository. It's used for
74 collecting all the changes and publishing them: on the one hand via the
75 rendered HTML and on the other via the standard darcs RCS interface.
77 R2, the repository the CGI operates on, is just a checkout of R1 and
78 doesn't really differ from the other checkouts that people will branch
83 #### Another possible approach
85 Here's what I (tuomov) think, would be a “cleaner” approach:
87 1. Upon starting to edit, Ikiwiki gets a copy of the page, and `darcs changes --context`.
88 This context _and_ the present version of the page are stored in as the “version” of the
89 page in a hidden control of the HTML.
90 Thus the HTML includes all that is needed to generate a patch wrt. to the state of the
91 repository at the time the edit was started. This is of course all that darcs needs.
92 2. Once the user is done with editing, _Ikiwiki generates a patch bundle_ for darcs.
93 This should be easy with existing `Text::Diff` or somesuch modules, as the Web edits
94 only concern single files. The reason why the old version of the page is stored in
95 the HTML (possibly compressed) is that the diff can be generated.
96 3. Now this patch bundle is applied with `darcs apply`, or sent by email for moderation…
97 there are many possibilities.
99 This approach avoids some of the problems of concurrent edits that the previous one may have,
100 although there may be conflicts, which may or may not propagate to the displayed web page.
101 (Unfortunately there is not an option to `darcs apply` to generate some sort of ‘confliction resolution
102 bundle’.) Also, only one repository is needed, as it is never directly modified
105 This approach might be applicable to other distributed VCSs as well, although they're not as oriented
106 towards transmitting changes with standalone patch bundles (often by email) as darcs is.
108 > The mercurial plugin seems to just use one repo and edit it directly - is
109 > there some reason that's okay there but not for darcs? I agree with tuomov
110 > that having just the one repo would be preferable; the point of a dvcs is
111 > that there's no difference between one repo and another. I've got a
112 > darcs.pm based on mercurial.pm, that's almost usable... --bma
114 >> IMHO it comes down to whatever works well for a given RCS. Seems like
115 >> the darcs approach _could_ be done with most any distributed system, but
116 >> it might be overkill for some (or all?) While there is the incomplete darcs
117 >> plugin in [[todo/darcs]], if you submit one that's complete, I will
118 >> probably accept it into ikiwiki.. --[[Joey]]
122 Regarding the Git support, Recai says:
124 I have been testing it for the past few days and it seems satisfactory. I
125 haven't observed any race condition regarding the concurrent blog commits
126 and it handles merge conflicts gracefully as far as I can see.
128 (After about a year, git support is nearly as solid as subversion support --[[Joey]])
130 As you may notice from the patch size, GIT support is not so trivial to
131 implement (for me, at least). It has some drawbacks (especially wrt merge
132 which was the hard part). GIT doesn't have a similar functionality like
133 'svn merge -rOLD:NEW FILE' (please see the relevant comment in `_merge_past`
134 for more details), so I had to invent an ugly hack just for the purpose.
136 > I was looking at this, and WRT the problem of uncommitted local changes,
137 > it seems to me you could just git-stash them now that git-stash exists.
138 > I think it didn't when you first added the git support.. --[[Joey]]
141 >> Yes, git-stash had not existed before. What about sth like below? It
142 >> seems to work (I haven't given much thought on the specific implementation
143 details). --[[roktas]]
145 >> # create test files
155 >> sed -e 's/2/2ME/' page >page.me # my changes
163 >> sed -e 's/5/5SOMEONE/' page >page.someone # someone's changes
172 >> # create a test repository
178 >> git commit -m init
180 >> # save the current HEAD
181 >> ME=$(git rev-list HEAD -- page)
182 >> $EDITOR page # assume that I'm starting to edit page via web
184 >> # simulates someone's concurrent commit
185 >> cp ../page.someone page
186 >> git commit -m someone -- page
188 >> # My editing session ended, the resulting content is in page.me
189 >> cp ../page.me page
198 >> # let's start to save my uncommitted changes
200 >> git stash save "changes by me"
201 >> # we've reached a clean state
210 >> # roll-back to the $ME state
211 >> git reset --soft $ME
212 >> # now, the file is marked as modified
213 >> git stash save "changes by someone"
215 >> # now, we're at the $ME state
224 >> stash@{0}: On master: changes by someone
225 >> stash@{1}: On master: changes by me
227 >> # first apply my changes
228 >> git stash apply stash@{1}
237 >> git commit -m me -- page
239 >> # apply someone's changes
240 >> git stash apply stash@{0}
249 >> git commit -m me+someone -- page
251 By design, Git backend uses a "master-clone" repository pair approach in contrast
252 to the single repository approach (here, _clone_ may be considered as the working
253 copy of a fictious web user). Even though a single repository implementation is
254 possible, it somewhat increases the code complexity of backend (I couldn't figure
255 out a uniform method which doesn't depend on the prefered repository model, yet).
256 By exploiting the fact that the master repo and _web user_'s repo (`srcdir`) are all
257 on the same local machine, I suggest to create the latter with the "`git clone -l -s`"
258 command to save disk space.
260 Note that, as a rule of thumb, you should always put the rcs wrapper (`post-update`)
261 into the master repository (`.git/hooks/`) as can be noticed in the Git wrappers of
262 the sample [[ikiwiki.setup]].
264 Here is how a web edit works with ikiwiki and git:
266 * ikiwiki cgi modifies the page source in the clone
267 * git-commit in the clone
268 * git push origin master, pushes the commit from the clone to the master repo
269 * the master repo's post-update hook notices this update, and runs ikiwiki
270 * ikiwiki notices the modifies page source, and compiles it
272 Here is a how a commit from a remote repository works:
274 * git-commit in the remote repository
275 * git-push, pushes the commit to the master repo on the server
276 * the master repo's post-update hook notices this update, and runs ikiwiki
277 * ikiwiki notices the modifies page source, and compiles it
281 The Mercurial backend is still in a early phase, so it may not be mature
282 enough, but it should be simple to understand and use.
284 As Mercurial is a distributed RCS, it lacks the distinction between
285 repository and working copy (every wc is a repo).
287 This means that the Mercurial backend uses directly the repository as
288 working copy (the master M and the working copy W described in the svn
289 example are the same thing).
291 You only need to specify 'srcdir' (the repository M) and 'destdir' (where
292 the HTML will be generated).
296 RCS commit from the outside are installed into M.
298 M is directly used as working copy (M is also W).
300 HTML is generated from the working copy in M. rcs_update() will update
301 to the last committed revision in M (the same as 'hg update').
302 If you use an 'update' hook you can generate automatically the HTML
303 in the destination directory each time 'hg update' is called.
305 CGI operates on M. rcs_commit() will commit directly in M.
307 If you have any question or suggestion about the Mercurial backend
308 please refer to [Emanuele](http://nerd.ocracy.org/em/)
314 There is a patch that needs a bit of work linked to from [[todo/rcs]].
318 In normal use, monotone has a local database as well as a workspace/working copy.
319 In ikiwiki terms, the local database takes the role of the master repository, and
320 the srcdir is the workspace. As all monotone workspaces point to a default
321 database, there is no need to tell ikiwiki explicitly about the "master" database. It
324 The backend currently supports normal committing and getting the history of the page.
325 To understand the parallel commit approach, you need to understand monotone's
326 approach to conflicts:
328 Monotone allows multiple micro-branches in the database. There is a command,
329 `mtn merge`, that takes the heads of all these branches and merges them back together
330 (turning the tree of branches into a dag). Conflicts in monotone (at time of writing)
331 need to be resolved interactively during this merge process.
332 It is important to note that having multiple heads is not an error condition in a
333 monotone database. This condition will occur in normal use. In this case
334 'update' will choose a head if it can, or complain and tell the user to merge.
336 For the ikiwiki plugin, the monotone ikiwiki plugin borrows some ideas from the svn ikiwiki plugin.
337 On prepedit() we record the revision that this change is based on (I'll refer to this as the prepedit revision). When the web user
338 saves the page, we check if that is still the current revision. If it is, then we commit.
339 If it isn't then we check to see if there were any changes by anyone else to the file
340 we're editing while we've been editing (a diff bewteen the prepedit revision and the current rev).
341 If there were no changes to the file we're editing then we commit as normal.
343 It is only if there have been parallel changes to the file we're trying to commit that
344 things get hairy. In this case the current approach is to
345 commit the web changes as a branch from the prepedit revision. This
346 will leave the repository with multiple heads. At this point, all data is saved.
347 The system then tries to merge the heads with a merger that will fail if it cannot
348 resolve the conflict. If the merge succeeds then everything is ok.
350 If that merge failed then there are conflicts. In this case, the current code calls
351 merge again with a merger that inserts conflict markers. It commits this new
352 revision with conflict markers to the repository. It then returns the text to the
353 user for cleanup. This is less neat than it could be, in that a conflict marked
354 revision gets committed to the repository.