1 This is mostly based on the Mercurial plugin (in fact, apart from the commands
2 being run, only the name of the rcs was changed in rcs_recentchanges, and
3 rcs_commit was only changed to work around bzr's lack of a switch to set the
4 username). bzr_log could probably be written better by someone better at perl,
5 and rcs_getctime and rcs_notify aren't written at all. --[[bma]]
7 (rcs_notify is not needed in this branch --[[Joey]])
15 use open qw{:utf8 :std};
24 my @entries = split(/\n-+\s/,join("", @lines));
28 foreach my $entry (@entries) {
30 my ($initial,$i) = split(/message:/,$entry,2);
31 my ($message, $j, $files) = split(/(added|modified|removed):/,$i,3);
32 $message =~ s/\n/\\n/g;
34 $entry = $initial . "\ndescription: " . $message . "\nfiles: " . $files;
36 my @lines = split(/\n/,$entry);
41 my ($key,$value) = split(/: /);
42 $entry{$key} = $value;
44 $entry{description}=~s/\\n/\n/g;
45 $entry{files}=~s/\s\s+/\ /g;
46 $entry{files}=~s/^\s+//g;
49 "description" => $entry{description},
50 "user" => $entry{committer},
51 "files" => $entry{files},
52 "date" => $entry{timestamp},
59 sub rcs_update () { #{{{
63 sub rcs_prepedit ($) { #{{{
67 sub rcs_commit ($$$;$$) { #{{{
68 my ($file, $message, $rcstoken, $user, $ipaddr) = @_;
71 $user = possibly_foolish_untaint($user);
73 elsif (defined $ipaddr) {
74 $user = "Anonymous from ".possibly_foolish_untaint($ipaddr);
80 $message = possibly_foolish_untaint($message);
81 if (! length $message) {
82 $message = "no message given";
85 my $olduser = `bzr whoami`;
87 system("bzr","whoami",$user); # This will set the branch username; there doesn't seem to be a way to do it on a per-commit basis.
88 # Save the old one and restore after the commit.
89 my @cmdline = ("bzr", "commit", "-m", $message, $config{srcdir}."/".$file);
90 if (system(@cmdline) != 0) {
91 warn "'@cmdline' failed: $!";
94 $olduser=possibly_foolish_untaint($olduser);
95 system("bzr","whoami",$olduser);
97 return undef; # success
100 sub rcs_add ($) { # {{{
103 my @cmdline = ("bzr", "add", "--quiet", "$config{srcdir}/$file");
104 if (system(@cmdline) != 0) {
105 warn "'@cmdline' failed: $!";
109 sub rcs_recentchanges ($) { #{{{
112 eval q{use CGI 'escapeHTML'};
115 my @cmdline = ("bzr", "log", "--long", "--verbose", "--limit", $num,$config{srcdir});
116 open (my $out, "@cmdline |");
118 eval q{use Date::Parse};
122 foreach my $info (bzr_log($out)) {
126 foreach my $msgline (split(/\n/, $info->{description})) {
127 push @message, { line => $msgline };
130 foreach my $file (split / /,$info->{files}) {
131 my $diffurl = $config{'diffurl'};
132 $diffurl =~ s/\[\[file\]\]/$file/go;
133 $diffurl =~ s/\[\[r2\]\]/$info->{changeset}/go;
136 page => pagename($file),
141 my $user = $info->{"user"};
142 $user =~ s/\s*<.*>\s*$//;
146 rev => $info->{"changeset"},
149 when => time - str2time($info->{"date"}),
150 message => [@message],
158 sub rcs_notify () { #{{{
162 sub rcs_getctime ($) { #{{{
172 > Thanks for doing this.
173 > bzr 0.90 has support for --author to commit to set the author for one commit at a time,
174 > you might like to use that instead of changing the global username (which is racy).
176 > Wouter van Heyst and I were also working on a plugin for bzr, but we were waiting for
177 > the smart server to grow the ability to run server side hooks, so that you can edit locally
178 > and then push to rebuild the wiki, but there is no need to stop this going in in the mean
180 > Thanks again --[[JamesWestby]]
182 >> I didn't know about --author, it doesn't seem to be mentioned in the manual.
183 >> I'd update the patch to reflect this, but it breaks with the version of bzr
184 >> from Stable, and also the one I'm currently using from backports.org.
186 >>> It's new (in fact I'm not even sure that it made it in to 0.90, it might be in 0.91 due
187 >>> in a couple of weeks.
188 >>> I was just noting it for a future enhancement. --[[JamesWestby]]
190 > I've just posted another patch with support for bzr, including support for
191 > --author and a testsuite to git://git.samba.org/jelmer/ikiwiki.git. I hadn't
192 > seen this page earlier. --[[jelmer]]
194 > I used jelmer's patch --[[done]]! --[[Joey]]