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]]
13 use open qw{:utf8 :std};
22 my @entries = split(/\n-+\s/,join("", @lines));
26 foreach my $entry (@entries) {
28 my ($initial,$i) = split(/message:/,$entry,2);
29 my ($message, $j, $files) = split(/(added|modified|removed):/,$i,3);
30 $message =~ s/\n/\\n/g;
32 $entry = $initial . "\ndescription: " . $message . "\nfiles: " . $files;
34 my @lines = split(/\n/,$entry);
39 my ($key,$value) = split(/: /);
40 $entry{$key} = $value;
42 $entry{description}=~s/\\n/\n/g;
43 $entry{files}=~s/\s\s+/\ /g;
44 $entry{files}=~s/^\s+//g;
47 "description" => $entry{description},
48 "user" => $entry{committer},
49 "files" => $entry{files},
50 "date" => $entry{timestamp},
57 sub rcs_update () { #{{{
61 sub rcs_prepedit ($) { #{{{
65 sub rcs_commit ($$$;$$) { #{{{
66 my ($file, $message, $rcstoken, $user, $ipaddr) = @_;
69 $user = possibly_foolish_untaint($user);
71 elsif (defined $ipaddr) {
72 $user = "Anonymous from ".possibly_foolish_untaint($ipaddr);
78 $message = possibly_foolish_untaint($message);
79 if (! length $message) {
80 $message = "no message given";
83 my $olduser = `bzr whoami`;
85 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.
86 # Save the old one and restore after the commit.
87 my @cmdline = ("bzr", "commit", "-m", $message, $config{srcdir}."/".$file);
88 if (system(@cmdline) != 0) {
89 warn "'@cmdline' failed: $!";
92 $olduser=possibly_foolish_untaint($olduser);
93 system("bzr","whoami",$olduser);
95 return undef; # success
98 sub rcs_add ($) { # {{{
101 my @cmdline = ("bzr", "add", "--quiet", "$config{srcdir}/$file");
102 if (system(@cmdline) != 0) {
103 warn "'@cmdline' failed: $!";
107 sub rcs_recentchanges ($) { #{{{
110 eval q{use CGI 'escapeHTML'};
113 my @cmdline = ("bzr", "log", "--long", "--verbose", "--limit", $num,$config{srcdir});
114 open (my $out, "@cmdline |");
116 eval q{use Date::Parse};
120 foreach my $info (bzr_log($out)) {
124 foreach my $msgline (split(/\n/, $info->{description})) {
125 push @message, { line => $msgline };
128 foreach my $file (split / /,$info->{files}) {
129 my $diffurl = $config{'diffurl'};
130 $diffurl =~ s/\[\[file\]\]/$file/go;
131 $diffurl =~ s/\[\[r2\]\]/$info->{changeset}/go;
134 page => pagename($file),
139 my $user = $info->{"user"};
140 $user =~ s/\s*<.*>\s*$//;
144 rev => $info->{"changeset"},
147 when => time - str2time($info->{"date"}),
148 message => [@message],
156 sub rcs_notify () { #{{{
160 sub rcs_getctime ($) { #{{{
170 > Thanks for doing this.
171 > bzr 0.90 has support for --author to commit to set the author for one commit at a time,
172 > you might like to use that instead of changing the global username (which is racy).
174 > Wouter van Heyst and I were also working on a plugin for bzr, but we were waiting for
175 > the smart server to grow the ability to run server side hooks, so that you can edit locally
176 > and then push to rebuild the wiki, but there is no need to stop this going in in the mean
178 > Thanks again --[[JamesWestby]]
180 >> I didn't know about --author, it doesn't seem to be mentioned in the manual.
181 >> I'd update the patch to reflect this, but it breaks with the version of bzr
182 >> from Stable, and also the one I'm currently using from backports.org.