webrev revision 8111
10139N/A# Script for generating code review pages similar to those generated by 10139N/A# The contents of this file are subject to the terms of the 10139N/A# Common Development and Distribution License, Version 1.0 only 10139N/A# (the "License"). You may not use this file except in compliance 10139N/A# See the License for the specific language governing permissions 10139N/A# and limitations under the License. 10139N/A# When distributing Covered Code, include this CDDL HEADER in each 10139N/A# If applicable, add the following below this CDDL HEADER, with the 10139N/A# fields enclosed by brackets "[]" replaced with your own identifying 10139N/A# information: Portions Copyright [yyyy] [name of copyright owner] 10139N/A# Copyright 2006 Sun Microsystems, Inc. All rights reserved. 10139N/A# Use is subject to license terms. 10139N/A# FIXME: would be nice to turn these into command line options 10139N/A# max number of chars in each line, above which lines are wrapped in 10139N/A# number of lines of context in sdiffs 10139N/A# Valid @FOO@ tags in the HTML templates: 10139N/A# @AUTHOR@ - real name of the current user according to the passwd entry 10139N/A# @COPYRIGHT@ - copyright statement (not implemented) 10139N/A ' <META NAME="author" CONTENT="@AUTHOR@">\n' .
10139N/A ' <META NAME="generator" CONTENT="webrev for svn">\n' .
10139N/A# ' <META NAME="copyright" CONTENT="@COPYRIGHT@">\n' . 10139N/A ' <BODY BGCOLOR="#FFFFFF">\n' .
10139N/A ' <FONT FACE="arial,sans">\n' .
10139N/A ' <CENTER><FONT SIZE=+1><B>@TITLE@</B></FONT></CENTER><P>\n';
10139N/A ' <FONT FACE="arial,sans" SIZE="-2">\n' .
10139N/A ' Webrev report generated by @UNAME@@@HOSTNAME@ on @DATE@.\n' .
10139N/A# HTML page header template for the diff pages 10139N/A# HTML page footer template for the diff pages 10139N/A# Descriptions of file status flags 10139N/A 'C', '<FONT COLOR="#FF4444">Conflicted</FONT>', 10139N/A '?', '<FONT COLOR="#FF4444">Not under version control</FONT>', 10139N/A# Map property change status to file name 10139N/A# FIXME: currently these are not used, but should be. 10139N/A# Descriptions of file status flags 10139N/A# fill the %file_status map based on svn status / cvs status output 10139N/A # map CVS status names to svn status flags 10139N/A 'File had conflicts on merge', 'C'); 10139N/A# fill in values in the HTML templates 10139N/A# replace html special chars with corresponding entities # create the unified diff page and return the [udiff] link print DIFF "<TT><PRE>\n"; print DIFF "<FONT COLOR=\"green\" SIZE=\"+1\"><b>$line</b></FONT>\n"; } elsif ($line =~ /^@@/) { print DIFF "<FONT COLOR=\"red\" SIZE=\"+1\"><b>$line</b></FONT>\n"; } elsif ($line =~ /^\+\+\+/) { print DIFF "<FONT COLOR=\"red\" SIZE=\"+1\"><b>$line</b></FONT>\n"; } elsif ($line =~ /^\+/) { print DIFF "<FONT COLOR=\"blue\"><b>$line</b></FONT>\n"; } elsif ($line =~ /^\*\*\*/) { print DIFF "<FONT COLOR=\"red\" SIZE=\"+1\"><b>$line</b></FONT>\n"; } elsif ($line =~ /^-/) { print DIFF "<FONT COLOR=\"brown\">$line</FONT>\n"; print DIFF "</PRE></TT>\n"; # create the context diff page and return the [cdiff] link print DIFF "<TT><PRE>\n"; print DIFF "<FONT COLOR=\"blue\"><b>$line</b></FONT>\n"; } elsif ($line =~ /^---/) { print DIFF "<FONT COLOR=\"green\" SIZE=\"+1\"><b>$line</b></FONT>\n"; } elsif ($line =~ /^\*\*\*/) { print DIFF "<FONT COLOR=\"red\" SIZE=\"+1\"><b>$line</b></FONT>\n"; } elsif ($line =~ /^-/) { print DIFF "<FONT COLOR=\"brown\">$line</FONT>\n"; } elsif ($line =~ /^!/) { print DIFF "<FONT COLOR=\"blue\">$line</FONT>\n"; print DIFF "</PRE></TT>\n"; # add a line to the array representing either the left of the right side # of an sdiff. Lines are wrapped if longer than $SDIFF_MAX_LINE # returns the number of lines actually added to the array # $ref is a reference to the array # $start is printed before the line # $line is the line itself # $end is printed to the end of the line # $indent_len is the number of chars to indent wrapped lines (because of the # push (@$ref, "<PRE STYLE=\"margin: 1pt\">$line</PRE>"); # generate the sdiff page and return the [sdiff] link # we're going to work from a unified diff between the old and the new files # the 1st 2 lines are the file names my @left = ("<FONT COLOR=\"red\" SIZE=\"+1\"><b>$l</b></FONT>\n"); my @right = ("<FONT COLOR=\"green\" SIZE=\"+1\"><b>$l</b></FONT>\n"); # line numbers on the left and right side if ($line =~ /^\@\@ -([0-9]+),[0-9]+ \+([0-9]+),[0-9]+ \@\@/) { # new lines added to the file: print them on the right side in blue if ($line =~ /^\+(.*)/) { # print an equal number of blank lines on the left side while ($line =~ /^\-(.*)/) { # if deleted lines are immediately followed by added lines, # then some of the deleted lines are actually changed lines. # print them in blue on both sides while ($line =~ /^\+(.*)/) { # no deleted lines: print the new lines on the right side # deleted lines remain, print them in brown on the left side # unchanged (context) lines # fetch the next line if exists print DIFF "<TABLE COLS=2 BORDER=1 CELLSPACING=0>\n"; print DIFF "<TR><TD VALIGN=top>\n"; print DIFF "<TABLE WIDTH=100% COLS=1 BORDER=0 CELLSPACING=0 CELLPADDING=0>\n"; print DIFF "<TR><TD BGCOLOR=#DDDDDD><PRE STYLE=\"margin: 1pt;\">$line\n</PRE></TD></TR>\n"; print DIFF "<TR><TD><PRE STYLE=\"margin: 1pt;\">$line\n</PRE></TD></TR>\n"; print DIFF "</TABLE></TD>\n"; print DIFF "<TD VALIGN=top>\n"; print DIFF "<TABLE WIDTH=100% COLS=1 BORDER=0 CELLSPACING=0 CELLPADDING=0>\n"; print DIFF "<TR><TD BGCOLOR=#DDDDDD><PRE STYLE=\"margin: 1pt;\">$line\n</PRE></TD></TR>\n"; print DIFF "<TR><TD><PRE STYLE=\"margin: 1pt;\">$line\n</PRE></TD></TR>\n"; print DIFF "</TABLE></TD></TR>\n"; # map ChangeLog entries to files # find updated ChangeLog files and extract the entries for each file if ($line =~ /^\+(\s+\* \S+.*)/) { # read all lines until the next # assign the same entry to each file listed with # commas before the first : while ($ecat =~ /^([^:,]+)[:,]\s*(.*)/) { ################ MAIN ################################################### msg_fatal ("Webrev directory could not be created"); print "Finding changed files...\n"; print "Reading ChangeLogs...\n"; print "Processing files...\n"; print INDEX " "; print INDEX "<P>\n", next; print INDEX "<BR> "; print INDEX "<BR> "; print INDEX "<BR> "; print INDEX "$lines new line(s) not under svn control\n"; print INDEX "<BR> "; print INDEX "<BR> "; print INDEX "<FONT COLOR=red>No ChangeLog entry found</FONT><BR>\n"; print "Run this script inside a Subversion or CVS controlled directory\n"; print "to create an html code review document.\n"; print "The svn or cvs command must be in your PATH and should not\n"; print "require interaction (e.g. use ssh-add first)\n"; msg_fatal ("No CVS or Subversion control files found in this directory");