]> sipb.mit.edu Git - ikiwiki.git/blob - doc/patchqueue/darcs.mdwn
add news item for ikiwiki 1.45
[ikiwiki.git] / doc / patchqueue / darcs.mdwn
1 Here's Thomas Schwinge unfinished darcs support for ikiwiki.
2
3 (Finishing this has been suggested as a [[soc]] project.)
4
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.
9
10 -- [Thomas Schwinge](mailto:tschwinge@gnu.org)
11
12 [[toggle text="show"]]
13 [[toggleable text="""
14         # Support for the darcs rcs, <URL:http://darcs.net/>.
15         # Copyright (C) 2006  Thomas Schwinge <tschwinge@gnu.org>
16         #
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.
21         #
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.
26         #
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.
30         
31         
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.
37         
38         
39         use warnings;
40         use strict;
41         use IkiWiki;
42         
43         package IkiWiki;
44         
45         
46         # Which darcs executable to use.
47         my $darcs = ($ENV{DARCS} or 'darcs');
48         
49         
50         # Internal functions.
51         
52         sub darcs_info ($$$) {
53             my $field = shift;
54             my $repodir = shift;
55             my $file = shift; # Relative to the repodir.
56         
57             my $child = open(DARCS_CHANGES, "-|");
58             if (! $child) {
59                 exec($darcs, 'changes', '--repo=' . $repodir, '--xml-output', $file) or
60                     error('failed to run `darcs changes\'');
61             }
62         
63             # Brute force for now.  :-/
64             while (<DARCS_CHANGES>) {
65                 last if /^<\/created_as>$/;
66             }
67             ($_) = <DARCS_CHANGES> =~ /$field=\'([^\']+)/;
68             $field eq 'hash' and s/\.gz//; # Strip away the `.gz' from `hash'es.
69         
70             close(DARCS_CHANGES) or error('`darcs changes\' exited ' . $?);
71         
72             return $_;
73         }
74         
75         
76         # Exported functions.
77         
78         sub rcs_update () {
79             # Not needed.
80         }
81         
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.
88         
89             my $file = shift; # Relative to the repodir.
90         
91             my $hash = darcs_info('hash', $config{srcdir}, $file);
92             return defined $hash ? $hash : "";
93         }
94         
95         sub rcs_commit ($$$) {
96             # Commit the page.  Returns `undef' on success and a version of the page
97             # with conflict markers on failure.
98         
99             my $file = shift; # Relative to the repodir.
100             my $message = shift;
101             my $rcstoken = shift;
102         
103             # Compute if the ``revision'' of $file changed.
104             my $changed = darcs_info('hash', $config{srcdir}, $file) ne $rcstoken;
105         
106             # Yes, the following is a bit convoluted.
107             if ($changed) {
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: $!");
111         
112                 # Roll the repository back to $rcstoken.
113         
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
116                 # succeed.
117         
118                 # We need to revert everything as `darcs obliterate' might choke
119                 # otherwise.
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");
132         
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: $!");
136             }
137         
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');
145         
146             # Update the repository by pulling from the default repository, which is
147             # master repository.
148             system($darcs, "pull", "--quiet", "--repodir=" . $config{srcdir},
149                    "--all") and error("`darcs pull' failed\n");
150         
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'");
163         
164             # Push the changes to the main repository.
165             system($darcs, 'push', '--quiet', '--repodir=' . $config{srcdir}, '--all')
166                 and error('`darcs push\' failed');
167             # TODO: darcs send?
168         
169             if ($conflicts) {
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");
175                 return $document;
176             } else {
177                 return undef;
178             }
179         }
180         
181         sub rcs_add ($) {
182             my $file = shift; # Relative to the repodir.
183         
184             # Intermediate directories will be added automagically.
185             system($darcs, 'add', '--quiet', '--repodir=' . $config{srcdir},
186                    '--boring', $file) and error('`darcs add\' failed');
187         }
188         
189         sub rcs_recentchanges ($) {
190             warn('rcs_recentchanges() is not implemented');
191             return 'rcs_recentchanges() is not implemented';
192         }
193         
194         sub rcs_notify () {
195             warn('rcs_notify() is not implemented');
196         }
197         
198         sub rcs_getctime () {
199             warn('rcs_getctime() is not implemented');
200         }
201         
202         1
203 """]]