webrev revision 8453
# Script for generating code review pages similar to those generated by # The contents of this file are subject to the terms of the # Common Development and Distribution License, Version 1.0 only # (the "License"). You may not use this file except in compliance # See the License for the specific language governing permissions # and limitations under the License. # When distributing Covered Code, include this CDDL HEADER in each # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # Copyright 2006 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # - require the target dir to be empty # - breaks if you have a new subdir that is not under svn control # - should have a way to exclude some or all not-svn-controlled files # FIXME: would be nice to turn these into command line options # max number of chars in each line, above which lines are wrapped in # number of lines of context in sdiffs # Valid @FOO@ tags in the HTML templates: # @AUTHOR@ - real name of the current user according to the passwd entry # @COPYRIGHT@ - copyright statement (not implemented) # @UNAME@ - current user name # @HOSTNAME@ - hostname of the current host as printed by /bin/hostname # @DATE@ - current date string as printed by /bin/date ' <TITLE>@TITLE@</TITLE>\n' .
' <META NAME="author" CONTENT="@AUTHOR@">\n' .
' <META NAME="generator" CONTENT="webrev for svn">\n' .
# ' <META NAME="copyright" CONTENT="@COPYRIGHT@">\n' . ' <BODY BGCOLOR="#FFFFFF">\n' .
' <FONT FACE="arial,sans">\n' .
' <CENTER><FONT SIZE=+1><B>@TITLE@</B></FONT></CENTER><P>\n';
' <HR SIZE=1 NOSHADE>\n' .
' <FONT FACE="arial,sans" SIZE="-2">\n' .
' Webrev report generated by @UNAME@@@HOSTNAME@ on @DATE@.\n' .
# HTML page header template for the diff pages # HTML page footer template for the diff pages # Map status to file name # Descriptions of file status flags 'C', '<FONT COLOR="#FF4444">Conflicted</FONT>', '?', '<FONT COLOR="#FF4444">Not under version control</FONT>', # Map property change status to file name # FIXME: currently these are not used, but should be. # Descriptions of file status flags # fill the %file_status map based on svn status / cvs status output if ($line =~ /^(.)(.)(.)(.)(.)(.) (.*)/) { # map CVS status names to svn status flags 'File had conflicts on merge', 'C'); } elsif ($line =~ /^? (.*)/) { # fill in values in the HTML templates # 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");