webrev.sh revision e0e0293ac229cd6d0db5217ec05fe61463aa00e2
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# 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]
#
# CDDL HEADER END
#
#
# ident "%Z%%M% %I% %E% SMI"
#
# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
# This script takes a file list and a workspace and builds a set of html files
# suitable for doing a code review of source changes via a web page.
# Documentation is available via the manual page, webrev.1, or just
# type 'webrev -h'.
#
# Acknowledgements to contributors to webrev are listed in the webrev(1)
# man page.
#
#
# Note this will have to be changed in 2100 or when SCCS has support for
# 4 digit years; whichever is the sooner!
#
WEBREV_UPDATED=20%E%
HTML='<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n'
FRAMEHTML='<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n'
STDHEAD='<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="-1" />
<!--
Note to customizers: the body of the webrev is IDed as SUNWwebrev
to allow easy overriding by users of webrev via the userContent.css
mechanism available in some browsers.
For example, to have all "removed" information be red instead of
brown, set a rule in your userContent.css file like:
body#SUNWwebrev span.removed { color: red ! important; }
-->
body {
background-color: #eeeeee;
}
hr {
border: none 0;
border-top: 1px solid #aaa;
height: 1px;
}
font-size: .8em;
border-bottom: 1px solid #aaa;
padding-left: 1em;
padding-right: 1em;
}
div.summary h2 {
margin-bottom: 0.3em;
}
div.summary table th {
text-align: right;
vertical-align: top;
white-space: nowrap;
}
font-size: 0.7em;
}
color: red;
font-size: large;
font-weight: bold;
}
color: green;
font-size: large;
font-weight: bold;
}
color: brown;
}
color: blue;
}
span.new {
color: blue;
font-weight: bold;
}
a.print { font-size: x-small; }
a:hover { background-color: #ffcc99; }
</style>
pre { font-size: 0.8em; font-family: courier, monospace; }
span.removed { color: #444; font-style: italic }
span.changed { font-weight: bold; }
span.new { font-weight: bold; }
span.newmarker { font-size: 1.2em; font-weight: bold; }
span.oldmarker { font-size: 1.2em; font-weight: bold; }
a.print {display: none}
hr { border: none 0; border-top: 1px solid #aaa; height: 1px; }
</style>
'
#
# UDiffs need a slightly different CSS rule for 'new' items (we don't
# want them to be bolded as we do in cdiffs or sdiffs).
#
UDIFFCSS='
span.new {
color: blue;
font-weight: normal;
}
</style>
'
#
# input_cmd | html_quote | output_cmd
# or
# html_quote filename | output_cmd
#
# Make a piece of source code safe for display in an HTML <pre> block.
#
{
}
#
# input_cmd | bug2url | output_cmd
#
# Scan for bugids and insert <a> links to the relevent bug database.
#
bug2url()
{
}
#
# input_cmd | sac2url | output_cmd
#
# Scan for ARC cases and insert <a> links to the relevent SAC database.
# This is slightly complicated because inside the SWAN, SAC cases are
# grouped by ARC: PSARC/2006/123. But on OpenSolaris.org, they are
# referenced as 2006/123 (without labelling the ARC).
#
sac2url()
{
sed -e 's|\([A-Z]\{1,2\}ARC\)[ /]\([0-9]\{4\}\)/\([0-9]\{3\}\)|<a href=\"'$SACURL'/\1/\2/\3\">\1 \2/\3</a>|g'
else
sed -e 's|\([A-Z]\{1,2\}ARC\)[ /]\([0-9]\{4\}\)/\([0-9]\{3\}\)|<a href=\"'$SACURL'/\2/\3\">\1 \2/\3</a>|g'
fi
}
#
# strip_unchanged <infile> | output_cmd
#
# Removes chunks of sdiff documents that have not changed. This makes it
# easier for a code reviewer to find the bits that have changed.
#
# Deleted lines of text are replaced by a horizontal rule. Some
# identical lines are retained before and after the changed lines to
# provide some context. The number of these lines is controlled by the
# variable C in the nawk script below.
#
# The script detects changed lines as any line that has a "<span class="
# string embedded (unchanged lines have no particular class and are not
# part of a <span>). Blank lines (without a sequence number) are also
# detected since they flag lines that have been inserted or deleted.
#
{
nawk '
BEGIN { C = c = 20 }
NF == 0 || /span class=/ {
if (c > C) {
c -= C
inx = 0
if (c > C) {
print "\n</pre><hr /><pre>"
inx = c % C
c = C
}
for (i = 0; i < c; i++)
print ln[(inx + i) % C]
}
c = 0;
print
next
}
{ if (c >= C) {
ln[c % C] = $0
c++;
next;
}
c++;
print
}
END { if (c > (C * 2)) print "\n</pre><hr />" }
' $1
}
#
# sdiff_to_html
#
# This function takes two files as arguments, obtains their diff, and
# processes the diff output to present the files as an HTML document with
# the files displayed side-by-side, differences shown in color. It also
# takes a delta comment, rendered as an HTML snippet, as the third
# argument. The function takes two files as arguments, then the name of
# file, the path, and the comment. The HTML will be delivered on stdout,
# e.g.
#
# '<a href="http://monaco.sfbay.sun.com/detail.jsp?cr=1234567">
# 1234567</a> my bugid' > <file>.html
#
# framed_sdiff() is then called which creates $2.frames.html
# in the webrev tree.
#
# FYI: This function is rather unusual in its use of awk. The initial
# diff run produces conventional diff output showing changed lines mixed
# with editing codes. The changed lines are ignored - we're interested in
# the editing codes, e.g.
#
# 8c8
# 57a61
# 63c66,76
# 68,93d80
# 106d90
# 108,110d91
#
# These editing codes are parsed by the awk script and used to generate
# another awk script that generates HTML, e.g the above lines would turn
# into something like this:
#
# BEGIN { printf "<pre>\n" }
# function sp(n) {for (i=0;i<n;i++)printf "\n"}
# function wl(n) {printf "<font color=%s>%4d %s </font>\n", n, NR, $0}
# NR==8 {wl("#7A7ADD");next}
# NR==54 {wl("#7A7ADD");sp(3);next}
# NR==56 {wl("#7A7ADD");next}
# NR==57 {wl("black");printf "\n"; next}
# : :
#
# This script is then run on the original source file to generate the
# HTML that corresponds to the source file.
#
# The two HTML files are then combined into a single piece of HTML that
# uses an HTML table construct to present the files side by side. You'll
# notice that the changes are color-coded:
#
# black - unchanged lines
# blue - changed lines
# bold blue - new lines
# brown - deleted lines
#
# Blank lines are inserted in each file to keep unchanged lines in sync
# (side-by-side). This format is familiar to users of sdiff(1) or
# Teamware's filemerge tool.
#
{
TNAME=$3
TPATH=$4
COMMENT=$5
#
# Now we have the diffs, generate the HTML for the old file.
#
nawk '
BEGIN {
printf "function sp(n) {for (i=0;i<n;i++)printf \"\\n\"}\n"
printf "function removed() "
printf "{printf \"<span class=\\\"removed\\\">%%4d %%s</span>\\n\", NR, $0}\n"
printf "function changed() "
printf "{printf \"<span class=\\\"changed\\\">%%4d %%s</span>\\n\", NR, $0}\n"
printf "function bl() {printf \"%%4d %%s\\n\", NR, $0}\n"
}
/^</ {next}
/^>/ {next}
/^---/ {next}
{
split($1, a, /[cad]/) ;
if (index($1, "a")) {
if (a[1] == 0) {
n = split(a[2], r, /,/);
if (n == 1)
printf "BEGIN\t\t{sp(1)}\n"
else
printf "BEGIN\t\t{sp(%d)}\n",\
(r[2] - r[1]) + 1
next
}
printf "NR==%s\t\t{", a[1]
n = split(a[2], r, /,/);
s = r[1];
if (n == 1)
printf "bl();printf \"\\n\"; next}\n"
else {
n = r[2] - r[1]
printf "bl();sp(%d);next}\n",\
(r[2] - r[1]) + 1
}
next
}
if (index($1, "d")) {
n = split(a[1], r, /,/);
n1 = r[1]
n2 = r[2]
if (n == 1)
printf "NR==%s\t\t{removed(); next}\n" , n1
else
printf "NR==%s,NR==%s\t{removed(); next}\n" , n1, n2
next
}
if (index($1, "c")) {
n = split(a[1], r, /,/);
n1 = r[1]
n2 = r[2]
final = n2
d1 = 0
if (n == 1)
printf "NR==%s\t\t{changed();" , n1
else {
d1 = n2 - n1
printf "NR==%s,NR==%s\t{changed();" , n1, n2
}
m = split(a[2], r, /,/);
n1 = r[1]
n2 = r[2]
if (m > 1) {
d2 = n2 - n1
if (d2 > d1) {
if (n > 1) printf "if (NR==%d)", final
printf "sp(%d);", d2 - d1
}
}
printf "next}\n" ;
next
}
}
END { printf "{printf \"%%4d %%s\\n\", NR, $0 }\n" }
#
# Now generate the HTML for the new file
#
nawk '
BEGIN {
printf "function sp(n) {for (i=0;i<n;i++)printf \"\\n\"}\n"
printf "function new() "
printf "{printf \"<span class=\\\"new\\\">%%4d %%s</span>\\n\", NR, $0}\n"
printf "function changed() "
printf "{printf \"<span class=\\\"changed\\\">%%4d %%s</span>\\n\", NR, $0}\n"
printf "function bl() {printf \"%%4d %%s\\n\", NR, $0}\n"
}
/^</ {next}
/^>/ {next}
/^---/ {next}
{
split($1, a, /[cad]/) ;
if (index($1, "d")) {
if (a[2] == 0) {
n = split(a[1], r, /,/);
if (n == 1)
printf "BEGIN\t\t{sp(1)}\n"
else
printf "BEGIN\t\t{sp(%d)}\n",\
(r[2] - r[1]) + 1
next
}
printf "NR==%s\t\t{", a[2]
n = split(a[1], r, /,/);
s = r[1];
if (n == 1)
printf "bl();printf \"\\n\"; next}\n"
else {
n = r[2] - r[1]
printf "bl();sp(%d);next}\n",\
(r[2] - r[1]) + 1
}
next
}
if (index($1, "a")) {
n = split(a[2], r, /,/);
n1 = r[1]
n2 = r[2]
if (n == 1)
printf "NR==%s\t\t{new() ; next}\n" , n1
else
printf "NR==%s,NR==%s\t{new() ; next}\n" , n1, n2
next
}
if (index($1, "c")) {
n = split(a[2], r, /,/);
n1 = r[1]
n2 = r[2]
final = n2
d2 = 0;
if (n == 1) {
final = n1
printf "NR==%s\t\t{changed();" , n1
} else {
d2 = n2 - n1
printf "NR==%s,NR==%s\t{changed();" , n1, n2
}
m = split(a[1], r, /,/);
n1 = r[1]
n2 = r[2]
if (m > 1) {
d1 = n2 - n1
if (d1 > d2) {
if (n > 1) printf "if (NR==%d)", final
printf "sp(%d);", d1 - d2
}
}
printf "next}\n" ;
next
}
}
END { printf "{printf \"%%4d %%s\\n\", NR, $0 }\n" }
#
# Post-process the HTML files by running them back through nawk
#
html_quote < $1 | nawk -f /tmp/$$.file1 > /tmp/$$.file1.html
html_quote < $2 | nawk -f /tmp/$$.file2 > /tmp/$$.file2.html
#
# Now combine into a valid HTML file and side-by-side into a table
#
print "</head><body id=\"SUNWwebrev\">"
print "<a class=\"print\" href=\"javascript:print()\">Print this page</a>"
print "<pre>$COMMENT</pre>\n"
print "<table><tr valign=\"top\">"
print "<td><pre>"
print "</pre></td><td><pre>"
print "</pre></td>"
print "</tr></table>"
print "</body></html>"
framed_sdiff $TNAME $TPATH /tmp/$$.file1.html /tmp/$$.file2.html \
"$COMMENT"
}
#
# framed_sdiff <filename> <filepath> <lhsfile> <rhsfile> <comment>
#
# Expects lefthand and righthand side html files created by sdiff_to_html.
# We use insert_anchors() to augment those with HTML navigation anchors,
# and then emit the main frame. Content is placed into:
#
# $WDIR/DIR/$TNAME.lhs.html
# $WDIR/DIR/$TNAME.rhs.html
# $WDIR/DIR/$TNAME.frames.html
#
# NOTE: We rely on standard usage of $WDIR and $DIR.
#
function framed_sdiff
{
typeset TNAME=$1
typeset TPATH=$2
typeset lhsfile=$3
typeset rhsfile=$4
typeset comments=$5
typeset RTOP
# Enable html files to access WDIR via a relative path.
<script type="text/javascript" src="$RTOP/ancnav.js" />
</head>
<body id="SUNWwebrev" onkeypress="keypress(event);">
<a name="0" />
<pre>$comments</pre><hr />
EOF
cp $WDIR/$DIR/$TNAME.lhs.html $WDIR/$DIR/$TNAME.rhs.html
insert_anchors $lhsfile >> $WDIR/$DIR/$TNAME.lhs.html
insert_anchors $rhsfile >> $WDIR/$DIR/$TNAME.rhs.html
close='</body></html>'
print $close >> $WDIR/$DIR/$TNAME.lhs.html
print $close >> $WDIR/$DIR/$TNAME.rhs.html
print "$FRAMEHTML<head>$STDHEAD" > $WDIR/$DIR/$TNAME.frames.html
print "<title>$WNAME Framed-Sdiff " \
"$TPATH/$TNAME</title> </head>" >> $WDIR/$DIR/$TNAME.frames.html
cat >> $WDIR/$DIR/$TNAME.frames.html <<-EOF
<frameset rows="*,60">
<frameset cols="50%,50%">
<frame src="$TNAME.lhs.html" scrolling="auto" name="lhs" />
<frame src="$TNAME.rhs.html" scrolling="auto" name="rhs" />
</frameset>
<frame src="$RTOP/ancnav.html" scrolling="no" marginwidth="0"
marginheight="0" name="nav" />
<noframes>
<body id="SUNWwebrev">
Alas 'frames' webrev requires that your browser supports frames
and has the feature enabled.
</body>
</noframes>
</frameset>
</html>
EOF
}
#
# fix_postscript
#
# Merge codereview output files to a single conforming postscript file, by:
# - removing all extraneous headers/trailers
# - making the page numbers right
# - removing pages devoid of contents which confuse some
# postscript readers.
#
# From Casper.
#
function fix_postscript
{
infile=$1
cat > /tmp/$$.crmerge.pl << \EOF
print scalar(<>); # %!PS-Adobe---
print "%%Orientation: Landscape\n";
$pno = 0;
$doprint = 1;
$page = "";
while (<>) {
next if (/^%%Pages:\s*\d+/);
if (/^%%Page:/) {
if ($pno == 0 || $page =~ /\)S/) {
# Header or single page containing text
print "%%Page: ? $pno\n" if ($pno > 0);
print $page;
$pno++;
} else {
# Empty page, skip it.
}
$page = "";
$doprint = 1;
next;
}
# Skip from %%Trailer of one document to Endprolog
# %%Page of the next
$doprint = 0 if (/^%%Trailer/);
$page .= $_ if ($doprint);
}
if ($page =~ /\)S/) {
print "%%Page: ? $pno\n";
print $page;
} else {
$pno--;
}
print "%%Trailer\n%%Pages: $pno\n";
EOF
$PERL /tmp/$$.crmerge.pl < $infile
}
#
# input_cmd | insert_anchors | output_cmd
#
# Flag blocks of difference with sequentially numbered invisible
# anchors. These are used to drive the frames version of the
# sdiffs output.
#
# NOTE: Anchor zero flags the top of the file irrespective of changes,
# an additional anchor is also appended to flag the bottom.
#
# The script detects changed lines as any line that has a "<span
# class=" string embedded (unchanged lines have no class set and are
# not part of a <span>. Blank lines (without a sequence number)
# are also detected since they flag lines that have been inserted or
# deleted.
#
function insert_anchors
{
nawk '
function ia() {
# This should be able to be a singleton <a /> but that
# seems to trigger a bug in firefox a:hover rule processing
printf "<a name=\"%d\" id=\"anc%d\"></a>", anc, anc++;
}
BEGIN {
anc=1;
inblock=1;
printf "<pre>\n";
}
NF == 0 || /^<span class=/ {
if (inblock == 0) {
ia();
inblock=1;
}
print;
next;
}
{
inblock=0;
print;
}
END {
ia();
printf "<b style=\"font-size: large; color: red\">";
printf "--- EOF ---</b>"
for(i=0;i<8;i++) printf "\n\n\n\n\n\n\n\n\n\n";
printf "</pre>"
printf "<form name=\"eof\">";
printf "<input name=\"value\" value=\"%d\" type=\"hidden\" />",
anc - 1;
printf "</form>";
}
' $1
}
#
# relative_dir
#
# Print a relative return path from $1 to $2. For example if
# this function would print "../../../../".
#
# In the event that $1 is not in $2 a warning is printed to stderr,
# and $2 is returned-- the result of this is that the resulting webrev
# is not relocatable.
#
function relative_dir
{
typeset cur="${1##$2?(/)}"
typeset ret=""
if [[ $2 == $cur ]]; then # Should never happen.
# Should never happen.
print -u2 "\nWARNING: relative_dir: \"$1\" not relative "
print -u2 "to \"$2\". Check input paths. Framed webrev "
print -u2 "will not be relocatable!"
print $2
return
fi
while [[ -n ${cur} ]];
do
if [[ -z $ret ]]; then
ret=".."
else
fi
done
print $ret
}
#
# frame_nav_js
#
# Emit javascript for frame navigation
#
function frame_nav_js
{
sfactor*=1.2;
scount=10;
}
scount--;
}
// lines.
//
//
}
function getAncValue()
{
}
function setAncValue(val)
{
val = 0;
}
//
// on each side, so we pluck from the left.
//
maxval = parent.lhs.document.eof.value.value;
if (val < maxval) {
return (val);
}
// this must be: val >= maxval
val = maxval;
return (val);
}
function stopScroll() {
if (scrolling==1) {
clearInterval(myInt);
scrolling=0;
}
}
function startScroll() {
stopScroll();
scrolling=1;
myInt=setInterval("scrollByPix()",10);
}
function handlePress(b) {
switch (b) {
case 1 :
scrollToAnc(-1);
break;
case 2 :
scrollToAnc(getAncValue() - 1);
break;
case 3 :
sfactor=-3;
startScroll();
break;
case 4 :
sfactor=3;
startScroll();
break;
case 5 :
scrollToAnc(getAncValue() + 1);
break;
case 6 :
scrollToAnc(999999);
break;
}
}
function handleRelease(b) {
stopScroll();
}
function keypress(ev) {
var keynum;
var keychar;
if (window.event) { // IE
keynum = ev.keyCode;
} else if (ev.which) { // non-IE
keynum = ev.which;
}
keychar = String.fromCharCode(keynum);
if (keychar == "k") {
handlePress(2);
return (0);
} else if (keychar == "j" || keychar == " ") {
handlePress(5);
return (0);
}
return (1);
}
function ValidateDiffNum(){
if (val == "EOF") {
scrollToAnc(999999);
return;
}
if (val == "BOF") {
scrollToAnc(0);
return;
}
i=parseInt(val);
if (isNaN(i)) {
parent.nav.document.diff.display.value = getAncValue();
} else {
scrollToAnc(i);
}
return false;
}
EOF
}
#
# frame_navigation
#
# Output anchor navigation file for framed sdiffs.
#
function frame_navigation
{
print "$HTML<head>$STDHEAD"
cat << \EOF
<title>Anchor Navigation</title>
<meta http-equiv="Content-Script-Type" content="text/javascript">
div.button td { padding-left: 5px; padding-right: 5px;
background-color: #eee; text-align: center;
border: 1px #444 outset; cursor: pointer; }
div.button a { font-weight: bold; color: black }
div.button td:hover { background: #ffcc99; }
</style>
EOF
print "<script type=\"text/javascript\" src=\"ancnav.js\" />"
cat << \EOF
</head>
<body id="SUNWwebrev" bgcolor="#eeeeee" onload="document.diff.real.focus();"
onkeypress="keypress(event);">
<noscript lang="javascript">
<center>
<p><big>Framed Navigation controls require Javascript</big><br />
Either this browser is incompatable or javascript is not enabled</p>
</center>
</noscript>
<table width="100%" border="0" align="center">
<tr>
<td valign="middle" width="25%">Diff navigation:
Use 'j' and 'k' for next and previous diffs; or use buttons
at right</td>
<td align="center" valign="top" width="50%">
<div class="button">
<table border="0" align="center">
<tr>
<td>
<a onMouseDown="handlePress(1);return true;"
onMouseUp="handleRelease(1);return true;"
onMouseOut="handleRelease(1);return true;"
onClick="return false;"
title="Go to Beginning Of file">BOF</a></td>
<td>
<a onMouseDown="handlePress(3);return true;"
onMouseUp="handleRelease(3);return true;"
onMouseOut="handleRelease(3);return true;"
title="Scroll Up: Press and Hold to accelerate"
onClick="return false;">Scroll Up</a></td>
<td>
<a onMouseDown="handlePress(2);return true;"
onMouseUp="handleRelease(2);return true;"
onMouseOut="handleRelease(2);return true;"
title="Go to previous Diff"
onClick="return false;">Prev Diff</a>
</td></tr>
<tr>
<td>
<a onMouseDown="handlePress(6);return true;"
onMouseUp="handleRelease(6);return true;"
onMouseOut="handleRelease(6);return true;"
onClick="return false;"
title="Go to End Of File">EOF</a></td>
<td>
<a onMouseDown="handlePress(4);return true;"
onMouseUp="handleRelease(4);return true;"
onMouseOut="handleRelease(4);return true;"
title="Scroll Down: Press and Hold to accelerate"
onClick="return false;">Scroll Down</a></td>
<td>
<a onMouseDown="handlePress(5);return true;"
onMouseUp="handleRelease(5);return true;"
onMouseOut="handleRelease(5);return true;"
title="Go to next Diff"
onClick="return false;">Next Diff</a></td>
</tr>
</table>
</div>
</td>
<th valign="middle" width="25%">
<form action="" name="diff" onsubmit="return ValidateDiffNum();">
<input name="display" value="BOF" size="8" type="text" />
<input name="real" value="0" size="8" type="hidden" />
</form>
</th>
</tr>
</table>
</body>
</html>
EOF
}
#
# diff_to_html <filename> <filepath> { U | C } <comment>
#
# Processes the output of diff to produce an HTML file representing either
# context or unified diffs.
#
diff_to_html()
{
TNAME=$1
TPATH=$2
DIFFTYPE=$3
COMMENT=$4
print "$HTML<head>$STDHEAD"
print "<title>$WNAME ${DIFFTYPE}diff $TPATH</title>"
if [[ $DIFFTYPE == "U" ]]; then
print "$UDIFFCSS"
fi
cat <<-EOF
</head>
<body id="SUNWwebrev">
<a class="print" href="javascript:print()">Print this page</a>
<pre>$COMMENT</pre>
<pre>
EOF
html_quote | nawk '
/^--- new/ { next }
/^\+\+\+ new/ { next }
/^--- old/ { next }
/^\*\*\* old/ { next }
/^\*\*\*\*/ { next }
next}
next}
next}
'
print "</pre></body></html>\n"
}
#
# source_to_html { new | old } <filename>
#
# Process a plain vanilla source file to transform it into an HTML file.
#
source_to_html()
{
WHICH=$1
TNAME=$2
print "$HTML<head>$STDHEAD"
print "<title>$WHICH $TNAME</title>"
print "<body id=\"SUNWwebrev\">"
print "<pre>"
print "</pre></body></html>"
}
#
# teamwarecomments {text|html} parent-file child-file
#
# newest delta from the parent, get all deltas from the child starting
# with that delta, and then get all info starting with the second oldest
# delta in that list (the first delta unique to the child).
#
# This code adapted from Bill Shannon's "spc" script
#
{
fmt=$1
if [[ -f $pfile ]]; then
else
psid=1.1
fi
N=${#sids[@]}
nawkprg='
/^COMMENTS:/ {p=1; continue}
/^D [0-9]+\.[0-9]+/ {printf "--- %s ---\n", $2; p=0; }
NF == 0u { continue }
{if (p==0) continue; print $0 }'
if [[ $N -ge 2 ]]; then
return
fi
html_quote | bug2url | sac2url | nawk "$nawkprg"
fi
}
#
# wxcomments {text|html} filepath
#
# Given the pathname of a file, find its location in a "wx" active file
# list and print the following sccs comment. Output is either text or
# HTML; if the latter, embedded bugids (sequence of 5 or more digits) are
# turned into URLs.
#
{
typeset fmt=$1
typeset p=$2
$1 == "'$p'" {
do getline ; while (NF > 0)
getline
while (NF > 0) { print ; getline }
exit
}' < $wxfile`
print "$comm"
return
fi
}
#
# getcomments {text|html} filepath parentpath
#
# Fetch the comments depending on what SCM mode we're in.
#
{
typeset fmt=$1
typeset p=$2
typeset pp=$3
if [[ -n $wxfile ]]; then
else
fi
fi
}
#
# printCI <total-changed> <inserted> <deleted> <modified> <unchanged>
#
# Print out Code Inspection figures similar to sccs-prt(1) format.
#
function printCI
{
typeset str
str="line"
else
str="lines"
fi
}
#
# difflines <oldfile> <newfile>
#
# Calculate and emit number of added, removed, modified and unchanged lines,
# and total lines changed, the sum of added + removed + modified.
#
function difflines
{
typeset filename
# Change range of lines: N,Nc
/^[0-9]*,[0-9]*c$/ {
n=split(substr($1,1,length($1)-1), counts, ",");
if (n != 2) {
error=2
exit;
}
#
# 3,5c means lines 3 , 4 and 5 are changed, a total of 3 lines.
# following would be 5 - 3 = 2! Hence +1 for correction.
#
r=(counts[2]-counts[1])+1;
#
# Now count replacement lines: each represents a change instead
# of a delete, so increment c and decrement r.
#
while (getline != /^\.$/) {
c++;
r--;
}
#
# If there were more replacement lines than original lines,
# then r will be negative; in this case there are no deletions,
# but there are r changes that should be counted as adds, and
# since r is negative, subtract it from a and add it to c.
#
if (r < 0) {
a-=r;
c+=r;
}
#
# If there were more original lines than replacement lines, then
# r will be positive; in this case, increment d by that much.
#
if (r > 0) {
d+=r;
}
next;
}
# Change lines: Nc
/^[0-9].*c$/ {
# The first line is a replacement; any more are additions.
if (getline != /^\.$/) {
c++;
while (getline != /^\.$/) a++;
}
next;
}
# Add lines: both Na and N,Na
/^[0-9].*a$/ {
while (getline != /^\.$/) a++;
next;
}
# Delete range of lines: N,Nd
/^[0-9]*,[0-9]*d$/ {
n=split(substr($1,1,length($1)-1), counts, ",");
if (n != 2) {
error=2
exit;
}
#
# 3,5d means lines 3 , 4 and 5 are deleted, a total of 3 lines.
# following would be 5 - 3 = 2! Hence +1 for correction.
#
r=(counts[2]-counts[1])+1;
d+=r;
next;
}
# Delete line: Nd. For example 10d says line 10 is deleted.
/^[0-9]*d$/ {d++; next}
# Should not get here!
{
error=1;
exit;
}
# Finish off - print results
END {
printf("tot=%d;mod=%d;del=%d;ins=%d;err=%d\n",
(c+d+a), c, d, a, error);
}' )
# End of nawk, Check to see if any trouble occurred.
print "Unexpected Error occurred reading" \
return
fi
# Accumulate totals
# Calculate unchanged lines
fi
# print summary
print "<span class=\"lineschanged\">"
print "</span>"
}
#
# flist_from_wx
#
# Sets up webrev to source its information from a wx-formatted file.
# Sets the global 'wxfile' variable.
#
function flist_from_wx
{
typeset argfile=$1
if [[ -n ${argfile%%/*} ]]; then
#
# If the wx file pathname is relative then make it absolute
# because the webrev does a "cd" later on.
#
else
fi
nawk '{ c = 1; print;
while (getline) {
if (NF == 0) { c = -c; continue }
if (c > 0) print
}
print " Done."
}
#
# flist_from_teamware [ <args-to-putback-n> ]
#
# Generate the file list by extracting file names from a putback -n. Some
# "currently checked out" warning. Renames are detected here too. Extract
# values for CODEMGR_WS and CODEMGR_PARENT from the output of the putback
# -n as well, but remove them if they are already defined.
#
function flist_from_teamware
{
if [[ -n $codemgr_parent ]]; then
if [[ ! -d $codemgr_parent/Codemgr_wsdata ]]; then
"valid teamware workspace"
exit 1
fi
fi
print " File list from: 'putback -n $parent_args $*' ... \c"
putback -n $parent_args $* 2>&1 |
nawk '
/^update:|^create:/ {print $2}
/^Parent workspace:/ {printf("CODEMGR_PARENT=%s\n",$3)}
/^Child workspace:/ {printf("CODEMGR_WS=%s\n",$3)}
/^The following files are currently checked out/ {p = 1; continue}
NF == 0 {p=0 ; continue}
/^rename/ {old=$3}
$1 == "to:" {print $2, old}
/^"/ {continue}
p == 1 {print $1}' |
print " Done."
}
function env_from_flist
{
[[ -r $FLIST ]] || return
#
# Use "eval" to set env variables that are listed in the file
# list. Then copy those into our local versions of those
# variables if they have not been set already.
#
[[ -z $codemgr_ws && -n $CODEMGR_WS ]] && codemgr_ws=$CODEMGR_WS
#
# Check to see if CODEMGR_PARENT is set in the flist file.
#
[[ -z $codemgr_parent && -n $CODEMGR_PARENT ]] && \
}
#
# detect_scm
#
# We dynamically test the SCM type; this allows future extensions to
# new SCM types
#
function detect_scm
{
#
# If CODEMGR_WS is specified in the flist file, we assume teamware.
#
if [[ -r $FLIST ]]; then
if [[ $? -eq 0 ]]; then
print "teamware"
return
fi
fi
#
# The presence of $CODEMGR_WS and a Codemgr_wsdata directory
# is our clue that this is a teamware workspace.
#
print "teamware"
else
print "unknown"
fi
}
function look_for_prog
{
typeset path
typeset ppath
typeset progname=$1
if [[ -n $prog ]]; then
print $prog
fi
}
#
# Usage message.
#
function usage
{
print 'Usage:\twebrev [common-options]
webrev [common-options] ( <file> | - )
webrev [common-options] -w <wx file>
Options:
-i <filename>: Include <filename> in the index.html file.
-o <outdir>: Output webrev to specified directory.
-p <compare-against>: Use specified parent wkspc or basis for comparison
-w <wxfile>: Use specified wx active file.
Environment:
WDIR: Control the output directory.
WEBREV_BUGURL: Control the URL prefix for bugids.
WEBREV_SACURL: Control the URL prefix for ARC cases.
SCM Environment:
Teamware: CODEMGR_WS: Workspace location.
Teamware: CODEMGR_PARENT: Parent workspace location.
'
exit 2
}
#
#
# Main program starts here
#
#
trap "rm -f /tmp/$$.* ; exit" 0 1 2 3 15
set +o noclobber
[[ -z $WDIFF ]] && WDIFF=`look_for_prog wdiff`
[[ -z $WX ]] && WX=`look_for_prog wx`
[[ -z $CODEREVIEW ]] && CODEREVIEW=`look_for_prog codereview`
[[ -z $PS2PDF ]] && PS2PDF=`look_for_prog ps2pdf`
[[ -z $PERL ]] && PERL=`look_for_prog perl`
if [[ ! -x $PERL ]]; then
print -u2 "Error: No perl interpreter found. Exiting."
exit 1
fi
#
# These aren't fatal, but we want to note them to the user.
# We don't warn on the absence of 'wx' until later when we've
# determined that we actually need to try to invoke it.
#
[[ ! -x $CODEREVIEW ]] && print -u2 "WARNING: codereview(1) not found."
# Declare global total counters.
do
i) iflag=1
o) oflag=1
p) pflag=1
#
# If -l has been specified, we need to abort further options
# processing, because subsequent arguments are going to be
# arguments to 'putback -n'.
#
l) lflag=1
break;;
w) wflag=1;;
O) Oflag=1;;
?) usage;;
esac
done
fi
#
# If this manually set as the parent, and it appears to be an earlier webrev,
#
if [[ -n $pflag && -d $codemgr_parent/raw_files/new ]]; then
fi
if [[ $1 == "-" ]]; then
flist_mode="stdin"
shift
elif [[ -n $1 ]]; then
if [[ ! -r $1 ]]; then
print -u2 "$1: no such file or not readable"
fi
flist_mode="file"
flist_file=$1
shift
else
flist_mode="auto"
fi
fi
#
# Before we go on to further consider -l and -w, work out which SCM we think
# is in use.
#
print -u2 "Unable to determine SCM type currently in use."
print -u2 "For teamware: webrev looks for \$CODEMGR_WS either in"
print -u2 " the environment or in the file list."
exit 1
fi
if [[ -n $lflag ]]; then
#
# If the -l flag is given instead of the name of a file list,
# then generate the file list by extracting file names from a
# putback -n.
#
flist_from_teamware "$*"
shift $#
elif [[ -n $wflag ]]; then
#
# If the -w is given then assume the file list is in Bonwick's "wx"
# command format, i.e. pathname lines alternating with SCCS comment
# lines with blank lines as separators. Use the SCCS comments later
# in building the index.html file.
#
wxfile=$1
if [[ -z $wxfile && -n $CODEMGR_WS ]]; then
if [[ -r $CODEMGR_WS/wx/active ]]; then
fi
fi
"be auto-detected (check \$CODEMGR_WS)" && exit 1
if [[ -n "$*" ]]; then
shift
fi
print -u2 " File list from: standard input"
print -u2 " File list from: $flist_file"
fi
if [[ $# -gt 0 ]]; then
print -u2 "WARNING: unused arguments: $*"
fi
#
# Parent (internally $codemgr_parent) and workspace ($codemgr_ws) can
# be set in a number of ways, in decreasing precedence:
#
# 1) on the command line (only for the parent)
# 2) in the user environment
# 3) in the flist
# 4) automatically based on the workspace (only for the parent)
#
#
# Here is case (2): the user environment
#
[[ -z $codemgr_ws && -n $CODEMGR_WS ]] && codemgr_ws=$CODEMGR_WS
if [[ -n $codemgr_ws && ! -d $codemgr_ws ]]; then
print -u2 "$codemgr_ws: no such workspace"
exit 1
fi
[[ -z $codemgr_parent && -n $CODEMGR_PARENT ]] && \
if [[ -n $codemgr_parent && ! -d $codemgr_parent ]]; then
print -u2 "$codemgr_parent: no such directory"
exit 1
fi
#
# If we're in auto-detect mode and we haven't already gotten the file
# list, then see if we can get it by probing for wx.
#
if [[ ! -x $WX ]]; then
print -u2 "WARNING: wx not found!"
fi
#
# We need to use wx list -w so that we get renamed files, etc.
# but only if a wx active file exists-- otherwise wx will
# hang asking us to initialize our wx information.
#
if [[ -x $WX && -f $codemgr_ws/wx/active ]]; then
print -u2 " File list from: 'wx list -w' ... \c"
$WX comments > /tmp/$$.wx_comments
wxfile=/tmp/$$.wx_comments
print -u2 "done"
fi
fi
#
# If by hook or by crook we've gotten a file list by now (perhaps
# from the command line), eval it to extract environment variables from
# it: This is step (3).
#
#
# Continuing step (3): If we still have no file list, we'll try to get
# it from teamware.
#
if [[ -z $flist_done ]]; then
fi
#
# Observe true directory name of CODEMGR_WS, as used later in
# webrev title.
#
codemgr_ws=$(cd $codemgr_ws;print $PWD)
#
# (4) If we still don't have a value for codemgr_parent, get it
# from workspace.
#
[[ -z $codemgr_parent ]] && codemgr_parent=`workspace parent`
if [[ ! -d $codemgr_parent ]]; then
print -u2 "$CODEMGR_PARENT: no such parent workspace"
exit 1
fi
#
# Reset CODEMGR_WS to make sure teamware commands are happy.
#
fi
#
# If the user didn't specify a -i option, check to see if there is a
# webrev-info file in the workspace directory.
#
iflag=1
INCLUDE_FILE="$CWS/webrev-info"
fi
if [[ -n $iflag ]]; then
if [[ ! -r $INCLUDE_FILE ]]; then
"not readable."
exit 1
else
#
# $INCLUDE_FILE may be a relative path, and the script alters
# PWD, so we just stash a copy in /tmp.
#
cp $INCLUDE_FILE /tmp/$$.include
fi
fi
#
# Output directory.
#
#
# Name of the webrev, derived from the workspace name; in the
# future this could potentially be an option.
#
if [ "${WDIR%%/*}" ]; then
fi
if [[ ! -d $WDIR ]]; then
[[ $? != 0 ]] && exit 1
fi
#
# Summarize what we're going to do.
#
print " Workspace: $CWS"
if [[ -n $parent_webrev ]]; then
print "Compare against: webrev at $parent_webrev"
else
print "Compare against: $PWS"
fi
[[ -n $INCLUDE_FILE ]] && print " Including: $INCLUDE_FILE"
print " Output to: $WDIR"
#
# Save the file list in the webrev dir
#
#
# Bug IDs will be replaced by a URL. Order of precedence
# is: default location, $WEBREV_BUGURL, the -O flag.
#
[[ -n $WEBREV_BUGURL ]] && BUGURL="$WEBREV_BUGURL"
#
# Likewise, ARC cases will be replaced by a URL. Order of precedence
# is: default, $WEBREV_SACURL, the -O flag.
#
# Note that -O also triggers different substitution behavior for
# SACURL. See sac2url().
#
[[ -n $WEBREV_SACURL ]] && SACURL="$WEBREV_SACURL"
print " Output Files:"
#
# Clean up the file list: Remove comments, blank lines and env variables.
#
FLIST=/tmp/$$.flist.clean
#
# First pass through the files: generate the per-file webrev HTML-files.
#
do
set - $LINE
P=$1
#
# Normally, each line in the file list is just a pathname of a
# file that has been modified or created in the child. A file
# that is renamed in the child workspace has two names on the
# line: new name followed by the old name.
#
oldname=""
oldpath=""
if [[ $# -eq 2 ]]; then
PP=$2 # old filename
rename=1
fi
DIR=${P%/*}
if [[ $DIR == $P ]]; then
fi
F=${P##*/}
else
DIR=${P%/*}
fi
F=${P##*/}
PP=$P
PF=$F
fi
COMM=`getcomments html $P $PP`
continue
fi
print "\t$P$oldname\n\t\t\c"
# Make the webrev mirror directory if necessary
# cd to the directory so the names are short
#
# If we're in OpenSolaris mode, we enforce a minor policy:
# help to make sure the reviewer doesn't accidentally publish
# source which is in usr/closed/* or deleted_files/usr/closed/*
#
pdeleted=${P##deleted_files/usr/closed/}
print "*** Omitting closed source for OpenSolaris" \
"mode review"
continue
fi
fi
#
# We stash old and new files into parallel directories in /tmp
# and do our diffs there. This makes it possible to generate
# clean looking diffs which don't have absolute paths present.
#
# If the child's version doesn't exist then
# get a readonly copy.
if [[ ! -f $F && -f SCCS/s.$F ]]; then
fi
#
# Snag new version of file.
#
#
# Get the parent's version of the file. First see whether the
# child's version is checked out and get the parent's version
# with keywords expanded or unexpanded as appropriate.
#
if [ -f "SCCS/p.$F" ]; then
else
fi
else
# Parent is not a real workspace, but just a raw
# directory tree - use the file that's there as
# the old file.
fi
fi
fi
print "*** Error: file not in parent or child"
continue
fi
if [[ $? == 0 && $rename == 1 ]]; then
fi
#
# If we have old and new versions of the file then run the appropriate
# diffs. This is complicated by a couple of factors:
#
# - renames must be handled specially: we emit a 'remove'
# diff and an 'add' diff
# - new files and deleted files must be handled specially
# - Solaris patch(1m) can't cope with file creation
# (and hence renames) as of this writing.
# - To make matters worse, gnu patch doesn't interpret the
# output of Solaris diff properly when it comes to
# adds and deletes. We need to do some "cleansing"
# transformations:
# [to add a file] @@ -1,0 +X,Y @@ --> @@ -0,0 +X,Y @@
# [to del a file] @@ -X,Y +1,0 @@ --> @@ -X,Y +0,0 @@
#
cleanse_rmfile="sed 's/^\(@@ [0-9+,-]*\) [0-9+,-]* @@$/\1 +0,0 @@/'"
cleanse_newfile="sed 's/^@@ [0-9+,-]* \([0-9+,-]* @@\)$/@@ -0,0 \1/'"
if [[ -z $rename ]]; then
else
fi
else
fi
#
# Tack the patch we just made onto the accumulated patch for the
# whole wad.
#
print " patch\c"
if [[ -f $ofile && -f $nfile && -z $mv_but_nodiff ]]; then
print " cdiffs\c"
print " udiffs\c"
if [[ -x $WDIFF ]]; then
$WDIR/$DIR/$F.wdiff.html 2>/dev/null
if [[ $? -eq 0 ]]; then
print " wdiffs\c"
else
print " wdiffs[fail]\c"
fi
fi
print " sdiffs\c"
print " frames\c"
elif [[ -f $ofile && -f $nfile && -n $mv_but_nodiff ]]; then
# renamed file: may also have differences
elif [[ -f $nfile ]]; then
# new file: count added lines
elif [[ -f $ofile ]]; then
# old file: count deleted lines
fi
#
# Now we generate the postscript for this file. We generate diffs
# only in the event that there is delta, or the file is new (it seems
# tree-killing to print out the contents of deleted files).
#
if [[ -f $nfile ]]; then
if [[ -z $mv_but_nodiff ]]; then
textcomm=`getcomments text $P $PP`
if [[ -x $CODEREVIEW ]]; then
if [[ $? -eq 0 ]]; then
print " ps\c"
else
print " ps[fail]\c"
fi
fi
fi
fi
if [[ -f $ofile && -z $mv_but_nodiff ]]; then
print " old\c"
fi
if [[ -f $nfile ]]; then
print " new\c"
fi
print
done
print " Generating PDF: Skipped: no output available"
elif [[ -x $CODEREVIEW && -x $PS2PDF ]]; then
print " Generating PDF: \c"
print "Done."
else
print " Generating PDF: Skipped: missing 'ps2pdf' or 'codereview'"
fi
# If we're in OpenSolaris mode and there's a closed dir under $WDIR,
# delete it - prevent accidental publishing of closed source
fi
# Now build the index.html file that contains
# links to the source files and their diffs.
cd $CWS
# Save total changed lines for Code Inspection.
print " index.html: \c"
exec 3<&1 # duplicate stdout to FD3.
exec 1<&- # Close stdout.
exec > $INDEXFILE # Open stdout to index file.
print "<title>$WNAME</title>"
print "</head>"
print "<body id=\"SUNWwebrev\">"
print "<div class=\"summary\">"
print "<h2>Code Review for $WNAME</h2>"
print "<table>"
#
# Figure out the username and gcos name. To maintain compatibility
# with passwd(4), we must support '&' substitutions.
#
realname=`print $realname | sed s/\&/$userupper/`
print "<tr><th>Prepared by:</th>"
fi
print "<tr><th>Workspace:</th><td>$CWS</td></tr>"
print "<tr><th>Compare against:</th><td>"
if [[ -n $parent_webrev ]]; then
print "webrev at $parent_webrev"
else
print "$PWS"
fi
print "</td></tr>"
print "<tr><th>Summary of changes:</th><td>"
print "</td></tr>"
print "<tr><th>Patch of changes:</th><td>"
fi
print "<tr><th>Printable review:</th><td>"
fi
print "<tr><th>Author comments:</th><td><div>"
print "</div></td></tr>"
fi
print "</table>"
print "</div>"
#
# Second pass through the files: generate the rest of the index file
#
do
set - $LINE
P=$1
if [[ $# == 2 ]]; then
PP=$2
else
PP=$P
oldname=""
fi
DIR=${P%/*}
if [[ $DIR == $P ]]; then
fi
# Avoid processing the same file twice.
# It's possible for renamed files to
# appear twice in the file list
F=$WDIR/$P
print "<p>"
# If there's a diffs file, make diffs links
if [[ -f $F.cdiff.html ]]; then
print "<a href=\"$P.cdiff.html\">Cdiffs</a>"
print "<a href=\"$P.udiff.html\">Udiffs</a>"
if [[ -f $F.wdiff.html && -x $WDIFF ]]; then
print "<a href=\"$P.wdiff.html\">Wdiffs</a>"
fi
print "<a href=\"$P.sdiff.html\">Sdiffs</a>"
print "<a href=\"$P.frames.html\">Frames</a>"
else
print " ------ ------ ------"
if [[ -x $WDIFF ]]; then
print " ------"
fi
print " ------"
fi
# If there's an old file, make the link
if [[ -f $F-.html ]]; then
print "<a href=\"$P-.html\">Old</a>"
else
print " ---"
fi
# If there's an new file, make the link
if [[ -f $F.html ]]; then
print "<a href=\"$P.html\">New</a>"
else
print " ---"
fi
if [[ -f $F.patch ]]; then
print "<a href=\"$P.patch\">Patch</a>"
else
print " -----"
fi
else
print " ---"
fi
print "<b>$P</b> $oldname"
#
# Check for usr/closed and deleted_files/usr/closed
#
$P == deleted_files/usr/closed/* ]]; then
print " <i>Closed source: omitted from" \
"this review</i>"
fi
fi
print "</p>"
# Insert delta comments
print "<blockquote><pre>"
getcomments html $P $PP
print "</pre>"
# Add additional comments comment
print "<!-- Add comments to explain changes in $P here -->"
# Add count of changes.
if [[ -f $F.count ]]; then
fi
print "</blockquote>"
done
print
print
print "<hr />"
print "<p style=\"font-size: small\">"
print "This code review page was prepared using <b>$0</b>"
print "(vers $WEBREV_UPDATED)."
print "Webrev is maintained by the <a href=\"http://www.opensolaris.org\">"
print "OpenSolaris</a> project. The latest version may be obtained"
print "<a href=\"http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/tools/scripts/webrev.sh\">here</a>.</p>"
print "</body>"
print "</html>"
exec 1<&- # Close FD 1.
exec 1<&3 # dup FD 3 to restore stdout.
exec 3<&- # close FD 3.
print "Done."