2 # gerrvim -- Gerrit review's comments preparation helper
3 # Copyright (C) 2015-2024 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, version 3 of the License.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
29 my $main_message = undef;
30 my $verbatim_block = 0;
34 my $r = join "\n", @buf;
38 return decode_utf8 $r;
42 ($comments{$filename} = []) unless defined $comments{$filename};
43 my %c = (message => buf2str);
44 if ($lineend - $linebgn == 1) {
47 $c{range} = {start_line => $linebgn, end_line => $lineend};
49 ($c{in_reply_to} = $1) if ($blockid =~ /^R(.*)$/);
50 push @{$comments{$filename}}, \%c;
55 if (/^-{5}BEGIN (\w+) (.*) (\d+) (\d+)-{5}$/) {
57 ($main_message = buf2str) unless $blockn;
59 comment_done if defined $filename;
65 push @buf, $_ unless $verbatim_block;
66 if (/^-{5}END-{5}$/) {
70 comment_done if defined $filename;
71 ($main_message = buf2str) if !$blockn;
73 my %result = (comments => \%comments);
74 ($result{message} = $main_message) if $main_message;
75 print encode_json(\%result);