9 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", "update", "--quiet", $config{srcdir});
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", "--quiet", "-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", "--quiet", "$config{srcdir}/$file");
87 if (system(@cmdline) != 0) {
88 warn "'@cmdline' failed: $!";
92 sub rcs_recentchanges ($) { #{{{
95 my @cmdline = ("bzr", "log", "-v", "--show-ids", "--limit", $num,
97 open (my $out, "@cmdline |");
99 eval q{use Date::Parse};
103 foreach my $info (bzr_log($out)) {
107 foreach my $msgline (split(/\n/, $info->{message})) {
108 push @message, { line => $msgline };
111 foreach my $file (split(/\n/, $info->{files})) {
112 my ($filename, $fileid) = split(/[ \t]+/, $file);
113 my $diffurl = $config{'diffurl'};
114 $diffurl =~ s/\[\[file\]\]/$filename/go;
115 $diffurl =~ s/\[\[file-id\]\]/$fileid/go;
116 $diffurl =~ s/\[\[r2\]\]/$info->{revno}/go;
119 page => pagename($filename),
124 my $user = $info->{"committer"};
125 if (defined($info->{"author"})) { $user = $info->{"author"}; }
126 $user =~ s/\s*<.*>\s*$//;
130 rev => $info->{"revno"},
133 when => time - str2time($info->{"timestamp"}),
134 message => [@message],
142 sub rcs_getctime ($) { #{{{
145 # XXX filename passes through the shell here, should try to avoid
147 my @cmdline = ("bzr", "log", "--limit", '1', "$config{srcdir}/$file");
148 open (my $out, "@cmdline |");
150 my @log = bzr_log($out);
152 if (length @log < 1) {
156 eval q{use Date::Parse};
159 my $ctime = str2time($log[0]->{"timestamp"});