diff.jsp revision 1168
0N/A<%--
0N/ACDDL HEADER START
0N/A
0N/AThe contents of this file are subject to the terms of the
0N/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
0N/Aident "@(#)diff.jsp 1.2 05/12/01 SMI"
0N/A
0N/A--%><%@ page import = "javax.servlet.*,
0N/Ajava.lang.*,
0N/Ajavax.servlet.http.*,
0N/Ajava.util.*,
0N/Ajava.io.*,
0N/Ajava.text.*,
170N/Ajava.net.URLDecoder,
0N/Aorg.opensolaris.opengrok.analysis.*,
0N/Aorg.opensolaris.opengrok.analysis.FileAnalyzer.Genre,
0N/Aorg.opensolaris.opengrok.web.*,
0N/Aorg.opensolaris.opengrok.history.*,
0N/Aorg.apache.commons.jrcs.diff.*"
0N/A%><%@include file="mast.jsp"%><%!
0N/A
0N/AString readableLine(int n) {
0N/A if (n < 10) {
0N/A return " " + n;
0N/A } else {
0N/A return String.valueOf(n);
0N/A }
0N/A}
0N/A
0N/A%><%
0N/A
0N/Aif (valid) {
188N/A final String rp1 = request.getParameter("r1");
188N/A final String rp2 = request.getParameter("r2");
170N/A String srcRoot = environment.getSourceRootFile().getAbsolutePath();
170N/A
170N/A String r1 = null;
170N/A String r2 = null;
170N/A File rpath1 = null;
170N/A File rpath2 = null;
940N/A String[] tmp=null;
170N/A try {
940N/A if (rp1!=null) tmp = rp1.split("@");
170N/A if (tmp != null && tmp.length == 2) {
830N/A rpath1 = new File(srcRoot+URLDecoder.decode(tmp[0], "UTF-8"));
830N/A r1 = URLDecoder.decode(tmp[1], "UTF-8");
170N/A }
170N/A } catch (UnsupportedEncodingException e) {
170N/A }
170N/A
170N/A try {
940N/A if (rp2!=null) tmp = rp2.split("@");
170N/A if (tmp != null && tmp.length == 2) {
170N/A if (tmp != null && tmp.length == 2) {
830N/A rpath2 = new File(srcRoot+URLDecoder.decode(tmp[0], "UTF-8"));
830N/A r2 = URLDecoder.decode(tmp[1], "UTF-8");
170N/A }
170N/A }
170N/A } catch (UnsupportedEncodingException e) {
170N/A }
170N/A
283N/A if (r1 == null || r2 == null || r1.equals("") || r2.equals("") || r1.equals(r2)) {
0N/A%><div class="src"><h3 class="error">Error:</h3>
1126N/A Please pick two revisions to compare the changed from the <a href="<%=context+Constants.histL+uriEncodedName%>">history</a>
0N/A</div><%
0N/A// Error message ask to choose two versions from History log page with link to it
0N/A } else {
0N/A Genre g = AnalyzerGuru.getGenre(basename);
0N/A if (g == Genre.PLAIN || g == null || g == Genre.DATA || g == Genre.HTML) {
0N/A InputStream in1 = null;
0N/A InputStream in2 = null;
0N/A try{
170N/A in1 = HistoryGuru.getInstance().getRevision(rpath1.getParent(), rpath1.getName(), r1);
170N/A in2 = HistoryGuru.getInstance().getRevision(rpath2.getParent(), rpath2.getName(), r2);
0N/A } catch (Exception e) {
0N/A %> <h3 class="error">Error opening revisions!</h3> <%
0N/A }
0N/A try {
0N/A if (in1 != null && in2 != null) {
0N/A g = AnalyzerGuru.getGenre(basename);
0N/A if (g == null) {
0N/A g = AnalyzerGuru.getGenre(in1);
0N/A }
0N/A if (g == Genre.IMAGE) {
0N/A %> <div id="difftable">
0N/A <table rules="cols" cellpadding="5"><tr><th><%=basename%> (revision <%=r1%>)</th><th><%=basename%> (revision <%=r2%>)</th></tr>
1111N/A <tr><td><img src="<%=context+Constants.rawP+path%>?r=<%=r1%>"/></td><td><img src="<%=context+Constants.rawP+path%>?r=<%=r2%>"/></td></tr></table></div><%
0N/A } else if (g == Genre.PLAIN || g == Genre.HTML) {
0N/A//--------Do THE DIFFS------------
947N/A ArrayList<String> l1 = new ArrayList<String>();
0N/A String line;
0N/A BufferedReader reader1 = new BufferedReader(new InputStreamReader(in1));
0N/A BufferedReader reader2 = new BufferedReader(new InputStreamReader(in2));
0N/A
0N/A while ((line = reader1.readLine()) != null) {
0N/A l1.add(line);
0N/A }
0N/A
947N/A ArrayList<String> l2 = new ArrayList<String>();
0N/A while ((line = reader2.readLine()) != null) {
0N/A l2.add(line);
0N/A }
0N/A Object[] file1 = l1.toArray();
0N/A Object[] file2 = l2.toArray();
0N/A
0N/A Revision rev = Diff.diff(file1, file2);
0N/A
0N/A if(rev.size() == 0) {
0N/A %><b>No differences found!</b><%
0N/A } else {
0N/A
0N/A int ln1 = 0;
0N/A int ln2 = 0;
0N/A
0N/A String format = request.getParameter("format");
0N/A if(format == null || (!format.equals("o") && !format.equals("n") && !format.equals("u") && !format.equals("t")))
0N/A format = "s";
0N/A String pfull = request.getParameter("full");
0N/A boolean full = pfull != null && pfull.equals("1");
0N/A pfull = full ? "1" : "0";
0N/A
0N/A
0N/A%><div id="difftable"><div id="diffbar"><span class="tabsel">&nbsp;<span class="d"> Deleted </span>&nbsp;<span class="a">&nbsp;Added&nbsp;</span>&nbsp;</span> | <%
0N/A
0N/Aif(format.equals("s")) {
0N/A %><span class="tabsel"><b>sdiff</b></span> <%
0N/A} else {
188N/A %><span class="tab"><a href="<%=reqURI%>?r1=<%=rp1%>&r2=<%=rp2%>&format=s&full=<%=pfull%>">sdiff</a></span> <%
0N/A}
0N/A
0N/A if(format.equals("u")) {
0N/A %><span class="tabsel"><b>udiff</b></span> <%
0N/A } else {
188N/A %><span class="tab"><a href="<%=reqURI%>?r1=<%=rp1%>&r2=<%=rp2%>&format=u&full=<%=pfull%>">udiff</a></span> <%
0N/A }
0N/A
0N/A if(format.equals("t")) {
0N/A %><span class="tabsel"><b>text</b></span> <%
0N/A } else {
188N/A %><span class="tab"><a href="<%=reqURI%>?r1=<%=rp1%>&r2=<%=rp2%>&format=t&full=<%=pfull%>">text</a></span> <%
0N/A }
0N/A
0N/A if(format.equals("o")) {
0N/A %><span class="tabsel"><b>old (<%=r1%>)</b></span> <%
0N/A } else {
188N/A %><span class="tab"><a href="<%=reqURI%>?r1=<%=rp1%>&r2=<%=rp2%>&format=o&full=<%=pfull%>">old (<%=r1%>)</a></span> <%
0N/A }
0N/A
0N/A if(format.equals("n")) {
0N/A %><span class="tabsel"><b>new (<%=r2%>)</b></span>&nbsp;|&nbsp;<%
0N/A } else {
188N/A %><span class="tab"><a href="<%=reqURI%>?r1=<%=rp1%>&r2=<%=rp2%>&format=n&full=<%=pfull%>">new (<%=r2%>)</a></span>&nbsp;|&nbsp;<%
0N/A }
0N/A
0N/A if(!full) {
188N/A %><span class="tab"><a href="<%=reqURI%>?r1=<%=rp1%>&r2=<%=rp2%>&format=<%=format%>&full=1">&nbsp; &nbsp; full &nbsp; &nbsp;</a></span> <span class="tabsel"><b>compact</b></span><%
0N/A } else {
188N/A %><span class="tabsel"><b>&nbsp; &nbsp; full &nbsp; &nbsp;</b> </span> <span class="tab"> <a href="<%=reqURI%>?r1=<%=rp1%>&r2=<%=rp2%>&format=<%=format%>&full=0">compact</a></span><%
0N/A }
0N/A
0N/A if(format.equals("s") || format.equals("u")) {
0N/A %></div><pre wrap><table cellpadding="2" cellspacing="1" border="0" rules="cols"><%
0N/A if(format.equals("s")) {
0N/A %><tr><th><%=basename%> (<%=r1%>)</th><th><%=basename%> (<%=r2%>)</th></tr><%
0N/A }
0N/A } else {
0N/A %></div><pre wrap><%
0N/A }
0N/A
0N/A for (int i=0; i < rev.size(); i++) {
0N/A Delta d = rev.getDelta(i);
0N/A if(format.equals("t")) {
345N/A %><%=Util.htmlize(d.toString())%><%
0N/A } else {
0N/A Chunk c1 = d.getOriginal();
0N/A Chunk c2 = d.getRevised();
0N/A int cn1 = c1.first();
0N/A int cl1 = c1.last();
0N/A int cn2 = c2.first();
0N/A int cl2 = c2.last();
0N/A
0N/A int i1 = cn1, i2 = cn2;
0N/A for (; i1 <= cl1 && i2 <= cl2; i1++, i2++) {
1025N/A String[] ss = Util.diffline(Util.htmlize((String)file1[i1]), Util.htmlize((String)file2[i2]));
0N/A file1[i1] = ss[0];
0N/A file2[i2] = ss[1];
0N/A }
1168N/A
1168N/A for (; i1 <= cl1; i1++) {
1168N/A file1[i1] = "<span class=\"d\">" + Util.htmlize((String)file1[i1]) + "</span>";
0N/A }
1168N/A
1168N/A for(; i2 <= cl2; i2++) {
1168N/A file2[i2] = "<span class=\"a\">" + Util.htmlize((String)file2[i2]) + "</span>";
0N/A }
1168N/A
0N/A if (format.equals("u")) {
0N/A// UDIFF
0N/A if (cn1 > ln1 || cn2 > ln2) {
0N/A %><tr class="k"><td><%
0N/A if (full || (cn2 - ln2 < 20)) {
0N/A for (int j = ln2; j < cn2; j++) {
345N/A %><i><%=readableLine(++ln2)%></i><%=Util.htmlize((String)file2[j])%><br/><%
0N/A }
0N/A } else {
0N/A for (int j = ln2; j < ln2+8; j++) {
345N/A %><i><%=readableLine(j+1)%></i><%=Util.htmlize((String)file2[j])%><br/><%
0N/A }
488N/A %><br/>--- <b><%=cn2 - ln2 - 16%> unchanged lines hidden</b> (<a href="<%=reqURI%>?r1=<%=rp1%>&r2=<%=rp2%>&format=<%=format%>&full=1#<%=ln2%>">view full</a>) --- <br/><br/><%
0N/A ln2 = cn2-8;
0N/A for (int j = cn2 - 8; j < cn2; j++) {
345N/A %><i><%=readableLine(++ln2)%></i><%=Util.htmlize((String)file2[j])%><br/><%
0N/A }
0N/A }
0N/A %></td></tr><%
0N/A ln1 = cn1;
0N/A }
0N/A if(cn1 <= cl1) {
0N/A %><tr><td class="d"><%
0N/A for(int j = cn1; j <= cl1 ; j++) {
0N/A %><strike class="d"><%=readableLine(++ln1)%></strike><%=file1[j]%><br/><%
0N/A }
0N/A %></td></tr><%
0N/A }
0N/A if(cn2 <= cl2) {
0N/A %><tr class="k"><td><%
0N/A for(int j = cn2; j < cl2; j++) {
0N/A %><i class="a"><%=readableLine(++ln2)%></i><%=file2[j]%><br/><%
0N/A }
0N/A %><i class="a"><%=readableLine(++ln2)%></i><%=file2[cl2]%><%
0N/A if(full) {
0N/A %><a name="<%=ln2%>" /><%
0N/A }
0N/A %></td></tr><%
0N/A }
0N/A// SDIFF by default
0N/A } else if(format.equals("s")) {
0N/A
0N/A if (cn1 > ln1 || cn2 > ln2) {
0N/A %><tr class="k"><td><%
0N/A if(full || cn2 - ln2 < 20) {
0N/A for(int j = ln1; j < cn1; j++) {
345N/A %><i><%=readableLine(++ln1)%></i><%=Util.htmlize((String)file1[j])%><br/><%
0N/A }
0N/A %></td><td><%
0N/A for(int j = ln2; j < cn2 ; j++) {
345N/A %><i><%=readableLine(++ln2)%></i><%=Util.htmlize((String)file2[j])%><br/><%
0N/A }
0N/A } else {
0N/A for(int j = ln1; j < ln1+8; j++) {
345N/A %><i><%=readableLine(j+1)%></i><%=Util.htmlize((String)file1[j])%><br/><%
0N/A }
488N/A %><br/>--- <b><%=cn1 - ln1 - 16%> unchanged lines hidden</b> (<a href="<%=reqURI%>?r1=<%=rp1%>&r2=<%=rp2%>&format=<%=format%>&full=1#<%=ln2%>">view full</a>) --- <br/><br/><%
0N/A ln1 = cn1-8;
0N/A for (int j = cn1 - 8; j < cn1; j++) {
345N/A %><i><%=readableLine(++ln1)%></i><%=Util.htmlize((String)file1[j])%><br/><%
0N/A }
0N/A %></td><td><%
0N/A for (int j = ln2; j < ln2+8; j++) {
345N/A %><i><%=readableLine(j+1)%></i><%=Util.htmlize((String)file2[j])%><br/><%
0N/A }
488N/A %><br/>--- <b><%=cn2 - ln2 - 16%> unchanged lines hidden</b> (<a href="<%=reqURI%>?r1=<%=rp1%>&r2=<%=rp2%>&format=<%=format%>&full=1#<%=ln2%>">view full</a>) --- <br/><br/><%
0N/A ln2 = cn2-8;
0N/A for (int j = cn2 - 8; j < cn2; j++) {
345N/A %><i><%=readableLine(++ln2)%></i><%=Util.htmlize((String)file2[j])%><br/><%
0N/A }
0N/A }
0N/A %></td></tr><%
0N/A }
0N/A
0N/A %><tr valign="top" class="k"><td><%
0N/A for(int j = cn1; j <= cl1; j++) {
0N/A %><i><%=readableLine(++ln1)%></i><%=file1[j]%><br/><%
0N/A }
0N/A %></td><td><%
0N/A for(int j = cn2; j <= cl2; j++) {
705N/A %><i><%=readableLine(++ln2)%></i><a name="<%=ln2%>"></a><%=file2[j]%><br/><%
0N/A }
0N/A %></td></tr><%
0N/A
0N/A// OLD -----
0N/A } else if ( format.equals("o")) {
0N/A if (cn1 > ln1) {
0N/A if(full || cn1 - ln1 < 20) {
0N/A for(int j = ln1; j < cn1; j++) {
345N/A %><i><%=readableLine(++ln1)%></i><%=Util.htmlize((String)file1[j])%><br/><%
0N/A }
0N/A } else {
0N/A for(int j = ln1; j < ln1+8; j++) {
345N/A %><i><%=readableLine(j+1)%></i><%=Util.htmlize((String)file1[j])%><br/><%
0N/A }
488N/A %><br/>--- <b><%=cn1 - ln1 - 16%> unchanged lines hidden</b> (<a href="<%=reqURI%>?r1=<%=rp1%>&r2=<%=rp2%>&format=<%=format%>&full=1#<%=ln1%>">view full</a>) --- <br/><br/><%
0N/A ln1 = cn1-8;
0N/A for (int j = cn1 - 8; j < cn1; j++) {
345N/A %><i><%=readableLine(++ln1)%></i><%=Util.htmlize((String)file1[j])%><br/><%
0N/A }
0N/A }
0N/A }
0N/A for(int j = cn1; j <= cl1 ; j++) {
0N/A %><i><%=readableLine(++ln1)%></i><%=file1[j]%><br/><%
0N/A }
0N/A if(full) {
0N/A %><a name="<%=ln1%>" ></a><%
0N/A }
0N/A
0N/A// NEW -----------
0N/A } else if ( format.equals("n")) {
0N/A
0N/A if (cn2 > ln2) {
0N/A if(full || cn2 - ln2 < 20) {
0N/A for(int j = ln2; j < cn2 ; j++) {
345N/A %><i><%=readableLine(++ln2)%></i><%=Util.htmlize((String)file2[j])%><br/><%
0N/A }
0N/A } else {
0N/A for (int j = ln2; j < ln2+8; j++) {
345N/A %><i><%=readableLine(j+1)%></i><%=Util.htmlize((String)file2[j])%><br/><%
0N/A }
488N/A %><br/>--- <b><%=cn2 - ln2 - 16%> unchanged lines hidden</b> (<a href="<%=reqURI%>?r1=<%=rp1%>&r2=<%=rp2%>&format=<%=format%>&full=1#<%=ln2%>">view full</a>) --- <br/><br/><%
0N/A ln2 = cn2-8;
0N/A for (int j = cn2 - 8; j < cn2; j++) {
345N/A %><i><%=readableLine(++ln2)%></i><%=Util.htmlize((String)file2[j])%><br/><%
0N/A }
0N/A }
0N/A }
0N/A for(int j = cn2; j <= cl2 ; j++) {
0N/A %><i><%=readableLine(++ln2)%></i><%=file2[j]%><br/><%
0N/A }
0N/A if(full) {
0N/A %><a name="<%=ln2%>"></a><%
0N/A }
0N/A
0N/A }
0N/A }
0N/A }
0N/A
0N/A
0N/A if (file1.length >= ln1) {
0N/A// dump the remaining
0N/A if (format.equals("s")) {
0N/A if (full || file1.length - ln1 < 20) {
0N/A %><tr><td><%
0N/A for (int j = ln1; j < file1.length ; j++) {
345N/A %><i><%=(j+1)%></i><%=Util.htmlize((String)file1[j])%><br/><%
0N/A }
0N/A %></td><td><%
0N/A for (int j = ln2; j < file2.length ; j++) {
345N/A %><i><%=(j+1)%></i><%=Util.htmlize((String)file2[j])%><br/><%
0N/A }
0N/A %></td></tr></table><%
0N/A } else {
0N/A %><tr><td><%
0N/A for (int j = ln1; j < ln1 + 8 ; j++) {
345N/A %><i><%=(j+1)%></i><%=Util.htmlize((String)file1[j])%><br/><%
0N/A }
0N/A
0N/A %><br/> --- <b><%=file1.length - ln1 - 8%> unchanged lines hidden</b> --- </td><td><%
0N/A for (int j = ln2; j < ln2 + 8 ; j++) {
345N/A %><i><%=(j+1)%></i><%=Util.htmlize((String)file2[j])%><br/><%
0N/A }
0N/A %><br/>--- <b><%=file1.length - ln1 - 8%> unchanged lines hidden</b> ---</td></tr></table><%
0N/A }
0N/A } else if (format.equals("u")) {
0N/A if (full || file2.length - ln2 < 20) {
0N/A %><tr><td><%
0N/A for (int j = ln2; j < file2.length ; j++) {
345N/A %><i><%=(j+1)%></i><%=Util.htmlize((String)file2[j])%><br/><%
0N/A }
0N/A %></td></tr></table><%
0N/A } else {
0N/A %><tr><td><%
0N/A for (int j = ln2; j < ln2 + 8 ; j++) {
345N/A %><i><%=(j+1)%></i><%=Util.htmlize((String)file2[j])%><br/><%
0N/A }
0N/A %><br/>--- <b><%=file2.length - ln2 - 8%> unchanged lines hidden</b> ---</td></tr></table><%
0N/A }
0N/A } else if (format.equals("o")) {
0N/A if (full || file1.length - ln1 < 20) {
0N/A for (int j = ln1; j < file1.length ; j++) {
345N/A %><i><%=(j+1)%></i><%=Util.htmlize((String)file1[j])%><br/><%
0N/A }
0N/A } else {
0N/A for (int j = ln1; j < ln1 + 8 ; j++) {
345N/A %><i><%=(j+1)%></i><%=Util.htmlize((String)file1[j])%><br/><%
0N/A }
0N/A
0N/A %><br/> --- <b><%=file1.length - ln1 - 8%> unchanged lines hidden</b> ---<br/><%
0N/A }
0N/A } else if (format.equals("n")) {
0N/A if (full || file2.length - ln2 < 20) {
0N/A for (int j = ln2; j < file2.length ; j++) {
345N/A %><i><%=(j+1)%></i><%=Util.htmlize((String)file2[j])%><br/><%
0N/A }
0N/A } else {
0N/A for (int j = ln2; j < ln2 + 8 ; j++) {
345N/A %><i><%=(j+1)%></i><%=Util.htmlize((String)file2[j])%><br/><%
0N/A }
0N/A %><br/> --- <b><%=file2.length - ln2 - 8%> unchanged lines hidden</b> ---<br/><%
0N/A }
0N/A }
0N/A
0N/A }
0N/A
0N/A//----DIFFS Done--------
0N/A%></pre></div><%
0N/A }
0N/A } else {
1111N/A %> <div id="src">Diffs for binary files cannot be displayed! Files are <a href="<%=context+Constants.rawP+path%>?r=<%=r1%>"><%=basename%>(revision <%=r1%>)</a> and
1111N/A <a href="<%=context+Constants.rawP+path%>?r=<%=r2%>"><%=basename%>(revision <%=r2%>)</a>.
0N/A </div><%
0N/A }
0N/A }
0N/A } catch (FileNotFoundException e) {
345N/A %><div class="src"><h3 class="error">Error Opening files! <%=Util.htmlize(e.getMessage())%></h3></div><%
1156N/A } finally {
1156N/A if(in1 != null)
1156N/A try {
1156N/A in1.close();
1156N/A } catch (IOException ignore) {
1156N/A }
1156N/A if(in2 != null)
1156N/A try {
1156N/A in2.close();
1156N/A } catch (IOException ignore) {
1156N/A }
0N/A }
0N/A } else if (g == Genre.IMAGE) {
0N/A %> <div class="src">
0N/A <table rules="cols" cellpadding="5"><tr><th><%=basename%> (revision <%=r1%>)</th><th><%=basename%> (revision <%=r2%>)</th></tr>
1111N/A <tr><td><img src="<%=context+Constants.rawP+path%>?r=<%=r1%>"/></td><td><img src="<%=context+Constants.rawP+path%>?r=<%=r2%>"/></td></tr></table></div><%
0N/A
0N/A } else {
1111N/A %> <div class="src">Diffs for binary files cannot be displayed. Files are <a href="<%=context+Constants.rawP+path%>?r=<%=r1%>"><%=basename%>(revision <%=r1%>)</a> and
1111N/A <a href="<%=context+Constants.rawP+path%>?r=<%=r2%>"><%=basename%>(revision <%=r2%>)</a>.
0N/A </div><%
0N/A }
0N/A }
66N/A%><%@include file="foot.jspf"%><%
0N/A}
0N/A%>