2 # gerrvim -- Gerrit review's comments preparation helper
3 # Copyright (C) 2015 Sergey Matveev <stargrave@stargrave.org>
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
30 my $main_message = undef;
31 my $verbatim_block = 0;
35 my $r = join "\n", @buf;
39 return decode_utf8 $r;
43 ($comments{$filename} = []) unless defined $comments{$filename};
44 my %c = (message => buf2str);
45 if ($lineend - $linebgn == 1) {
48 $c{range} = {start_line => $linebgn, end_line => $lineend};
50 ($c{in_reply_to} = $1) if ($blockid =~ /^R(.*)$/);
51 push @{$comments{$filename}}, \%c;
56 if (/^-{5}BEGIN (\w+) (.*) (\d+) (\d+)-{5}$/) {
58 ($main_message = buf2str) unless $blockn;
60 comment_done if defined $filename;
66 push @buf, $_ unless $verbatim_block;
67 if (/^-{5}END-{5}$/) {
71 comment_done if defined $filename;
72 ($main_message = buf2str) if !$blockn;
74 my %result = (comments => \%comments);
75 ($result{message} = $main_message) if $main_message;
76 print encode_json(\%result);