diff.jsp revision 1281
1281N/A<%--
1186N/A$Id$
1186N/A
0N/ACDDL HEADER START
0N/A
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/A
0N/ASee LICENSE.txt included in this distribution for the specific
0N/Alanguage governing permissions and limitations under the License.
0N/A
0N/AWhen distributing Covered Code, include this CDDL HEADER in each
0N/Afile and include the License file at LICENSE.txt.
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]
0N/A
0N/ACDDL HEADER END
0N/A
830N/ACopyright 2009 Sun Microsystems, Inc. All rights reserved.
0N/AUse is subject to license terms.
0N/A
1186N/APortions Copyright 2011 Jens Elkner.
1186N/A--%><%@page import="
1186N/Ajava.io.BufferedReader,
1186N/Ajava.io.FileNotFoundException,
1186N/Ajava.io.InputStream,
1186N/Ajava.io.InputStreamReader,
1186N/Ajava.io.UnsupportedEncodingException,
1186N/Ajava.net.URLDecoder,
1186N/Ajava.util.ArrayList,
0N/A
1186N/Aorg.apache.commons.jrcs.diff.Chunk,
1186N/Aorg.apache.commons.jrcs.diff.Delta,
1186N/Aorg.apache.commons.jrcs.diff.Diff,
1186N/Aorg.apache.commons.jrcs.diff.Revision,
1186N/Aorg.opensolaris.opengrok.analysis.AnalyzerGuru,
0N/Aorg.opensolaris.opengrok.analysis.FileAnalyzer.Genre,
1186N/Aorg.opensolaris.opengrok.web.DiffData,
1186N/Aorg.opensolaris.opengrok.web.DiffType"
1186N/A%><%!
1186N/Aprivate String getAnnotateRevision(DiffData data) {
1281N/A if (data.type == DiffType.OLD || data.type == DiffType.NEW) {
1281N/A return "<script type=\"text/javascript\">/* <![CDATA[ */ "
1281N/A + "document.rev = 'r=" + data.rev[data.type == DiffType.NEW ? 1 : 0]
1281N/A + "'; /* ]]> */</script>";
1281N/A }
1281N/A return "";
1186N/A}
1186N/A%><%@
0N/A
1186N/Ainclude file="mast.jsp"
0N/A
0N/A%><%
1186N/A/* ---------------------- diff.jsp start --------------------- */
1186N/A{
1281N/A cfg = PageConfig.get(request);
1281N/A DiffData data = cfg.getDiffData();
1281N/A
1281N/A if (data.errorMsg != null) {
0N/A
1186N/A%>
1186N/A<div class="src">
1281N/A <h3 class="error">Error:</h3>
1281N/A <p><%= data.errorMsg %></p>
1186N/A</div><%
1186N/A
1281N/A } else if (data.genre == Genre.IMAGE) {
170N/A
1281N/A String link = request.getContextPath() + Prefix.RAW_P
1281N/A + Util.htmlize(cfg.getPath());
1186N/A%>
1186N/A<div id="difftable">
1281N/A <table class="image">
1281N/A <thead>
1281N/A <tr><th><%= data.filename %> (revision <%= data.rev[0] %>)</th>
1281N/A <th><%= data.filename %> (revision <%= data.rev[1] %>)</th>
1281N/A </tr>
1281N/A </thead>
1281N/A <tbody>
1281N/A <tr><td><img src="<%= link %>?r=<%= data.rev[0] %>"/></td>
1281N/A <td><img src="<%= link %>?r=<%= data.rev[1] %>"/></td>
1281N/A </tr>
1281N/A </tbody>
1281N/A </table>
1186N/A</div><%
170N/A
1281N/A } else if (data.genre != Genre.PLAIN && data.genre != Genre.HTML) {
170N/A
1281N/A String link = request.getContextPath() + Prefix.RAW_P
1281N/A + Util.htmlize(cfg.getPath());
1186N/A%>
1281N/A<div id="src">Diffs for binary files cannot be displayed! Files are <a
1281N/A href="<%= link %>?r=<%= data.rev[0] %>"><%=
1281N/A data.filename %>(revision <%= data.rev[0] %>)</a> and <a
1281N/A href="<%= link %>?r=<%= data.rev[1] %>"><%=
1281N/A data.filename %>(revision <%= data.rev[1] %>)</a>.
0N/A</div><%
0N/A
1281N/A } else if (data.revision.size() == 0) {
1281N/A %>
1281N/A <%= getAnnotateRevision(data) %>
1281N/A <b>No differences found!</b><%
1281N/A
1281N/A } else {
1281N/A //-------- Do THE DIFFS ------------
1281N/A int ln1 = 0;
1281N/A int ln2 = 0;
1281N/A String rp1 = data.param[0];
1281N/A String rp2 = data.param[1];
1281N/A String reqURI = request.getRequestURI();
1281N/A String[] file1 = data.file[0];
1281N/A String[] file2 = data.file[1];
1281N/A
1281N/A DiffType type = data.type;
1281N/A boolean full = data.full;
1186N/A%>
1186N/A<%= getAnnotateRevision(data) %>
1186N/A<div id="diffbar">
1281N/A <div class="legend">
1281N/A <span class="d">Deleted</span>
1281N/A <span class="a">Added</span>
1281N/A </div>
1281N/A <div class="tabs"><%
1281N/A for (DiffType t : DiffType.values()) {
1281N/A if (type == t) {
1281N/A %> <span class="active"><%= t.toString() %><%
1281N/A if (t == DiffType.OLD) {
1281N/A %> ( <%= data.rev[0] %> )<%
1281N/A } else if (t == DiffType.NEW) {
1281N/A %> ( <%= data.rev[1] %> )<%
1281N/A }
1281N/A %></span><%
1281N/A } else {
1281N/A %> <span><a href="<%= reqURI %>?r1=<%= rp1 %>&amp;r2=<%= rp2
1281N/A %>&amp;format=<%= t.getAbbrev() %>&amp;full=<%= full ? '1' : '0'
1281N/A %>"><%= t.toString() %><%
1281N/A if (t == DiffType.OLD) {
1281N/A %> ( <%= data.rev[0] %> )<%
1281N/A } else if (t == DiffType.NEW) {
1281N/A %> ( <%= data.rev[1] %> )<%
1281N/A }
1281N/A %></a></span><%
1281N/A }
1281N/A }
1281N/A %></div>
1281N/A <div class="ctype"><%
1281N/A if (!full) {
1281N/A %>
1281N/A <span><a href="<%= reqURI %>?r1=<%= rp1 %>&amp;r2=<%= rp2
1281N/A %>&amp;format=<%= type.getAbbrev() %>&amp;full=1">full</a></span>
1281N/A <span class="active">compact</span><%
1281N/A } else {
1281N/A %>
1281N/A <span class="active">full</span>
1281N/A <span> <a href="<%= reqURI %>?r1=<%= rp1 %>&amp;r2=<%= rp2
1281N/A %>&amp;format=<%= type.getAbbrev() %>&amp;full=0">compact</a></span><%
1281N/A }
1281N/A %></div>
1186N/A</div>
1168N/A
1186N/A<div id="difftable">
1281N/A <div class="pre"><%
1281N/A if (type == DiffType.SIDEBYSIDE || type == DiffType.UNIFIED) {
1281N/A %><table class="plain"><%
1281N/A if (type == DiffType.SIDEBYSIDE) {
1281N/A %>
1281N/A <thead><tr>
1281N/A <th><%= data.filename %> (<%= data.rev[0] %>)</th>
1281N/A <th><%= data.filename %> (<%= data.rev[1] %>)</th>
1281N/A </tr></thead><%
1281N/A }
1281N/A %>
1281N/A <tbody><%
1281N/A }
1281N/A
1281N/A for (int i=0; i < data.revision.size(); i++) {
1281N/A Delta d = data.revision.getDelta(i);
1281N/A if (type == DiffType.TEXT) {
1281N/A %><%= Util.htmlize(d.toString()) %><%
1281N/A } else {
1281N/A Chunk c1 = d.getOriginal();
1281N/A Chunk c2 = d.getRevised();
1281N/A int cn1 = c1.first();
1281N/A int cl1 = c1.last();
1281N/A int cn2 = c2.first();
1281N/A int cl2 = c2.last();
1281N/A
1281N/A int i1 = cn1, i2 = cn2;
1281N/A StringBuilder bl1 = new StringBuilder(80);
1281N/A StringBuilder bl2 = new StringBuilder(80);
1281N/A for (; i1 <= cl1 && i2 <= cl2; i1++, i2++) {
1281N/A Util.htmlize(file1[i1], bl1);
1281N/A Util.htmlize(file2[i2], bl2);
1281N/A String[] ss = Util.diffline(bl1, bl2);
1281N/A file1[i1] = ss[0];
1281N/A file2[i2] = ss[1];
1281N/A bl1.setLength(0);
1281N/A bl2.setLength(0);
1281N/A }
1281N/A // deleted
1281N/A for (; i1 <= cl1; i1++) {
1281N/A bl1.setLength(0);
1281N/A bl1.append("<span class=\"d\">");
1281N/A Util.htmlize(file1[i1], bl1);
1281N/A file1[i1] = bl1.append("</span>").toString();
1281N/A }
1281N/A // added
1281N/A for (; i2 <= cl2; i2++) {
1281N/A bl2.setLength(0);
1281N/A bl2.append("<span class=\"a\">");
1281N/A Util.htmlize(file2[i2], bl2);
1281N/A file2[i2] = bl2.append("</span>").toString();
1281N/A }
1168N/A
1281N/A if (type == DiffType.UNIFIED) {
0N/A// UDIFF
1281N/A if (cn1 > ln1 || cn2 > ln2) {
1281N/A %>
1281N/A <tr class="k"><td><%
1281N/A if (full || (cn2 - ln2 < 20)) {
1281N/A for (int j = ln2; j < cn2; j++) {
1281N/A %><i><%= ++ln2 %></i><%=
1281N/A Util.htmlize(file2[j]) %><br/><%
1281N/A }
1281N/A } else {
1281N/A for (int j = ln2; j < ln2 + 8; j++) {
1281N/A %><i><%= j+1 %></i><%=
1281N/A Util.htmlize(file2[j]) %><br/><%
1281N/A }
1281N/A %><br/>--- <b><%= cn2 - ln2 - 16
1281N/A %> unchanged lines hidden</b> (<a href="<%= reqURI
1281N/A %>?r1=<%= rp1 %>&amp;r2=<%= rp2
1281N/A %>&amp;format=<%= type.getAbbrev()
1281N/A %>&amp;full=1#<%= ln2 %>">view full</a>) --- <br/><br/><%
1281N/A ln2 = cn2 - 8;
1281N/A for (int j = ln2; j < cn2; j++) {
1281N/A %><i><%= ++ln2 %></i><%= Util.htmlize(file2[j]) %><br/><%
1281N/A }
1281N/A }
1281N/A %></td>
1281N/A </tr><%
1281N/A ln1 = cn1;
1281N/A }
1281N/A if (cn1 <= cl1) {
1281N/A %>
1281N/A <tr><td><%
1281N/A for (int j = cn1; j <= cl1 ; j++) {
1281N/A %><del class="d"><%= ++ln1 %></del><%= file1[j]
1281N/A %><br/><%
1281N/A }
1281N/A %></td>
1281N/A </tr><%
1281N/A }
1281N/A if (cn2 <= cl2) {
1281N/A %>
1281N/A <tr class="k"><td><%
1281N/A for (int j = cn2; j < cl2; j++) {
1281N/A %><i class="a"><%= ++ln2 %></i><%= file2[j]
1281N/A %><br/><%
1281N/A }
1281N/A %><i class="a"><%= ++ln2 %></i><%= file2[cl2] %><%
1281N/A if(full) {
1281N/A %><a name="<%= ln2 %>" /><%
1281N/A }
1281N/A %></td>
1281N/A </tr><%
1281N/A }
1281N/A } else if (type == DiffType.SIDEBYSIDE) {
1186N/A// SDIFF
1281N/A if (cn1 > ln1 || cn2 > ln2) {
1281N/A %>
1281N/A <tr class="k"><td><%
1281N/A if (full || cn2 - ln2 < 20) {
1281N/A for (int j = ln1; j < cn1; j++) {
1281N/A %><i><%= ++ln1 %></i><%=
1281N/A Util.htmlize(file1[j]) %><br/><%
1281N/A }
1281N/A %></td><td><%
1281N/A for (int j = ln2; j < cn2 ; j++) {
1281N/A %><i><%= ++ln2 %></i><%=
1281N/A Util.htmlize(file2[j]) %><br/><%
1281N/A }
1281N/A } else {
1281N/A for (int j = ln1; j < ln1 + 8; j++) {
1281N/A %><i><%= j+1 %></i><%=
1281N/A Util.htmlize(file1[j]) %><br/><%
1281N/A }
1281N/A %><br/>--- <b><%= cn1 - ln1 - 16
1281N/A %> unchanged lines hidden</b> (<a href="<%= reqURI
1281N/A %>?r1=<%= rp1 %>&amp;r2=<%= rp2
1281N/A %>&amp;format=<%= type.getAbbrev()
1281N/A %>&amp;full=1#<%= ln2 %>">view full</a>) --- <br/><br/><%
1281N/A ln1 = cn1 - 8;
1281N/A for (int j = ln1; j < cn1; j++) {
1281N/A %><i><%= ++ln1 %></i><%=
1281N/A Util.htmlize(file1[j]) %><br/><%
1281N/A }
1281N/A %></td><td><%
1281N/A for (int j = ln2; j < ln2 + 8; j++) {
1281N/A %><i><%= j+1 %></i><%=
1281N/A Util.htmlize(file2[j]) %><br/><%
1281N/A }
1281N/A %><br/>--- <b><%= cn2 - ln2 - 16
1281N/A %> unchanged lines hidden</b> (<a href="<%= reqURI
1281N/A %>?r1=<%= rp1 %>&amp;r2=<%= rp2
1281N/A %>&amp;format=<%= type.getAbbrev()
1281N/A %>&amp;full=1#<%= ln2 %>">view full</a>) --- <br/><br/><%
1281N/A ln2 = cn2 - 8;
1281N/A for (int j = ln2; j < cn2; j++) {
1281N/A %><i><%= ++ln2 %></i><%=
1281N/A Util.htmlize(file2[j]) %><br/><%
1281N/A }
1281N/A }
1281N/A %></td>
1281N/A </tr><%
1281N/A }
1281N/A %>
1281N/A <tr class="k"><td><%
1281N/A for (int j = cn1; j <= cl1; j++) {
1281N/A %><i><%= ++ln1 %></i><%= file1[j] %><br/><%
1281N/A }
1281N/A %></td><td><%
1281N/A for (int j = cn2; j <= cl2; j++) {
1281N/A %><i><%= ++ln2 %></i><a name="<%= ln2 %>"></a><%=
1281N/A file2[j] %><br/><%
1281N/A }
1281N/A %></td>
1281N/A </tr><%
1186N/A// OLD
1281N/A } else if (type == DiffType.OLD) {
1281N/A // OLD
1281N/A if (cn1 > ln1) {
1281N/A if (full || cn1 - ln1 < 20) {
1281N/A for (int j = ln1; j < cn1; j++) {
1281N/A %><i><%= ++ln1 %></i><%=
1281N/A Util.htmlize(file1[j]) %><br/><%
1281N/A }
1281N/A } else {
1281N/A for (int j = ln1; j < ln1 + 8; j++) {
1281N/A %><i><%= j+1 %></i><%=
1281N/A Util.htmlize(file1[j]) %><br/><%
1281N/A }
1281N/A %><br/>--- <b><%= cn1 - ln1 - 16
1281N/A %> unchanged lines hidden</b> (<a href="<%= reqURI
1281N/A %>?r1=<%= rp1 %>&amp;r2=<%= rp2
1281N/A %>&amp;format=<%= type.getAbbrev()
1281N/A %>&amp;full=1#<%=ln1%>">view full</a>) --- <br/><br/><%
1281N/A ln1 = cn1 - 8;
1281N/A for (int j = ln1; j < cn1; j++) {
1281N/A %><i><%= ++ln1 %></i><%=
1281N/A Util.htmlize(file1[j]) %><br/><%
1281N/A }
1281N/A }
1281N/A }
1281N/A for (int j = cn1; j <= cl1 ; j++) {
1281N/A %><i><%= ++ln1 %></i><%= file1[j] %><br/><%
1281N/A }
1281N/A if (full) {
1281N/A %><a name="<%=ln1%>" ></a><%
1281N/A }
1186N/A// NEW
1281N/A } else if (type == DiffType.NEW) {
1281N/A if (cn2 > ln2) {
1281N/A if (full || cn2 - ln2 < 20) {
1281N/A for (int j = ln2; j < cn2 ; j++) {
1281N/A %><i><%= ++ln2 %></i><%=
1281N/A Util.htmlize(file2[j]) %><br/><%
1281N/A }
1281N/A } else {
1281N/A for (int j = ln2; j < ln2 + 8; j++) {
1281N/A %><i><%= j+1 %></i><%=
1281N/A Util.htmlize(file2[j]) %><br/><%
1281N/A }
1281N/A %><br/>--- <b><%= cn2 - ln2 - 16
1281N/A %> unchanged lines hidden</b> (<a href="<%= reqURI
1281N/A %>?r1=<%= rp1 %>&amp;r2=<%= rp2
1281N/A %>&amp;format=<%= type.getAbbrev()
1281N/A %>&amp;full=1#<%= ln2 %>">view full</a>) --- <br/><br/><%
1281N/A ln2 = cn2 - 8;
1281N/A for (int j = ln2; j < cn2; j++) {
1281N/A %><i><%= ++ln2 %></i><%=
1281N/A Util.htmlize(file2[j]) %><br/><%
1281N/A }
1281N/A }
1281N/A }
1281N/A for (int j = cn2; j <= cl2 ; j++) {
1281N/A %><i><%= ++ln2 %></i><%= file2[j] %><br/><%
1281N/A }
1281N/A if (full) {
1281N/A %><a name="<%= ln2 %>"></a><%
1281N/A }
1281N/A }
1281N/A } // else
1281N/A } // for
1186N/A// deltas done, dump the remaining
1281N/A if (file1.length >= ln1) {
1281N/A if (type == DiffType.SIDEBYSIDE) {
1281N/A if (full || file1.length - ln1 < 20) {
1281N/A %>
1281N/A <tr><td><%
1281N/A for (int j = ln1; j < file1.length ; j++) {
1281N/A %><i><%= j+1 %></i><%= Util.htmlize(file1[j]) %><br/><%
1281N/A }
1281N/A %></td><td><%
1281N/A for (int j = ln2; j < file2.length ; j++) {
1281N/A %><i><%= j+1 %></i><%= Util.htmlize(file2[j]) %><br/><%
1281N/A }
1281N/A %></td>
1281N/A </tr>
1281N/A </tbody>
1281N/A </table><%
1281N/A } else {
1281N/A %>
1281N/A <tr><td><%
1281N/A for (int j = ln1; j < ln1 + 8 ; j++) {
1281N/A %><i><%= j+1 %></i><%= Util.htmlize(file1[j]) %><br/><%
1281N/A }
1281N/A %><br/> --- <b><%= file1.length - ln1 - 8
1281N/A %> unchanged lines hidden</b> --- </td><td><%
1281N/A for (int j = ln2; j < ln2 + 8 ; j++) {
1281N/A %><i><%= j+1 %></i><%= Util.htmlize(file2[j]) %><br/><%
1281N/A }
1281N/A %><br/>--- <b><%= file1.length - ln1 - 8
1281N/A %> unchanged lines hidden</b> ---</td>
1281N/A </tr>
1281N/A </tbody>
1281N/A </table><%
1281N/A }
1281N/A } else if (type == DiffType.UNIFIED) {
1281N/A if (full || file2.length - ln2 < 20) {
1281N/A %>
1281N/A <tr><td><%
1281N/A for (int j = ln2; j < file2.length ; j++) {
1281N/A %><i><%= j+1 %></i><%= Util.htmlize(file2[j]) %><br/><%
1281N/A }
1281N/A %></td>
1281N/A </tr>
1281N/A </tbody>
1281N/A </table><%
1281N/A } else {
1281N/A %>
1281N/A <tr><td><%
1281N/A for (int j = ln2; j < ln2 + 8 ; j++) {
1281N/A %><i><%= j+1 %></i><%= Util.htmlize(file2[j]) %><br/><%
1281N/A }
1281N/A %><br/>--- <b><%= file2.length - ln2 - 8
1281N/A %> unchanged lines hidden</b> ---</td>
1281N/A </tr>
1281N/A </tbody>
1281N/A </table><%
1281N/A }
1281N/A } else if (type == DiffType.OLD) {
1281N/A if (full || file1.length - ln1 < 20) {
1281N/A for (int j = ln1; j < file1.length ; j++) {
1281N/A %><i><%= j+1 %></i><%= Util.htmlize(file1[j]) %><br/><%
1281N/A }
1281N/A } else {
1281N/A for (int j = ln1; j < ln1 + 8 ; j++) {
1281N/A %><i><%= j+1 %></i><%= Util.htmlize(file1[j]) %><br/><%
1281N/A }
1281N/A %><br/> --- <b><%= file1.length - ln1 - 8
1281N/A %> unchanged lines hidden</b> ---<br/><%
1281N/A }
1281N/A } else if (type == DiffType.NEW) {
1281N/A if (full || file2.length - ln2 < 20) {
1281N/A for (int j = ln2; j < file2.length ; j++) {
1281N/A %><i><%= j+1 %></i><%=Util.htmlize(file2[j])%><br/><%
1281N/A }
1281N/A } else {
1281N/A for (int j = ln2; j < ln2 + 8 ; j++) {
1281N/A %><i><%= j+1 %></i><%= Util.htmlize(file2[j]) %><br/><%
1281N/A }
1281N/A %><br/> --- <b><%= file2.length - ln2 - 8
1281N/A %> unchanged lines hidden</b> ---<br/><%
1281N/A }
1281N/A }
1281N/A }
0N/A
1186N/A//----DIFFS Done--------
1281N/A %></div>
1186N/A</div><%
1281N/A }
1186N/A}
1186N/A/* ---------------------- diff.jsp end --------------------- */
1186N/A%><%@
0N/A
1186N/Ainclude file="foot.jspf"
0N/A
1186N/A%>