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_commit_staged ($$$) {
84 # Commits all staged changes. Changes can be staged using rcs_add,
85 # rcs_remove, and rcs_rename.
86 my ($message, $user, $ipaddr)=@_;
88 error("rcs_commit_staged not implemented for bzr"); # TODO
91 sub rcs_add ($) { # {{{
94 my @cmdline = ("bzr", "add", "--quiet", "$config{srcdir}/$file");
95 if (system(@cmdline) != 0) {
96 warn "'@cmdline' failed: $!";
100 sub rcs_remove ($) { # {{{
103 error("rcs_remove not implemented for bzr"); # TODO
106 sub rcs_rename ($$) { # {{{
107 my ($src, $dest) = @_;
109 error("rcs_rename not implemented for bzr"); # TODO
112 sub rcs_recentchanges ($) { #{{{
115 my @cmdline = ("bzr", "log", "-v", "--show-ids", "--limit", $num,
117 open (my $out, "@cmdline |");
119 eval q{use Date::Parse};
123 foreach my $info (bzr_log($out)) {
127 foreach my $msgline (split(/\n/, $info->{message})) {
128 push @message, { line => $msgline };
131 foreach my $file (split(/\n/, $info->{files})) {
132 my ($filename, $fileid) = split(/[ \t]+/, $file);
133 my $diffurl = $config{'diffurl'};
134 $diffurl =~ s/\[\[file\]\]/$filename/go;
135 $diffurl =~ s/\[\[file-id\]\]/$fileid/go;
136 $diffurl =~ s/\[\[r2\]\]/$info->{revno}/go;
139 page => pagename($filename),
144 my $user = $info->{"committer"};
145 if (defined($info->{"author"})) { $user = $info->{"author"}; }
146 $user =~ s/\s*<.*>\s*$//;
150 rev => $info->{"revno"},
153 when => time - str2time($info->{"timestamp"}),
154 message => [@message],
162 sub rcs_getctime ($) { #{{{
165 # XXX filename passes through the shell here, should try to avoid
167 my @cmdline = ("bzr", "log", "--limit", '1', "$config{srcdir}/$file");
168 open (my $out, "@cmdline |");
170 my @log = bzr_log($out);
172 if (length @log < 1) {
176 eval q{use Date::Parse};
179 my $ctime = str2time($log[0]->{"timestamp"});