diff.jsp revision 1025
431N/A<%--
431N/ACDDL HEADER START
431N/A
431N/AThe contents of this file are subject to the terms of the
431N/ACommon Development and Distribution License (the "License").
431N/AYou may not use this file except in compliance with the License.
431N/A
431N/ASee LICENSE.txt included in this distribution for the specific
431N/Alanguage governing permissions and limitations under the License.
431N/A
431N/AWhen distributing Covered Code, include this CDDL HEADER in each
431N/Afile and include the License file at LICENSE.txt.
431N/AIf applicable, add the following below this CDDL HEADER, with the
431N/Afields enclosed by brackets "[]" replaced with your own identifying
431N/Ainformation: Portions Copyright [yyyy] [name of copyright owner]
431N/A
431N/ACDDL HEADER END
431N/A
431N/ACopyright 2009 Sun Microsystems, Inc. All rights reserved.
431N/AUse is subject to license terms.
431N/A
431N/Aident "@(#)diff.jsp 1.2 05/12/01 SMI"
431N/A
431N/A--%><%@ page import = "javax.servlet.*,
431N/Ajava.lang.*,
431N/Ajavax.servlet.http.*,
431N/Ajava.util.*,
471N/Ajava.io.*,
471N/Ajava.text.*,
431N/Ajava.net.URLDecoder,
431N/Aorg.opensolaris.opengrok.analysis.*,
431N/Aorg.opensolaris.opengrok.analysis.FileAnalyzer.Genre,
431N/Aorg.opensolaris.opengrok.web.*,
431N/Aorg.opensolaris.opengrok.history.*,
431N/Aorg.apache.commons.jrcs.diff.*"
431N/A%><%@include file="mast.jsp"%><%!
431N/A
431N/AString readableLine(int n) {
431N/A if (n < 10) {
431N/A return " " + n;
431N/A } else {
431N/A return String.valueOf(n);
431N/A }
431N/A}
431N/A
431N/A%><%
431N/A
431N/Aif (valid) {
431N/A final String rp1 = request.getParameter("r1");
431N/A final String rp2 = request.getParameter("r2");
431N/A String srcRoot = environment.getSourceRootFile().getAbsolutePath();
431N/A
431N/A String r1 = null;
431N/A String r2 = null;
431N/A File rpath1 = null;
431N/A File rpath2 = null;
431N/A String[] tmp=null;
431N/A try {
431N/A if (rp1!=null) tmp = rp1.split("@");
431N/A if (tmp != null && tmp.length == 2) {
431N/A rpath1 = new File(srcRoot+URLDecoder.decode(tmp[0], "UTF-8"));
431N/A r1 = URLDecoder.decode(tmp[1], "UTF-8");
431N/A }
431N/A } catch (UnsupportedEncodingException e) {
431N/A }
431N/A
431N/A try {
431N/A if (rp2!=null) tmp = rp2.split("@");
431N/A if (tmp != null && tmp.length == 2) {
431N/A if (tmp != null && tmp.length == 2) {
431N/A rpath2 = new File(srcRoot+URLDecoder.decode(tmp[0], "UTF-8"));
431N/A r2 = URLDecoder.decode(tmp[1], "UTF-8");
431N/A }
431N/A }
431N/A } catch (UnsupportedEncodingException e) {
431N/A }
431N/A
431N/A if (r1 == null || r2 == null || r1.equals("") || r2.equals("") || r1.equals(r2)) {
431N/A%><div class="src"><h3 class="error">Error:</h3>
431N/A Please pick two revisions to compare the changed from the <a href="<%=context%>/history<%=path%>">history</a>
431N/A</div><%
431N/A// Error message ask to choose two versions from History log page with link to it
431N/A } else {
565N/A Genre g = AnalyzerGuru.getGenre(basename);
431N/A if (g == Genre.PLAIN || g == null || g == Genre.DATA || g == Genre.HTML) {
431N/A InputStream in1 = null;
431N/A InputStream in2 = null;
431N/A try{
431N/A in1 = HistoryGuru.getInstance().getRevision(rpath1.getParent(), rpath1.getName(), r1);
431N/A in2 = HistoryGuru.getInstance().getRevision(rpath2.getParent(), rpath2.getName(), r2);
431N/A } catch (Exception e) {
431N/A %> <h3 class="error">Error opening revisions!</h3> <%
431N/A }
431N/A try {
431N/A if (in1 != null && in2 != null) {
431N/A g = AnalyzerGuru.getGenre(basename);
431N/A if (g == null) {
431N/A g = AnalyzerGuru.getGenre(in1);
431N/A }
431N/A if (g == Genre.IMAGE) {
431N/A %> <div id="difftable">
431N/A <table rules="cols" cellpadding="5"><tr><th><%=basename%> (revision <%=r1%>)</th><th><%=basename%> (revision <%=r2%>)</th></tr>
526N/A <tr><td><img src="<%=context%>/raw<%=path%>?r=<%=r1%>"/></td><td><img src="<%=context%>/raw<%=path%>?r=<%=r2%>"/></td></tr></table></div><%
431N/A } else if (g == Genre.PLAIN || g == Genre.HTML) {
431N/A//--------Do THE DIFFS------------
431N/A ArrayList<String> l1 = new ArrayList<String>();
526N/A String line;
431N/A BufferedReader reader1 = new BufferedReader(new InputStreamReader(in1));
526N/A BufferedReader reader2 = new BufferedReader(new InputStreamReader(in2));
526N/A
526N/A while ((line = reader1.readLine()) != null) {
526N/A l1.add(line);
526N/A }
526N/A
526N/A ArrayList<String> l2 = new ArrayList<String>();
526N/A while ((line = reader2.readLine()) != null) {
431N/A l2.add(line);
431N/A }
431N/A Object[] file1 = l1.toArray();
431N/A Object[] file2 = l2.toArray();
431N/A
431N/A Revision rev = Diff.diff(file1, file2);
431N/A
431N/A if(rev.size() == 0) {
431N/A %><b>No differences found!</b><%
431N/A } else {
431N/A
431N/A int ln1 = 0;
431N/A int ln2 = 0;
431N/A
431N/A String format = request.getParameter("format");
431N/A if(format == null || (!format.equals("o") && !format.equals("n") && !format.equals("u") && !format.equals("t")))
431N/A format = "s";
431N/A String pfull = request.getParameter("full");
431N/A boolean full = pfull != null && pfull.equals("1");
431N/A pfull = full ? "1" : "0";
431N/A
431N/A
431N/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> | <%
431N/A
431N/Aif(format.equals("s")) {
431N/A %><span class="tabsel"><b>sdiff</b></span> <%
431N/A} else {
431N/A %><span class="tab"><a href="<%=reqURI%>?r1=<%=rp1%>&r2=<%=rp2%>&format=s&full=<%=pfull%>">sdiff</a></span> <%
431N/A}
431N/A
431N/A if(format.equals("u")) {
431N/A %><span class="tabsel"><b>udiff</b></span> <%
431N/A } else {
431N/A %><span class="tab"><a href="<%=reqURI%>?r1=<%=rp1%>&r2=<%=rp2%>&format=u&full=<%=pfull%>">udiff</a></span> <%
431N/A }
431N/A
431N/A if(format.equals("t")) {
431N/A %><span class="tabsel"><b>text</b></span> <%
431N/A } else {
431N/A %><span class="tab"><a href="<%=reqURI%>?r1=<%=rp1%>&r2=<%=rp2%>&format=t&full=<%=pfull%>">text</a></span> <%
431N/A }
431N/A
431N/A if(format.equals("o")) {
431N/A %><span class="tabsel"><b>old (<%=r1%>)</b></span> <%
431N/A } else {
431N/A %><span class="tab"><a href="<%=reqURI%>?r1=<%=rp1%>&r2=<%=rp2%>&format=o&full=<%=pfull%>">old (<%=r1%>)</a></span> <%
431N/A }
431N/A
431N/A if(format.equals("n")) {
431N/A %><span class="tabsel"><b>new (<%=r2%>)</b></span>&nbsp;|&nbsp;<%
431N/A } else {
431N/A %><span class="tab"><a href="<%=reqURI%>?r1=<%=rp1%>&r2=<%=rp2%>&format=n&full=<%=pfull%>">new (<%=r2%>)</a></span>&nbsp;|&nbsp;<%
431N/A }
431N/A
431N/A if(!full) {
431N/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><%
431N/A } else {
431N/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><%
431N/A }
431N/A
431N/A if(format.equals("s") || format.equals("u")) {
431N/A %></div><pre wrap><table cellpadding="2" cellspacing="1" border="0" rules="cols"><%
431N/A if(format.equals("s")) {
431N/A %><tr><th><%=basename%> (<%=r1%>)</th><th><%=basename%> (<%=r2%>)</th></tr><%
431N/A }
431N/A } else {
431N/A %></div><pre wrap><%
431N/A }
431N/A
431N/A for (int i=0; i < rev.size(); i++) {
431N/A Delta d = rev.getDelta(i);
431N/A if(format.equals("t")) {
431N/A %><%=Util.htmlize(d.toString())%><%
431N/A } else {
431N/A Chunk c1 = d.getOriginal();
431N/A Chunk c2 = d.getRevised();
431N/A int cn1 = c1.first();
431N/A int cl1 = c1.last();
431N/A int cn2 = c2.first();
431N/A int cl2 = c2.last();
431N/A
431N/A int i1 = cn1, i2 = cn2;
431N/A for (; i1 <= cl1 && i2 <= cl2; i1++, i2++) {
431N/A String[] ss = Util.diffline(Util.htmlize((String)file1[i1]), Util.htmlize((String)file2[i2]));
431N/A file1[i1] = ss[0];
431N/A file2[i2] = ss[1];
431N/A }
431N/A if(i1 <= cl1) {
431N/A for(int h=i1; h<= cl1; h++) {
431N/A file1[h] = Util.htmlize((String)file1[h]);
431N/A }
431N/A file1[i1] = "<span class=\"d\">" + file1[i1];
431N/A file1[cl1] = file1[cl1] + "</span>";
431N/A }
431N/A if(i2 <= cl2) {
431N/A for(int h=i2; h<= cl2; h++) {
431N/A file2[h] = Util.htmlize((String)file2[h]);
431N/A }
431N/A file2[i2] = "<span class=\"a\">" + file2[i2];
431N/A file2[cl2] = file2[cl2] + "</span>";
431N/A }
431N/A
431N/A if (format.equals("u")) {
431N/A// UDIFF
431N/A if (cn1 > ln1 || cn2 > ln2) {
431N/A %><tr class="k"><td><%
431N/A if (full || (cn2 - ln2 < 20)) {
431N/A for (int j = ln2; j < cn2; j++) {
431N/A %><i><%=readableLine(++ln2)%></i><%=Util.htmlize((String)file2[j])%><br/><%
431N/A }
431N/A } else {
431N/A for (int j = ln2; j < ln2+8; j++) {
431N/A %><i><%=readableLine(j+1)%></i><%=Util.htmlize((String)file2[j])%><br/><%
431N/A }
431N/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/><%
431N/A ln2 = cn2-8;
431N/A for (int j = cn2 - 8; j < cn2; j++) {
431N/A %><i><%=readableLine(++ln2)%></i><%=Util.htmlize((String)file2[j])%><br/><%
431N/A }
431N/A }
431N/A %></td></tr><%
431N/A ln1 = cn1;
431N/A }
431N/A if(cn1 <= cl1) {
431N/A %><tr><td class="d"><%
431N/A for(int j = cn1; j <= cl1 ; j++) {
431N/A %><strike class="d"><%=readableLine(++ln1)%></strike><%=file1[j]%><br/><%
431N/A }
431N/A %></td></tr><%
431N/A }
431N/A if(cn2 <= cl2) {
431N/A %><tr class="k"><td><%
431N/A for(int j = cn2; j < cl2; j++) {
431N/A %><i class="a"><%=readableLine(++ln2)%></i><%=file2[j]%><br/><%
431N/A }
431N/A %><i class="a"><%=readableLine(++ln2)%></i><%=file2[cl2]%><%
431N/A if(full) {
431N/A %><a name="<%=ln2%>" /><%
431N/A }
431N/A %></td></tr><%
431N/A }
431N/A// SDIFF by default
431N/A } else if(format.equals("s")) {
431N/A
431N/A if (cn1 > ln1 || cn2 > ln2) {
431N/A %><tr class="k"><td><%
431N/A if(full || cn2 - ln2 < 20) {
431N/A for(int j = ln1; j < cn1; j++) {
431N/A %><i><%=readableLine(++ln1)%></i><%=Util.htmlize((String)file1[j])%><br/><%
431N/A }
431N/A %></td><td><%
431N/A for(int j = ln2; j < cn2 ; j++) {
431N/A %><i><%=readableLine(++ln2)%></i><%=Util.htmlize((String)file2[j])%><br/><%
431N/A }
431N/A } else {
431N/A for(int j = ln1; j < ln1+8; j++) {
431N/A %><i><%=readableLine(j+1)%></i><%=Util.htmlize((String)file1[j])%><br/><%
431N/A }
431N/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/><%
431N/A ln1 = cn1-8;
431N/A for (int j = cn1 - 8; j < cn1; j++) {
431N/A %><i><%=readableLine(++ln1)%></i><%=Util.htmlize((String)file1[j])%><br/><%
431N/A }
431N/A %></td><td><%
431N/A for (int j = ln2; j < ln2+8; j++) {
431N/A %><i><%=readableLine(j+1)%></i><%=Util.htmlize((String)file2[j])%><br/><%
431N/A }
431N/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/><%
431N/A ln2 = cn2-8;
431N/A for (int j = cn2 - 8; j < cn2; j++) {
431N/A %><i><%=readableLine(++ln2)%></i><%=Util.htmlize((String)file2[j])%><br/><%
431N/A }
431N/A }
431N/A %></td></tr><%
431N/A }
431N/A
431N/A %><tr valign="top" class="k"><td><%
431N/A for(int j = cn1; j <= cl1; j++) {
431N/A %><i><%=readableLine(++ln1)%></i><%=file1[j]%><br/><%
431N/A }
431N/A %></td><td><%
431N/A for(int j = cn2; j <= cl2; j++) {
431N/A %><i><%=readableLine(++ln2)%></i><a name="<%=ln2%>"></a><%=file2[j]%><br/><%
431N/A }
431N/A %></td></tr><%
431N/A
431N/A// OLD -----
431N/A } else if ( format.equals("o")) {
431N/A if (cn1 > ln1) {
431N/A if(full || cn1 - ln1 < 20) {
431N/A for(int j = ln1; j < cn1; j++) {
431N/A %><i><%=readableLine(++ln1)%></i><%=Util.htmlize((String)file1[j])%><br/><%
431N/A }
431N/A } else {
431N/A for(int j = ln1; j < ln1+8; j++) {
431N/A %><i><%=readableLine(j+1)%></i><%=Util.htmlize((String)file1[j])%><br/><%
431N/A }
471N/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/><%
471N/A ln1 = cn1-8;
480N/A for (int j = cn1 - 8; j < cn1; j++) {
480N/A %><i><%=readableLine(++ln1)%></i><%=Util.htmlize((String)file1[j])%><br/><%
480N/A }
480N/A }
480N/A }
480N/A for(int j = cn1; j <= cl1 ; j++) {
480N/A %><i><%=readableLine(++ln1)%></i><%=file1[j]%><br/><%
480N/A }
471N/A if(full) {
471N/A %><a name="<%=ln1%>" ></a><%
471N/A }
471N/A
471N/A// NEW -----------
471N/A } else if ( format.equals("n")) {
471N/A
471N/A if (cn2 > ln2) {
471N/A if(full || cn2 - ln2 < 20) {
471N/A for(int j = ln2; j < cn2 ; j++) {
471N/A %><i><%=readableLine(++ln2)%></i><%=Util.htmlize((String)file2[j])%><br/><%
471N/A }
490N/A } else {
490N/A for (int j = ln2; j < ln2+8; j++) {
490N/A %><i><%=readableLine(j+1)%></i><%=Util.htmlize((String)file2[j])%><br/><%
490N/A }
490N/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/><%
490N/A ln2 = cn2-8;
490N/A for (int j = cn2 - 8; j < cn2; j++) {
490N/A %><i><%=readableLine(++ln2)%></i><%=Util.htmlize((String)file2[j])%><br/><%
490N/A }
490N/A }
490N/A }
490N/A for(int j = cn2; j <= cl2 ; j++) {
490N/A %><i><%=readableLine(++ln2)%></i><%=file2[j]%><br/><%
490N/A }
492N/A if(full) {
492N/A %><a name="<%=ln2%>"></a><%
492N/A }
492N/A
492N/A }
492N/A }
492N/A }
492N/A
492N/A
492N/A if (file1.length >= ln1) {
492N/A// dump the remaining
490N/A if (format.equals("s")) {
if (full || file1.length - ln1 < 20) {
%><tr><td><%
for (int j = ln1; j < file1.length ; j++) {
%><i><%=(j+1)%></i><%=Util.htmlize((String)file1[j])%><br/><%
}
%></td><td><%
for (int j = ln2; j < file2.length ; j++) {
%><i><%=(j+1)%></i><%=Util.htmlize((String)file2[j])%><br/><%
}
%></td></tr></table><%
} else {
%><tr><td><%
for (int j = ln1; j < ln1 + 8 ; j++) {
%><i><%=(j+1)%></i><%=Util.htmlize((String)file1[j])%><br/><%
}
%><br/> --- <b><%=file1.length - ln1 - 8%> unchanged lines hidden</b> --- </td><td><%
for (int j = ln2; j < ln2 + 8 ; j++) {
%><i><%=(j+1)%></i><%=Util.htmlize((String)file2[j])%><br/><%
}
%><br/>--- <b><%=file1.length - ln1 - 8%> unchanged lines hidden</b> ---</td></tr></table><%
}
} else if (format.equals("u")) {
if (full || file2.length - ln2 < 20) {
%><tr><td><%
for (int j = ln2; j < file2.length ; j++) {
%><i><%=(j+1)%></i><%=Util.htmlize((String)file2[j])%><br/><%
}
%></td></tr></table><%
} else {
%><tr><td><%
for (int j = ln2; j < ln2 + 8 ; j++) {
%><i><%=(j+1)%></i><%=Util.htmlize((String)file2[j])%><br/><%
}
%><br/>--- <b><%=file2.length - ln2 - 8%> unchanged lines hidden</b> ---</td></tr></table><%
}
} else if (format.equals("o")) {
if (full || file1.length - ln1 < 20) {
for (int j = ln1; j < file1.length ; j++) {
%><i><%=(j+1)%></i><%=Util.htmlize((String)file1[j])%><br/><%
}
} else {
for (int j = ln1; j < ln1 + 8 ; j++) {
%><i><%=(j+1)%></i><%=Util.htmlize((String)file1[j])%><br/><%
}
%><br/> --- <b><%=file1.length - ln1 - 8%> unchanged lines hidden</b> ---<br/><%
}
} else if (format.equals("n")) {
if (full || file2.length - ln2 < 20) {
for (int j = ln2; j < file2.length ; j++) {
%><i><%=(j+1)%></i><%=Util.htmlize((String)file2[j])%><br/><%
}
} else {
for (int j = ln2; j < ln2 + 8 ; j++) {
%><i><%=(j+1)%></i><%=Util.htmlize((String)file2[j])%><br/><%
}
%><br/> --- <b><%=file2.length - ln2 - 8%> unchanged lines hidden</b> ---<br/><%
}
}
}
//----DIFFS Done--------
%></pre></div><%
}
} else {
%> <div id="src">Diffs for binary files cannot be displayed! Files are <a href="<%=context%>/raw<%=path%>?r=<%=r1%>"><%=basename%>(revision <%=r1%>)</a> and
<a href="<%=context%>/raw<%=path%>?r=<%=r2%>"><%=basename%>(revision <%=r2%>)</a>.
</div><%
}
}
} catch (FileNotFoundException e) {
%><div class="src"><h3 class="error">Error Opening files! <%=Util.htmlize(e.getMessage())%></h3></div><%
}
if(in1 != null)
in1.close();
if(in2 != null)
in2.close();
} else if (g == Genre.IMAGE) {
%> <div class="src">
<table rules="cols" cellpadding="5"><tr><th><%=basename%> (revision <%=r1%>)</th><th><%=basename%> (revision <%=r2%>)</th></tr>
<tr><td><img src="<%=context%>/raw<%=path%>?r=<%=r1%>"/></td><td><img src="<%=context%>/raw<%=path%>?r=<%=r2%>"/></td></tr></table></div><%
} else {
%> <div class="src">Diffs for binary files cannot be displayed. Files are <a href="<%=context%>/raw<%=path%>?r=<%=r1%>"><%=basename%>(revision <%=r1%>)</a> and
<a href="<%=context%>/raw<%=path%>?r=<%=r2%>"><%=basename%>(revision <%=r2%>)</a>.
</div><%
}
}
%><%@include file="foot.jspf"%><%
}
%>