1 Here's Thomas Schwinge unfinished darcs support for ikiwiki.
3 (Finishing this has been suggested as a [[soc]] project.)
5 > I haven't been working on this for months and also won't in the near
6 > future. Feel free to use what I have done so
7 > far and bring it into an usable state! Also, feel free to contact me
8 > if there are questions.
10 -- [Thomas Schwinge](mailto:tschwinge@gnu.org)
12 [[toggle text="show"]]
14 # Support for the darcs rcs, <URL:http://darcs.net/>.
15 # Copyright (C) 2006 Thomas Schwinge <tschwinge@gnu.org>
17 # This program is free software; you can redistribute it and/or modify it
18 # under the terms of the GNU General Public License as published by the
19 # Free Software Foundation; either version 2 of the License, or (at your
20 # option) any later version.
22 # This program is distributed in the hope that it will be useful, but
23 # WITHOUT ANY WARRANTY; without even the implied warranty of
24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 # General Public License for more details.
27 # You should have received a copy of the GNU General Public License along
28 # with this program; if not, write to the Free Software Foundation, Inc.,
29 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
32 # We're guaranteed to be the only instance of ikiwiki running at a given
33 # time. It is essential that only ikiwiki is working on a particular
34 # repository. That means one instance of ikiwiki and it also means that
35 # you must not `darcs push' into this repository, as this might create
36 # race conditions, as I understand it.
46 # Which darcs executable to use.
47 my $darcs = ($ENV{DARCS} or 'darcs');
52 sub darcs_info ($$$) {
55 my $file = shift; # Relative to the repodir.
57 my $child = open(DARCS_CHANGES, "-|");
59 exec($darcs, 'changes', '--repo=' . $repodir, '--xml-output', $file) or
60 error('failed to run `darcs changes\'');
63 # Brute force for now. :-/
64 while (<DARCS_CHANGES>) {
65 last if /^<\/created_as>$/;
67 ($_) = <DARCS_CHANGES> =~ /$field=\'([^\']+)/;
68 $field eq 'hash' and s/\.gz//; # Strip away the `.gz' from `hash'es.
70 close(DARCS_CHANGES) or error('`darcs changes\' exited ' . $?);
82 sub rcs_prepedit ($) {
83 # Prepares to edit a file under revision control. Returns a token that
84 # must be passed to rcs_commit() when the file is to be commited. For us,
85 # this token the hash value of the latest patch that modifies the file,
86 # i.e. something like its current revision. If the file is not yet added
87 # to the repository, we return TODO: the empty string.
89 my $file = shift; # Relative to the repodir.
91 my $hash = darcs_info('hash', $config{srcdir}, $file);
92 return defined $hash ? $hash : "";
95 sub rcs_commit ($$$) {
96 # Commit the page. Returns `undef' on success and a version of the page
97 # with conflict markers on failure.
99 my $file = shift; # Relative to the repodir.
101 my $rcstoken = shift;
103 # Compute if the ``revision'' of $file changed.
104 my $changed = darcs_info('hash', $config{srcdir}, $file) ne $rcstoken;
106 # Yes, the following is a bit convoluted.
108 # TODO. Invent a better, non-conflicting name.
109 rename("$config{srcdir}/$file", "$config{srcdir}/$file.save") or
110 error("failed to rename $file to $file.save: $!");
112 # Roll the repository back to $rcstoken.
114 # TODO. Can we be sure that no changes are lost? I think that
115 # we can, if we make sure that the `darcs push' below will always
118 # We need to revert everything as `darcs obliterate' might choke
120 # TODO: `yes | ...' needed? Doesn't seem so.
121 system($darcs, "revert", "--repodir=" . $config{srcdir}, "--all") and
122 error("`darcs revert' failed");
123 # Remove all patches starting at $rcstoken.
124 # TODO. Something like `yes | darcs obliterate ...' seems to be needed.
125 system($darcs, "obliterate", "--quiet", "--repodir" . $config{srcdir},
126 "--match", "hash " . $rcstoken) and
127 error("`darcs obliterate' failed");
128 # Restore the $rcstoken one.
129 system($darcs, "pull", "--quiet", "--repodir=" . $config{srcdir},
130 "--match", "hash " . $rcstoken, "--all") and
131 error("`darcs pull' failed");
133 # We're back at $rcstoken. Re-install the modified file.
134 rename("$config{srcdir}/$file.save", "$config{srcdir}/$file") or
135 error("failed to rename $file.save to $file: $!");
138 # Record the changes.
139 # TODO: What if $message is empty?
140 writefile("$file.log", $config{srcdir}, $message);
141 system($darcs, 'record', '--repodir=' . $config{srcdir}, '--all',
142 '--logfile=' . "$config{srcdir}/$file.log",
143 '--author=' . 'web commit <web-hurd@gnu.org>', $file) and
144 error('`darcs record\' failed');
146 # Update the repository by pulling from the default repository, which is
148 system($darcs, "pull", "--quiet", "--repodir=" . $config{srcdir},
149 "--all") and error("`darcs pull' failed\n");
151 # If this updating yields any conflicts, we'll record them now to resolve
152 # them. If nothing is recorded, there are no conflicts.
153 $rcstoken = darcs_info('hash', $config{srcdir}, $file);
154 # TODO: Use only the first line here, i.e. only the patch name?
155 writefile("$file.log", $config{srcdir}, 'resolve conflicts: ' . $message);
156 system($darcs, 'record', '--repodir=' . $config{srcdir}, '--all',
157 '--logfile=' . "$config{srcdir}/$file.log",
158 '--author=' . 'web commit <web-hurd@gnu.org>', $file) and
159 error('`darcs record\' failed');
160 my $conflicts = darcs_info('hash', $config{srcdir}, $file) ne $rcstoken;
161 unlink("$config{srcdir}/$file.log") or
162 error("failed to remove `$file.log'");
164 # Push the changes to the main repository.
165 system($darcs, 'push', '--quiet', '--repodir=' . $config{srcdir}, '--all')
166 and error('`darcs push\' failed');
170 my $document = readfile("$config{srcdir}/$file");
171 # Try to leave everything in a consistent state.
172 # TODO: `yes | ...' needed? Doesn't seem so.
173 system($darcs, "revert", "--repodir=" . $config{srcdir}, "--all") and
174 warn("`darcs revert' failed.\n");
182 my $file = shift; # Relative to the repodir.
184 # Intermediate directories will be added automagically.
185 system($darcs, 'add', '--quiet', '--repodir=' . $config{srcdir},
186 '--boring', $file) and error('`darcs add\' failed');
189 sub rcs_recentchanges ($) {
190 warn('rcs_recentchanges() is not implemented');
191 return 'rcs_recentchanges() is not implemented';
195 warn('rcs_notify() is not implemented');
198 sub rcs_getctime () {
199 warn('rcs_getctime() is not implemented');