0N/AThe contents of this file are subject to the terms of the
1281N/ACommon Development and Distribution License (the "License").
0N/AYou may not use this file except in compliance with the License.
0N/Alanguage governing permissions and limitations under the License.
0N/AWhen distributing Covered Code, include this CDDL HEADER in each
0N/AIf applicable, add the following below this CDDL HEADER, with the
0N/Afields enclosed by brackets "[]" replaced with your own identifying
0N/Ainformation: Portions Copyright [yyyy] [name of copyright owner]
830N/ACopyright 2009 Sun Microsystems, Inc. All rights reserved.
0N/AUse is subject to license terms.
1186N/APortions Copyright 2011 Jens Elkner.
1388N/Aprivate static final String getAnnotateRevision(DiffData dd) {
1468N/A // let the client side know, which revision is shown if it is a single file
1468N/A/** Info container for hidden blocks */
1468N/A /** line# of the first line of the leading block */
1468N/A /** number of lines in the leading block */
1468N/A /** number of lines in the hidden block */
1468N/A /** number of lines in the trailing block */
1468N/A /** buffer which contains the formatted line numbers after hidden lines */
1468N/A /** buffer which contains the formatted source lines after hidden lines */
1468N/A /** if {@code true} dump all,
i.e. no hidden lines */
1468N/A * Create a new instance with initialized StringBuilders
1468N/A * @param full if {@code true} dump all,
i.e. no hidden lines *
1468N/A public Hidden(boolean full) {
1468N/A bn = new StringBuilder(32);
1468N/A bs = new StringBuilder(256);
1468N/A * Reset and prepare buffers to take new content.
1468N/A * @param start line# of the first line of the leading block
1468N/A * @param leading Number of leading lines
1468N/A * @param hidden Number of lines in the hidden block
1468N/A * @param trailing Number of trailing lines
1468N/A public void reset(int start, int leading, int hidden, int trailing) {
1468N/A return "{ start=" + start + "; leading=" + leading + "; hidden=" + hidden
1468N/A + "; trailing=" + trailing + "; full=" + full
1468N/A * Dump unchanged lines of a file. lines get htmlized.
1468N/A * @param line Current line# (start of dump)
1468N/A * @param howMany Number of lines to dump.
1468N/A * @param trailing Number of trailing lines to print after a "hidden" block
1468N/A * @param file Source code lines of the file to partially dump.
1468N/A * @param bn Where to append formatted line numbers
1468N/A * @param bs Where to append dumped formatted source code lines
1468N/A * @param h Where to store info about leading, hidden, trailing blocks
1468N/A * @param a If {code true}, line numbers get an anchor named with the line#
1468N/A * (can't use IDs instead of name, because IDs need to be unique)
1468N/A * @return line# + 1 of the last line dumped
1388N/A * @throws IndexOutOfBoundsException if <var>file</var> contains less than
1468N/A * <var>line</var> + <var>howMany</var> entries.
1388N/Aprivate static final int dumpFile(int line, int howMany, int trailing,
1468N/A String[] file, StringBuilder bn, StringBuilder bs, Hidden h, boolean a)
1468N/A // if we have fewer lines than leading+trailing+min_hidden lines, dump all
1468N/A for (;line < max; line++) {
1388N/A .append(line).append("</a>\n");
1468N/A for (int j = line; j < line + 8; j++) {
1388N/A .append(j).append("</a>\n");
1468N/A h.reset(line, 8, howMany - 8 - trailing, trailing); // hidden block (row n+1)
1468N/A // trailing block (row n+2)
1468N/A line += howMany - trailing ;
1468N/A for (; line < max; line++) {
1388N/A .append(line).append("</a>\n");
1468N/A * Dump a chunk of deleted or added source lines. lines get not htmlized.
1468N/A * @param cn line# of the first line in the file to format (start of dump)
1468N/A * @param cl line# of the last line in the file to format (end of dump)
1468N/A * @param line line# of the new file, which corresponds to <var>cn</var>
1468N/A * @param file file from which the chunk should be dumped
1468N/A * @param bn where to store formatted line numbers
1468N/A * @param bs where to store formatted source code
1468N/A * @param a if {code true}, line numbers get an anchor named with the line#
1468N/A * (can't use IDs instead of name, because IDs need to be unique)
1468N/A * @return line# + 1 of the last line dumped
1468N/Aprivate static final int dumpChunk(int cn, int cl, int line, String[] file,
1388N/A StringBuilder bn, StringBuilder bs, boolean a)
1468N/A for (int j = cn - 1; j < cl ; j++, line++) {
1388N/A .append(line).append("</a>\n");
1468N/A private static final String getHiddenBlockInfo(Hidden h, DiffData dd) {
1468N/A * Dump a sequence of numbers.
1468N/A * @param n first number to dump
1468N/A * @param count # of numbers to dump
1468N/A * @param bn buffer to use. Gets reset before appending stuff.
1468N/A * @return last number dumped + 1
1468N/Aprivate static final int genNums(int n, int count, StringBuilder bn) {
1465N/Aprivate static final String basename(String path) {
1468N/A <h3 class="error">Error:</h3>
1281N/A<div id="src">Diffs for binary files cannot be displayed! Files are <a
1388N/A <%= getAnnotateRevision(dd) %>
1388N/A <b>No differences found!</b><%
1388N/A //-------- Do THE DIFFS ------------
1388N/A<%= getAnnotateRevision(dd) %>
1388N/A <span class="m">Deleted</span>
1388N/A <span class="p">Added</span>
1388N/A %>&full=1">full</a></span>
1388N/A <span class="active dbformat">compact</span><%
1388N/A <span class="active dbformat">full</span>
1388N/A %>&full=0">compact</a></span><%
1468N/A StringBuilder bs1 = new StringBuilder(256); // formatted source lines file1
1468N/A StringBuilder bs2 = new StringBuilder(256); // formatted source lines file2
1468N/A StringBuilder bn1 = new StringBuilder(32); // formatted line#s file1
1468N/A StringBuilder bn2 = new StringBuilder(32); // formatted line#s file2
1468N/A int ln1 = 1; // next line of file1 to process
1468N/A int ln2 = 1; // next line of file2 to process
1468N/A String[] file1 =
dd.file[0]; // source lines of the 'old' file
1468N/A String[] file2 =
dd.file[1]; // source lines of the 'new' file
1468N/A Hidden h1 = new Hidden(
dd.full); // hidden line info + trailing stuff file1
1468N/A Hidden h2 = new Hidden(
dd.full); // hidden line info + trailing stuff file2
1468N/A lna = new StringBuilder(32); // buffer for line#s
1468N/A int cl1 =
c1.last() + 1; // line# of the last line of chunk file1
1468N/A int cl2 =
c2.last() + 1; // line# of the last line of chunk file2
1468N/A int i1 = cn1 - 1, i2 = cn2 - 1; // current line# in file1, file2
1468N/A for (; i1 < cl1 && i2 < cl2; i1++, i2++) {
1468N/A // To Dump flag: if == 1 normal, if == 2 sdiff, if == 3 wdiff row
1388N/A String tClass = " class='dtk'";
1468N/A ln1 = dumpFile(ln1, cn1 - ln1, 8, file1, bn2, bs2, h2, true);
1468N/A ln2 = dumpFile(ln2, cn2 - ln2, 8, file2, bn2, bs2, h2, true);
1468N/A } else if (like_udiff && (cn1 > ln1 || cn2 > ln2)) {
1468N/A ln2 = dumpFile(ln2, cn2 - ln2, 8, file2, bn2, bs2, h2, true);
1468N/A // h1 is not needed, so we abuse it to store linenums
1468N/A h1.full |= cn2 - ln2 + 1 < 20; // force same dump strategy for both
1468N/A ln1 = dumpFile(ln1, cn1 - ln1, 8, file1, bn1, bs1, h1, false);
1468N/A ln2 = dumpFile(ln2, cn2 - ln2, 8, file2, bn2, bs2, h2, true);
1388N/A <td class="dtn"><%= bn1 %></td>
1388N/A <td class="dts"><%= bs1 %></td><%
1388N/A <td class="dtn"><%= bn2 %></td>
1388N/A <td class="dts"><%= bs2 %></td>
1468N/A<tr class="dtl" id="hi_<%= i %>"><%
1468N/A String txt = getHiddenBlockInfo(h2, dd);
1468N/A <td class="dth" colspan="2"><%= txt %></td><%
1468N/A <td class="dth" colspan="2"><%= txt %></td><%
1468N/A <td class="dth" colspan="3"><%= getHiddenBlockInfo(h2, dd) %></td>
1468N/A<tr class="dte" id="hs_<%= i %>">
1468N/A <td class="dtn"><%= lna %></td>
1468N/A <td class="dtn"><%= bn1 %></td>
1468N/A <td class="dts"><%= bs1 %></td>
1388N/A tdClass = "dtm"; tClass = "";
1388N/A ln1 = dumpChunk(cn1, cl1, ln1, file1, bn2, bs2, true);
1388N/A ln2 = dumpChunk(cn2, cl2, ln2, file2, bn2, bs2, true);
1388N/A ln1 = dumpChunk(cn1, cl1, ln1, file1, bn2, bs2, false);
1388N/A <td class="dts"><%= bs2 %></td>
1388N/A ln2 = dumpChunk(cn2, cl2, ln2, file2, bn2, bs2, true);
1388N/A && (cn1 <= cl1 || cn2 <= cl2))
1388N/A ln1 = dumpChunk(cn1, cl1, ln1, file1, bn1, bs1, false);
1388N/A ln2 = dumpChunk(cn2, cl2, ln2, file2, bn2, bs2, true);
1388N/A <td class="dtm"><%= bn1 %></td>
1388N/A <td class="dts"><%= bs1 %></td><%
1388N/A <td class="<%= tdClass %>"><%= bn2 %></td>
1388N/A <td class="dts"><%= bs2 %></td>
1468N/A // deltas done, dump the remaining - the same as in the first part
1468N/A // of the loop, but without a trailing block
1468N/A // h1 is not needed, so we abuse it to store linenums
1388N/A <td class="dtn"><%= bn1 %></td>
1388N/A <td class="dts"><%= bs1 %></td><%
1388N/A <td class="dtn"><%= bn2 %></td>
1388N/A <td class="dts"><%= bs2 %></td>
1468N/A String txt = getHiddenBlockInfo(h2, dd);
1468N/A <td class="dth" colspan="2"><%= txt %></td><%
1468N/A <td class="dth" colspan="2"><%= txt %></td><%
1468N/A <td class="dth" colspan="3"><%= getHiddenBlockInfo(h2, dd) %></td>
1468N/A <td class="dtn"><%= lna %></td>
1468N/A <td class="dtn"><%= bn1 %></td>
1468N/A <td class="dts"><%= bs1 %></td>
1468N/A // trailing block is always empty, since last