7 use open qw{:utf8 :std};
11 sub bzr_log ($) { #{{{
19 if ($line =~ /^message:/) {
21 $infos[$#infos]{$key} = "";
23 elsif ($line =~ /^(modified|added|renamed|renamed and modified|removed):/) {
25 unless (defined($infos[$#infos]{$key})) { $infos[$#infos]{$key} = ""; }
27 elsif (defined($key) and $line =~ /^ (.*)/) {
28 $infos[$#infos]{$key} .= $1;
30 elsif ($line eq "------------------------------------------------------------\n") {
36 ($key, $value) = split /: +/, $line, 2;
37 $infos[$#infos]{$key} = $value;
45 sub rcs_update () { #{{{
46 my @cmdline = ("bzr", $config{srcdir}, "update");
47 if (system(@cmdline) != 0) {
48 warn "'@cmdline' failed: $!";
52 sub rcs_prepedit ($) { #{{{
56 sub rcs_commit ($$$;$$) { #{{{
57 my ($file, $message, $rcstoken, $user, $ipaddr) = @_;
60 $user = possibly_foolish_untaint($user);
62 elsif (defined $ipaddr) {
63 $user = "Anonymous from ".possibly_foolish_untaint($ipaddr);
69 $message = possibly_foolish_untaint($message);
70 if (! length $message) {
71 $message = "no message given";
74 my @cmdline = ("bzr", "commit", "-m", $message, "--author", $user,
75 $config{srcdir}."/".$file);
76 if (system(@cmdline) != 0) {
77 warn "'@cmdline' failed: $!";
80 return undef; # success
83 sub rcs_add ($) { # {{{
86 my @cmdline = ("bzr", "add", "$config{srcdir}/$file");
87 if (system(@cmdline) != 0) {
88 warn "'@cmdline' failed: $!";
92 sub rcs_recentchanges ($) { #{{{
95 eval q{use CGI 'escapeHTML'};
98 my @cmdline = ("bzr", "log", "-v", "--show-ids", "--limit", $num,
100 open (my $out, "@cmdline |");
102 eval q{use Date::Parse};
106 foreach my $info (bzr_log($out)) {
110 foreach my $msgline (split(/\n/, $info->{message})) {
111 push @message, { line => $msgline };
114 foreach my $file (split(/\n/, $info->{files})) {
115 my ($filename, $fileid) = split(/[ \t]+/, $file);
116 my $diffurl = $config{'diffurl'};
117 $diffurl =~ s/\[\[file\]\]/$filename/go;
118 $diffurl =~ s/\[\[file-id\]\]/$fileid/go;
119 $diffurl =~ s/\[\[r2\]\]/$info->{revno}/go;
122 page => pagename($filename),
127 my $user = $info->{"committer"};
128 if (defined($info->{"author"})) { $user = $info->{"author"}; }
129 $user =~ s/\s*<.*>\s*$//;
133 rev => $info->{"revno"},
136 when => time - str2time($info->{"timestamp"}),
137 message => [@message],
145 sub rcs_getctime ($) { #{{{
148 # XXX filename passes through the shell here, should try to avoid
150 my @cmdline = ("bzr", "log", "--limit", '1', "$config{srcdir}/$file");
151 open (my $out, "@cmdline |");
153 my @log = bzr_log($out);
155 if (length @log < 1) {
159 eval q{use Date::Parse};
162 my $ctime = str2time($log[0]->{"timestamp"});