webrev revision 12969
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainen# Script for generating code review pages similar to those generated by
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainen# ON's webrev tool
5bda841ca9e2ddd90702dc7e2a15326e4068066eTimo Sirainen# CDDL HEADER START
009d6d90b33bc7f64fa8251ac392cc87a835b833Timo Sirainen# The contents of this file are subject to the terms of the
03f4c5f3502801f5b318f464cc75313a88558805Timo Sirainen# Common Development and Distribution License, Version 1.0 only
009d6d90b33bc7f64fa8251ac392cc87a835b833Timo Sirainen# (the "License"). You may not use this file except in compliance
8d587838c414c48a331f0b54cd7ffd97e5024abdTimo Sirainen# with the License.
88b9f9eb91da632d3e941fe4276f8ace03205b25Timo Sirainen# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
027c729b3107441f54a2602ccf2c67c6206998d5Timo Sirainen# See the License for the specific language governing permissions
c37098f8ce6d512ba41f09564d04ed25720f0a77Timo Sirainen# and limitations under the License.
031d075daf75b74b286711c1b6f64c3ae70e541bTimo Sirainen# When distributing Covered Code, include this CDDL HEADER in each
031d075daf75b74b286711c1b6f64c3ae70e541bTimo Sirainen# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2ce5b1d19cba4654239116a34e3ad9d5b6af8551Timo Sirainen# If applicable, add the following below this CDDL HEADER, with the
2ce5b1d19cba4654239116a34e3ad9d5b6af8551Timo Sirainen# fields enclosed by brackets "[]" replaced with your own identifying
f90c6ff1ae3d5675abfc6ae05574924fda8dca9eTimo Sirainen# information: Portions Copyright [yyyy] [name of copyright owner]
f90c6ff1ae3d5675abfc6ae05574924fda8dca9eTimo Sirainen# CDDL HEADER END
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainen# Copyright 2006 Sun Microsystems, Inc. All rights reserved.
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainen# Use is subject to license terms.
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainen# - require the target dir to be empty
33502e55a9bf4cafcd184ca9b114c126e420f856Timo Sirainen# - breaks if you have a new subdir that is not under svn control
33502e55a9bf4cafcd184ca9b114c126e420f856Timo Sirainen# - should have a way to exclude some or all not-svn-controlled files
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainen# Usage: webrev /path/to/output/dir
6380f2bc729a03b328793e8ad6ba7587620fa184Timo Sirainen# creates the html report of changed in the current svn workspace (current dir)
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainen# FIXME: would be nice to turn these into command line options
bd49b2e35dfa08753e89bef12a694978599d0fc0Timo Sirainen# max number of chars in each line, above which lines are wrapped in
bd49b2e35dfa08753e89bef12a694978599d0fc0Timo Sirainen# side-by-side diffs
bd49b2e35dfa08753e89bef12a694978599d0fc0Timo Sirainen# number of lines of context in sdiffs
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen# Valid @FOO@ tags in the HTML templates:
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen# @TITLE@ - page title
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen# @AUTHOR@ - real name of the current user according to the passwd entry
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen# @COPYRIGHT@ - copyright statement (not implemented)
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainen# @UNAME@ - current user name
8d587838c414c48a331f0b54cd7ffd97e5024abdTimo Sirainen# @HOSTNAME@ - hostname of the current host as printed by /bin/hostname
03f4c5f3502801f5b318f464cc75313a88558805Timo Sirainen# @DATE@ - current date string as printed by /bin/date
03f4c5f3502801f5b318f464cc75313a88558805Timo Sirainen# HTML page header template for index.html
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainen ' <HEAD>\n' .
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainen ' <TITLE>@TITLE@</TITLE>\n' .
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainen ' <META NAME="author" CONTENT="@AUTHOR@">\n' .
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen ' <META NAME="generator" CONTENT="webrev for svn">\n' .
f26ef7a3a562dc42a1e9a4dde546bd30df3241e8Timo Sirainen# ' <META NAME="copyright" CONTENT="@COPYRIGHT@">\n' .
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen ' </HEAD>\n' .
4ee00532a265bdfb38539d811fcd12d51210ac35Timo Sirainen ' <BODY BGCOLOR="#FFFFFF">\n' .
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainen ' <FONT FACE="arial,sans">\n' .
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainen ' <CENTER><FONT SIZE=+1><B>@TITLE@</B></FONT></CENTER><P>\n';
57b523eeb99ed5d7f5002907a409cdef54353ce5Timo Sirainen# HTML page footer template for index.html
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainen ' </FONT>\n' .
009d6d90b33bc7f64fa8251ac392cc87a835b833Timo Sirainen ' <HR SIZE=1 NOSHADE>\n' .
009d6d90b33bc7f64fa8251ac392cc87a835b833Timo Sirainen ' <FONT FACE="arial,sans" SIZE="-2">\n' .
009d6d90b33bc7f64fa8251ac392cc87a835b833Timo Sirainen ' Webrev report generated by @UNAME@@@HOSTNAME@ on @DATE@.\n' .
009d6d90b33bc7f64fa8251ac392cc87a835b833Timo Sirainen ' </FONT>\n' .
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainen ' </BODY>\n' .
3b55c4f0e2ab51e2607556dde8d36360296b29e4Timo Sirainen# HTML page header template for the diff pages
3b55c4f0e2ab51e2607556dde8d36360296b29e4Timo Sirainen# HTML page footer template for the diff pages
009d6d90b33bc7f64fa8251ac392cc87a835b833Timo Sirainen# Map status to file name
009d6d90b33bc7f64fa8251ac392cc87a835b833Timo Sirainen# Descriptions of file status flags
009d6d90b33bc7f64fa8251ac392cc87a835b833Timo Sirainen 'C', '<FONT COLOR="#FF4444">Conflicted</FONT>',
678d0463849ba777106eb7875f27db07a5d8e3dfTimo Sirainen '?', '<FONT COLOR="#FF4444">Not under version control</FONT>',
03f4c5f3502801f5b318f464cc75313a88558805Timo Sirainen# Map property change status to file name
c37098f8ce6d512ba41f09564d04ed25720f0a77Timo Sirainen# FIXME: currently these are not used, but should be.
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainen# Descriptions of file status flags
f26ef7a3a562dc42a1e9a4dde546bd30df3241e8Timo Sirainen# fill the %file_status map based on svn status / cvs status output
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen my @lines = `LC_ALL=C svn --non-interactive status` or msg_fatal ('"svn status" failed');
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainen msg_warning ("Cannot process svn status output: $line");
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen my @lines = `LC_ALL=C cvs -z3 status 2>&1 | egrep '(^\\? |^cvs status: Examining |Status:)' | grep -v Up-to-date`
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen } elsif ($line =~ /^File: no file (.+)\s+Status: (.*)/) {
f26ef7a3a562dc42a1e9a4dde546bd30df3241e8Timo Sirainen } elsif ($line =~ /^File: (.*\S)\s+Status: (.*)/) {
2e5d624013c30633e8ded148d338ce46c321a995Timo Sirainen msg_warning ("Cannot process cvs status output: $line");
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen# fill in values in the HTML templates
2e5d624013c30633e8ded148d338ce46c321a995Timo Sirainen $str =~ s/\\n/\n/g;
8d587838c414c48a331f0b54cd7ffd97e5024abdTimo Sirainen# replace html special chars with corresponding entities
03f4c5f3502801f5b318f464cc75313a88558805Timo Sirainen msg_error ("Failed to create directory $webrev_dir/$file");
03f4c5f3502801f5b318f464cc75313a88558805Timo Sirainen system ("rm -f $webrev_dir/$file/new.$basename; cp $file $webrev_dir/$file/new.$basename");
03f4c5f3502801f5b318f464cc75313a88558805Timo Sirainen msg_fatal ("failed to copy file $file to $webrev_dir/$file");
031d075daf75b74b286711c1b6f64c3ae70e541bTimo Sirainen return "[<A HREF=\"$file/new.$basename\">new</A>] ";
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainen system ("rm -f $webrev_dir/$file/old.$basename");
031d075daf75b74b286711c1b6f64c3ae70e541bTimo Sirainen system ("svn --non-interactive cat -r BASE $file > $webrev_dir/$file/old.$basename");
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainen my $rev=`LC_ALL=C cvs -z3 status $file | grep 'Working revision' | cut -f2 -d:`;
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainen system ("cd $webrev_dir/tmp && LC_ALL=C cvs -q -z3 -d $CVSROOT co -r$rev $REPO/$basename >/dev/null 2>&1 && mv $REPO/$basename $webrev_dir/$file/old.$basename && cd / && rm -rf $webrev_dir/tmp");
39ed514f9d401b3cb589595c6a2f532050254d77Timo Sirainen return "[<A HREF=\"$file/old.$basename\">old</A>] ";
9b6eb5a72ffe61579e24c6ae4c6ce3d4e9104b95Timo Sirainen# create the unified diff page and return the [udiff] link
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainen @diff = `cd $webrev_dir/$file; /usr/bin/diff -u old.$basename new.$basename`;
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainen system ("rm -f $webrev_dir/$file/udiff.html");
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainen sysopen (DIFF, "$webrev_dir/$file/udiff.html", O_WRONLY | $overwrite | O_CREAT) or
57b523eeb99ed5d7f5002907a409cdef54353ce5Timo Sirainen msg_error ("failed to create file $webrev_dir/$file/udiff.html");
57b523eeb99ed5d7f5002907a409cdef54353ce5Timo Sirainen print DIFF eval_template ($file_page_header, "Unified diff of $file");
57b523eeb99ed5d7f5002907a409cdef54353ce5Timo Sirainen print DIFF "<FONT COLOR=\"green\" SIZE=\"+1\"><b>$line</b></FONT>\n";
57b523eeb99ed5d7f5002907a409cdef54353ce5Timo Sirainen print DIFF "<FONT COLOR=\"red\" SIZE=\"+1\"><b>$line</b></FONT>\n";
57b523eeb99ed5d7f5002907a409cdef54353ce5Timo Sirainen print DIFF "<FONT COLOR=\"red\" SIZE=\"+1\"><b>$line</b></FONT>\n";
57b523eeb99ed5d7f5002907a409cdef54353ce5Timo Sirainen print DIFF "<FONT COLOR=\"blue\"><b>$line</b></FONT>\n";
8d587838c414c48a331f0b54cd7ffd97e5024abdTimo Sirainen print DIFF "<FONT COLOR=\"red\" SIZE=\"+1\"><b>$line</b></FONT>\n";
6380f2bc729a03b328793e8ad6ba7587620fa184Timo Sirainen print DIFF "<FONT COLOR=\"brown\">$line</FONT>\n";
8d587838c414c48a331f0b54cd7ffd97e5024abdTimo Sirainen return "[<A HREF=\"$file/udiff.html\">udiff</A>] ";
6380f2bc729a03b328793e8ad6ba7587620fa184Timo Sirainen# create the context diff page and return the [cdiff] link
6380f2bc729a03b328793e8ad6ba7587620fa184Timo Sirainen my @diff = `cd $webrev_dir/$file; /usr/bin/diff -c old.$basename new.$basename`;
8d587838c414c48a331f0b54cd7ffd97e5024abdTimo Sirainen system ("rm -f $webrev_dir/$file/cdiff.html");
6380f2bc729a03b328793e8ad6ba7587620fa184Timo Sirainen sysopen (DIFF, "$webrev_dir/$file/cdiff.html", O_WRONLY | $overwrite | O_CREAT) or
031d075daf75b74b286711c1b6f64c3ae70e541bTimo Sirainen msg_error ("failed to create file $webrev_dir/$file/cdiff.html");
6380f2bc729a03b328793e8ad6ba7587620fa184Timo Sirainen print DIFF eval_template ($file_page_header, "Context diff of $file");
8d587838c414c48a331f0b54cd7ffd97e5024abdTimo Sirainen print DIFF "<FONT COLOR=\"blue\"><b>$line</b></FONT>\n";
8d587838c414c48a331f0b54cd7ffd97e5024abdTimo Sirainen print DIFF "<FONT COLOR=\"green\" SIZE=\"+1\"><b>$line</b></FONT>\n";
8d587838c414c48a331f0b54cd7ffd97e5024abdTimo Sirainen print DIFF "<FONT COLOR=\"red\" SIZE=\"+1\"><b>$line</b></FONT>\n";
8d587838c414c48a331f0b54cd7ffd97e5024abdTimo Sirainen print DIFF "<FONT COLOR=\"brown\">$line</FONT>\n";
8d587838c414c48a331f0b54cd7ffd97e5024abdTimo Sirainen print DIFF "<FONT COLOR=\"blue\">$line</FONT>\n";
37f96554a5734557cd454691d163e602d36384b4Timo Sirainen return "[<A HREF=\"$file/cdiff.html\">cdiff</A>] ";
5b6470e0e2ef4012430cdeca7d9b89c1278a0ed4Timo Sirainen# add a line to the array representing either the left of the right side
5b6470e0e2ef4012430cdeca7d9b89c1278a0ed4Timo Sirainen# of an sdiff. Lines are wrapped if longer than $SDIFF_MAX_LINE
5b6470e0e2ef4012430cdeca7d9b89c1278a0ed4Timo Sirainen# returns the number of lines actually added to the array
5b6470e0e2ef4012430cdeca7d9b89c1278a0ed4Timo Sirainen# $ref is a reference to the array
5b6470e0e2ef4012430cdeca7d9b89c1278a0ed4Timo Sirainen# $start is printed before the line
5b6470e0e2ef4012430cdeca7d9b89c1278a0ed4Timo Sirainen# $line is the line itself
5b6470e0e2ef4012430cdeca7d9b89c1278a0ed4Timo Sirainen# $end is printed to the end of the line
5b6470e0e2ef4012430cdeca7d9b89c1278a0ed4Timo Sirainen# $indent_len is the number of chars to indent wrapped lines (because of the
5b6470e0e2ef4012430cdeca7d9b89c1278a0ed4Timo Sirainen# line numbers
5b6470e0e2ef4012430cdeca7d9b89c1278a0ed4Timo Sirainen my $indent_str = sprintf ("%${indent_len}s ", "");
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainen my $lstart = substr ($line, 0, $SDIFF_MAX_LINE);
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainen $the_line = "$the_line\n$indent_str$line$end";
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen# push (@$ref, "<PRE STYLE=\"margin: 1pt\">$line</PRE>");
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen# generate the sdiff page and return the [sdiff] link
c37098f8ce6d512ba41f09564d04ed25720f0a77Timo Sirainen # we're going to work from a unified diff between the old and the new files
c37098f8ce6d512ba41f09564d04ed25720f0a77Timo Sirainen my $total_lines = `cat $webrev_dir/$file/old.$basename | wc -l`;
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen my @diff = `cd $webrev_dir/$file; /usr/bin/diff -U $SDIFF_CONTEXT old.$basename new.$basename`;
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen my @left = ("<FONT COLOR=\"red\" SIZE=\"+1\"><b>$l</b></FONT>\n");
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen my @right = ("<FONT COLOR=\"green\" SIZE=\"+1\"><b>$l</b></FONT>\n");
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen if ($line =~ /^\@\@ -([0-9]+),[0-9]+ \+([0-9]+),[0-9]+ \@\@/) {
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen $right_line = sprintf ("%${line_nr_len}s",$2);
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen # new lines added to the file: print them on the right side in blue
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen my $n = push_line (\@right, "<FONT COLOR=\"blue\">$right_line ", $1, "</FONT>", $line_nr_len);
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen # print an equal number of blank lines on the left side
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen $right_line = sprintf ("%${line_nr_len}s", ++$right_line);
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen # if deleted lines are immediately followed by added lines,
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen # then some of the deleted lines are actually changed lines.
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainen my $n1 = push_line (\@left, "<FONT COLOR=\"blue\">$left_line ", $line2, "</FONT>", $line_nr_len);
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainen $left_line = sprintf ("%${line_nr_len}s", ++$left_line);
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen my $n2 = push_line (\@right, "<FONT COLOR=\"blue\">$right_line ", $line1, "</FONT>", $line_nr_len);
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainen $right_line = sprintf ("%${line_nr_len}s", ++$right_line);
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainen # no deleted lines: print the new lines on the right side
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainen my $n = push_line (\@right, "<FONT COLOR=\"blue\">$right_line ", $line1, "</FONT>", $line_nr_len);
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainen $right_line = sprintf ("%${line_nr_len}s", ++$right_line);
57b523eeb99ed5d7f5002907a409cdef54353ce5Timo Sirainen # deleted lines remain, print them in brown on the left side
8d587838c414c48a331f0b54cd7ffd97e5024abdTimo Sirainen my $n = push_line (\@left, "<FONT COLOR=\"brown\">$left_line ", $line2, "</FONT>", $line_nr_len);
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainen $left_line = sprintf ("%${line_nr_len}s", ++$left_line);
f26ef7a3a562dc42a1e9a4dde546bd30df3241e8Timo Sirainen push_line (\@right, "$right_line ", $line, "", $line_nr_len);
f26ef7a3a562dc42a1e9a4dde546bd30df3241e8Timo Sirainen push_line (\@left, "$left_line ", $line, "", $line_nr_len);
f26ef7a3a562dc42a1e9a4dde546bd30df3241e8Timo Sirainen $left_line = sprintf ("%${line_nr_len}s", ++$left_line);
f26ef7a3a562dc42a1e9a4dde546bd30df3241e8Timo Sirainen $right_line = sprintf ("%${line_nr_len}s", ++$right_line);
1e1549f93601770d1bddf702baf55c593e3d97e9Timo Sirainen system ("rm -f $webrev_dir/$file/sdiff.html");
8d587838c414c48a331f0b54cd7ffd97e5024abdTimo Sirainen sysopen (DIFF, "$webrev_dir/$file/sdiff.html", O_WRONLY | $overwrite | O_CREAT) or
d2945436697f00504ef2b3af6afbd8a097e5eed2Timo Sirainen msg_error ("failed to create file $webrev_dir/$file/sdiff.html");
8d587838c414c48a331f0b54cd7ffd97e5024abdTimo Sirainen print DIFF eval_template ($file_page_header, "Side by side diff of $file");
8d587838c414c48a331f0b54cd7ffd97e5024abdTimo Sirainen print DIFF "<TABLE COLS=2 BORDER=1 CELLSPACING=0>\n";
8d587838c414c48a331f0b54cd7ffd97e5024abdTimo Sirainen print DIFF "<TABLE WIDTH=100% COLS=1 BORDER=0 CELLSPACING=0 CELLPADDING=0>\n";
8d587838c414c48a331f0b54cd7ffd97e5024abdTimo Sirainen print DIFF "<TR><TD BGCOLOR=#DDDDDD><PRE STYLE=\"margin: 1pt;\">$line\n</PRE></TD></TR>\n";
37e5638ddf924fd4a07623095dbc028c564f7192Timo Sirainen print DIFF "<TR><TD><PRE STYLE=\"margin: 1pt;\">$line\n</PRE></TD></TR>\n";
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainen print DIFF "<TABLE WIDTH=100% COLS=1 BORDER=0 CELLSPACING=0 CELLPADDING=0>\n";
dce232dfbb2244555299dffb3618a4724748d260Timo Sirainen print DIFF "<TR><TD BGCOLOR=#DDDDDD><PRE STYLE=\"margin: 1pt;\">$line\n</PRE></TD></TR>\n";
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainen print DIFF "<TR><TD><PRE STYLE=\"margin: 1pt;\">$line\n</PRE></TD></TR>\n";
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainen return "[<A HREF=\"$file/sdiff.html\">sdiff</A>] ";
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainen system ("rm -f $webrev_dir/$file/$basename.diff; svn --non-interactive diff $file > $webrev_dir/$file/$basename.diff");
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainen system ("rm -f $webrev_dir/$file/$basename.diff; cvs -q diff -up $file > $webrev_dir/$file/$basename.diff");
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainen return "[<A HREF=\"$file/$basename.diff\">patch</A>] ";
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainen# map ChangeLog entries to files
009d6d90b33bc7f64fa8251ac392cc87a835b833Timo Sirainen# find updated ChangeLog files and extract the entries for each file
009d6d90b33bc7f64fa8251ac392cc87a835b833Timo Sirainen if ($file eq "ChangeLog" or $file =~ /\/ChangeLog$/) {
009d6d90b33bc7f64fa8251ac392cc87a835b833Timo Sirainen @chlog_lines = `svn --non-interactive diff $file | grep "^\+"`;
8d587838c414c48a331f0b54cd7ffd97e5024abdTimo Sirainen @chlog_lines = `cvs -q diff -u $file | grep "^\+"`;
009d6d90b33bc7f64fa8251ac392cc87a835b833Timo Sirainen while (defined ($line) and $line =~ /^\+(\s+[^*].*)/) {
009d6d90b33bc7f64fa8251ac392cc87a835b833Timo Sirainen $ecat =~ s/^\s*\*\s*//;
009d6d90b33bc7f64fa8251ac392cc87a835b833Timo Sirainen # assign the same entry to each file listed with
009d6d90b33bc7f64fa8251ac392cc87a835b833Timo Sirainen################ MAIN ###################################################
009d6d90b33bc7f64fa8251ac392cc87a835b833Timo Sirainen msg_fatal ("Webrev directory could not be created");
30003461d9c5b090384b252260916cf50954d943Timo Sirainen sysopen (INDEX, "$webrev_dir/index.html", O_WRONLY | $overwrite | O_CREAT) or
39ed514f9d401b3cb589595c6a2f532050254d77Timo Sirainen msg_fatal ("failed to create file $webrev_dir/index.html");
009d6d90b33bc7f64fa8251ac392cc87a835b833Timo Sirainen print INDEX eval_template ($index_page_header, $title);
009d6d90b33bc7f64fa8251ac392cc87a835b833Timo Sirainen print INDEX "<P><B>$file</B> ($status_desc{$file_status{$file}})<BR>\n";
009d6d90b33bc7f64fa8251ac392cc87a835b833Timo Sirainen print INDEX gen_diff_new ($webrev_dir, $file);
009d6d90b33bc7f64fa8251ac392cc87a835b833Timo Sirainen print INDEX "<BR> ";
009d6d90b33bc7f64fa8251ac392cc87a835b833Timo Sirainen print INDEX gen_diff_old ($webrev_dir, $file);
009d6d90b33bc7f64fa8251ac392cc87a835b833Timo Sirainen print INDEX "<BR> ";
009d6d90b33bc7f64fa8251ac392cc87a835b833Timo Sirainen my $lines = `cat $webrev_dir/$file/old.$basename | wc -l`;
009d6d90b33bc7f64fa8251ac392cc87a835b833Timo Sirainen print INDEX gen_diff_new ($webrev_dir, $file);
009d6d90b33bc7f64fa8251ac392cc87a835b833Timo Sirainen print INDEX "<BR> ";
009d6d90b33bc7f64fa8251ac392cc87a835b833Timo Sirainen print INDEX "$lines new line(s) not under svn control\n";
009d6d90b33bc7f64fa8251ac392cc87a835b833Timo Sirainen my $changed_lines = `diff -c $webrev_dir/$file/old.$basename $webrev_dir/$file/new.$basename | grep '^! ' | wc -l`;
009d6d90b33bc7f64fa8251ac392cc87a835b833Timo Sirainen my $deleted_lines = `diff -c $webrev_dir/$file/old.$basename $webrev_dir/$file/new.$basename | grep '^- ' | wc -l`;
009d6d90b33bc7f64fa8251ac392cc87a835b833Timo Sirainen my $new_lines = `diff -c $webrev_dir/$file/old.$basename $webrev_dir/$file/new.$basename | grep '^+ ' | wc -l`;
009d6d90b33bc7f64fa8251ac392cc87a835b833Timo Sirainen my $total_lines = `cat $webrev_dir/$file/old.$basename | wc -l`;
009d6d90b33bc7f64fa8251ac392cc87a835b833Timo Sirainen my $unchanged_lines = $total_lines - $deleted_lines - $changed_lines;
009d6d90b33bc7f64fa8251ac392cc87a835b833Timo Sirainen print INDEX "<BR> ";
009d6d90b33bc7f64fa8251ac392cc87a835b833Timo Sirainen print INDEX "$new_lines line(s) new / $deleted_lines line(s) deleted / $changed_lines line(s) updated / $unchanged_lines line(s) unchanged\n";
009d6d90b33bc7f64fa8251ac392cc87a835b833Timo Sirainen } elsif ($file ne "ChangeLog" and not $file =~ /\/ChangeLog$/) {
009d6d90b33bc7f64fa8251ac392cc87a835b833Timo Sirainen print INDEX "<BR> ";
8d587838c414c48a331f0b54cd7ffd97e5024abdTimo Sirainen print INDEX "<FONT COLOR=red>No ChangeLog entry found</FONT><BR>\n";
009d6d90b33bc7f64fa8251ac392cc87a835b833Timo Sirainen print INDEX "<P><B>Total</B>: $total_new line(s) new / $total_deleted line(s) deleted / $total_changed line(s) updated / $total_unchanged line(s) unchanged<BR>\n";
009d6d90b33bc7f64fa8251ac392cc87a835b833Timo Sirainen print INDEX "An additional $total_non_svn line(s) not under source control<P>\n";
5b6470e0e2ef4012430cdeca7d9b89c1278a0ed4Timo Sirainen print INDEX eval_template ($index_page_footer);
3b55c4f0e2ab51e2607556dde8d36360296b29e4Timo Sirainenif ((@ARGV != 1) or ($ARGV[0] eq "-h") or ($ARGV[0] eq "--help")) {
3b55c4f0e2ab51e2607556dde8d36360296b29e4Timo Sirainen print "Usage: webrev /path/to/webrev/dir\n\n";
3b55c4f0e2ab51e2607556dde8d36360296b29e4Timo Sirainen print "Run this script inside a Subversion or CVS controlled directory\n";
3b55c4f0e2ab51e2607556dde8d36360296b29e4Timo Sirainen print "to create an html code review document.\n";
3b55c4f0e2ab51e2607556dde8d36360296b29e4Timo Sirainen print "The argument is a directory where the output is written.\n";
3b55c4f0e2ab51e2607556dde8d36360296b29e4Timo Sirainen print "The svn or cvs command must be in your PATH and should not\n";
5b6470e0e2ef4012430cdeca7d9b89c1278a0ed4Timo Sirainen print "require interaction (e.g. use ssh-add first)\n";
854255e62c956846537335b8c38f921a7e4b3afbTimo Sirainen msg_fatal ("No CVS or Subversion control files found in this directory");
678d0463849ba777106eb7875f27db07a5d8e3dfTimo Sirainen msg_fatal ("The target directory should not be svn or CVS controlled");