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