forked from oracle/opengrok
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiff.jsp
491 lines (465 loc) · 17.4 KB
/
diff.jsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
<%--
$Id$
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.
See LICENSE.txt included in this distribution 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 LICENSE.txt.
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
Copyright 2009 Sun Microsystems, Inc. All rights reserved.
Use is subject to license terms.
Portions Copyright 2011 Jens Elkner.
--%><%@page import="
java.io.BufferedReader,
java.io.FileNotFoundException,
java.io.InputStream,
java.io.InputStreamReader,
java.io.UnsupportedEncodingException,
java.net.URLDecoder,
java.util.ArrayList,
org.apache.commons.jrcs.diff.Chunk,
org.apache.commons.jrcs.diff.Delta,
org.apache.commons.jrcs.diff.Diff,
org.apache.commons.jrcs.diff.Revision,
org.opensolaris.opengrok.analysis.AnalyzerGuru,
org.opensolaris.opengrok.analysis.FileAnalyzer.Genre,
org.opensolaris.opengrok.web.DiffData,
org.opensolaris.opengrok.web.DiffType"
%><%!
private String getAnnotateRevision(DiffData data) {
if (data.type == DiffType.OLD || data.type == DiffType.NEW) {
return "<script type=\"text/javascript\">/* <![CDATA[ */ "
+ "document.rev = 'r=" + data.rev[data.type == DiffType.NEW ? 1 : 0]
+ "'; /* ]]> */</script>";
}
return "";
}
%><%@
include file="mast.jsp"
%><%
/* ---------------------- diff.jsp start --------------------- */
{
cfg = PageConfig.get(request);
DiffData data = cfg.getDiffData();
if (data.errorMsg != null) {
%>
<div class="src">
<h3 class="error">Error:</h3>
<p><%= data.errorMsg %></p>
</div><%
} else if (data.genre == Genre.IMAGE) {
String link = request.getContextPath() + Prefix.RAW_P
+ Util.htmlize(cfg.getPath());
%>
<div id="difftable">
<table class="image">
<thead>
<tr><th><%= data.filename %> (revision <%= data.rev[0] %>)</th>
<th><%= data.filename %> (revision <%= data.rev[1] %>)</th>
</tr>
</thead>
<tbody>
<tr><td><img src="<%= link %>?r=<%= data.rev[0] %>"/></td>
<td><img src="<%= link %>?r=<%= data.rev[1] %>"/></td>
</tr>
</tbody>
</table>
</div><%
} else if (data.genre != Genre.PLAIN && data.genre != Genre.HTML) {
String link = request.getContextPath() + Prefix.RAW_P
+ Util.htmlize(cfg.getPath());
%>
<div id="src">Diffs for binary files cannot be displayed! Files are <a
href="<%= link %>?r=<%= data.rev[0] %>"><%=
data.filename %>(revision <%= data.rev[0] %>)</a> and <a
href="<%= link %>?r=<%= data.rev[1] %>"><%=
data.filename %>(revision <%= data.rev[1] %>)</a>.
</div><%
} else if (data.revision.size() == 0) {
%>
<%= getAnnotateRevision(data) %>
<b>No differences found!</b><%
} else {
//-------- Do THE DIFFS ------------
int ln1 = 0;
int ln2 = 0;
String rp1 = data.param[0];
String rp2 = data.param[1];
String reqURI = request.getRequestURI();
String[] file1 = data.file[0];
String[] file2 = data.file[1];
DiffType type = data.type;
boolean full = data.full;
%>
<%= getAnnotateRevision(data) %>
<div id="diffbar">
<div class="legend">
<span class="d">Deleted</span>
<span class="a">Added</span>
</div>
<div class="tabs"><%
for (DiffType t : DiffType.values()) {
if (type == t) {
%> <span class="active"><%= t.toString() %><%
if (t == DiffType.OLD) {
%> ( <%= data.rev[0] %> )<%
} else if (t == DiffType.NEW) {
%> ( <%= data.rev[1] %> )<%
}
%></span><%
} else {
%> <span><a href="<%= reqURI %>?r1=<%= rp1 %>&r2=<%= rp2
%>&format=<%= t.getAbbrev() %>&full=<%= full ? '1' : '0'
%>"><%= t.toString() %><%
if (t == DiffType.OLD) {
%> ( <%= data.rev[0] %> )<%
} else if (t == DiffType.NEW) {
%> ( <%= data.rev[1] %> )<%
}
%></a></span><%
}
}
%></div>
<div class="ctype"><%
if (!full) {
%>
<span><a href="<%= reqURI %>?r1=<%= rp1 %>&r2=<%= rp2
%>&format=<%= type.getAbbrev() %>&full=1">full</a></span>
<span class="active">compact</span><%
} else {
%>
<span class="active">full</span>
<span> <a href="<%= reqURI %>?r1=<%= rp1 %>&r2=<%= rp2
%>&format=<%= type.getAbbrev() %>&full=0">compact</a></span><%
}
%></div>
</div>
<div id="difftable">
<div class="pre"><%
if (type == DiffType.SIDEBYSIDE || type == DiffType.UNIFIED) {
%><table class="plain"><%
if (type == DiffType.SIDEBYSIDE) {
%>
<thead><tr>
<th><%= data.filename %> (<%= data.rev[0] %>)</th>
<th><%= data.filename %> (<%= data.rev[1] %>)</th>
</tr></thead><%
}
%>
<tbody><%
}
for (int i=0; i < data.revision.size(); i++) {
Delta d = data.revision.getDelta(i);
if (type == DiffType.TEXT) {
%><%= Util.htmlize(d.toString()) %><%
} else {
Chunk c1 = d.getOriginal();
Chunk c2 = d.getRevised();
int cn1 = c1.first();
int cl1 = c1.last();
int cn2 = c2.first();
int cl2 = c2.last();
int i1 = cn1, i2 = cn2;
StringBuilder bl1 = new StringBuilder(80);
StringBuilder bl2 = new StringBuilder(80);
for (; i1 <= cl1 && i2 <= cl2; i1++, i2++) {
Util.htmlize(file1[i1], bl1);
Util.htmlize(file2[i2], bl2);
String[] ss = Util.diffline(bl1, bl2);
file1[i1] = ss[0];
file2[i2] = ss[1];
bl1.setLength(0);
bl2.setLength(0);
}
// deleted
for (; i1 <= cl1; i1++) {
bl1.setLength(0);
bl1.append("<span class=\"d\">");
Util.htmlize(file1[i1], bl1);
file1[i1] = bl1.append("</span>").toString();
}
// added
for (; i2 <= cl2; i2++) {
bl2.setLength(0);
bl2.append("<span class=\"a\">");
Util.htmlize(file2[i2], bl2);
file2[i2] = bl2.append("</span>").toString();
}
if (type == DiffType.UNIFIED) {
// UDIFF
if (cn1 > ln1 || cn2 > ln2) {
%>
<tr class="k"><td><%
if (full || (cn2 - ln2 < 20)) {
for (int j = ln2; j < cn2; j++) {
%><i><%= ++ln2 %></i><%=
Util.htmlize(file2[j]) %><br/><%
}
} else {
for (int j = ln2; j < ln2 + 8; j++) {
%><i><%= j+1 %></i><%=
Util.htmlize(file2[j]) %><br/><%
}
%><br/>--- <b><%= cn2 - ln2 - 16
%> unchanged lines hidden</b> (<a href="<%= reqURI
%>?r1=<%= rp1 %>&r2=<%= rp2
%>&format=<%= type.getAbbrev()
%>&full=1#<%= ln2 %>">view full</a>) --- <br/><br/><%
ln2 = cn2 - 8;
for (int j = ln2; j < cn2; j++) {
%><i><%= ++ln2 %></i><%= Util.htmlize(file2[j]) %><br/><%
}
}
%></td>
</tr><%
ln1 = cn1;
}
if (cn1 <= cl1) {
%>
<tr><td><%
for (int j = cn1; j <= cl1 ; j++) {
%><del class="d"><%= ++ln1 %></del><%= file1[j]
%><br/><%
}
%></td>
</tr><%
}
if (cn2 <= cl2) {
%>
<tr class="k"><td><%
for (int j = cn2; j < cl2; j++) {
%><i class="a"><%= ++ln2 %></i><%= file2[j]
%><br/><%
}
%><i class="a"><%= ++ln2 %></i><%= file2[cl2] %><%
if(full) {
%><a name="<%= ln2 %>" /><%
}
%></td>
</tr><%
}
} else if (type == DiffType.SIDEBYSIDE) {
// SDIFF
if (cn1 > ln1 || cn2 > ln2) {
%>
<tr class="k"><td><%
if (full || cn2 - ln2 < 20) {
for (int j = ln1; j < cn1; j++) {
%><i><%= ++ln1 %></i><%=
Util.htmlize(file1[j]) %><br/><%
}
%></td><td><%
for (int j = ln2; j < cn2 ; j++) {
%><i><%= ++ln2 %></i><%=
Util.htmlize(file2[j]) %><br/><%
}
} else {
for (int j = ln1; j < ln1 + 8; j++) {
%><i><%= j+1 %></i><%=
Util.htmlize(file1[j]) %><br/><%
}
%><br/>--- <b><%= cn1 - ln1 - 16
%> unchanged lines hidden</b> (<a href="<%= reqURI
%>?r1=<%= rp1 %>&r2=<%= rp2
%>&format=<%= type.getAbbrev()
%>&full=1#<%= ln2 %>">view full</a>) --- <br/><br/><%
ln1 = cn1 - 8;
for (int j = ln1; j < cn1; j++) {
%><i><%= ++ln1 %></i><%=
Util.htmlize(file1[j]) %><br/><%
}
%></td><td><%
for (int j = ln2; j < ln2 + 8; j++) {
%><i><%= j+1 %></i><%=
Util.htmlize(file2[j]) %><br/><%
}
%><br/>--- <b><%= cn2 - ln2 - 16
%> unchanged lines hidden</b> (<a href="<%= reqURI
%>?r1=<%= rp1 %>&r2=<%= rp2
%>&format=<%= type.getAbbrev()
%>&full=1#<%= ln2 %>">view full</a>) --- <br/><br/><%
ln2 = cn2 - 8;
for (int j = ln2; j < cn2; j++) {
%><i><%= ++ln2 %></i><%=
Util.htmlize(file2[j]) %><br/><%
}
}
%></td>
</tr><%
}
%>
<tr class="k"><td><%
for (int j = cn1; j <= cl1; j++) {
%><i><%= ++ln1 %></i><%= file1[j] %><br/><%
}
%></td><td><%
for (int j = cn2; j <= cl2; j++) {
%><i><%= ++ln2 %></i><a name="<%= ln2 %>"></a><%=
file2[j] %><br/><%
}
%></td>
</tr><%
// OLD
} else if (type == DiffType.OLD) {
// OLD
if (cn1 > ln1) {
if (full || cn1 - ln1 < 20) {
for (int j = ln1; j < cn1; j++) {
%><i><%= ++ln1 %></i><%=
Util.htmlize(file1[j]) %><br/><%
}
} else {
for (int j = ln1; j < ln1 + 8; j++) {
%><i><%= j+1 %></i><%=
Util.htmlize(file1[j]) %><br/><%
}
%><br/>--- <b><%= cn1 - ln1 - 16
%> unchanged lines hidden</b> (<a href="<%= reqURI
%>?r1=<%= rp1 %>&r2=<%= rp2
%>&format=<%= type.getAbbrev()
%>&full=1#<%=ln1%>">view full</a>) --- <br/><br/><%
ln1 = cn1 - 8;
for (int j = ln1; j < cn1; j++) {
%><i><%= ++ln1 %></i><%=
Util.htmlize(file1[j]) %><br/><%
}
}
}
for (int j = cn1; j <= cl1 ; j++) {
%><i><%= ++ln1 %></i><%= file1[j] %><br/><%
}
if (full) {
%><a name="<%=ln1%>" ></a><%
}
// NEW
} else if (type == DiffType.NEW) {
if (cn2 > ln2) {
if (full || cn2 - ln2 < 20) {
for (int j = ln2; j < cn2 ; j++) {
%><i><%= ++ln2 %></i><%=
Util.htmlize(file2[j]) %><br/><%
}
} else {
for (int j = ln2; j < ln2 + 8; j++) {
%><i><%= j+1 %></i><%=
Util.htmlize(file2[j]) %><br/><%
}
%><br/>--- <b><%= cn2 - ln2 - 16
%> unchanged lines hidden</b> (<a href="<%= reqURI
%>?r1=<%= rp1 %>&r2=<%= rp2
%>&format=<%= type.getAbbrev()
%>&full=1#<%= ln2 %>">view full</a>) --- <br/><br/><%
ln2 = cn2 - 8;
for (int j = ln2; j < cn2; j++) {
%><i><%= ++ln2 %></i><%=
Util.htmlize(file2[j]) %><br/><%
}
}
}
for (int j = cn2; j <= cl2 ; j++) {
%><i><%= ++ln2 %></i><%= file2[j] %><br/><%
}
if (full) {
%><a name="<%= ln2 %>"></a><%
}
}
} // else
} // for
// deltas done, dump the remaining
if (file1.length >= ln1) {
if (type == DiffType.SIDEBYSIDE) {
if (full || file1.length - ln1 < 20) {
%>
<tr><td><%
for (int j = ln1; j < file1.length ; j++) {
%><i><%= j+1 %></i><%= Util.htmlize(file1[j]) %><br/><%
}
%></td><td><%
for (int j = ln2; j < file2.length ; j++) {
%><i><%= j+1 %></i><%= Util.htmlize(file2[j]) %><br/><%
}
%></td>
</tr>
</tbody>
</table><%
} else {
%>
<tr><td><%
for (int j = ln1; j < ln1 + 8 ; j++) {
%><i><%= j+1 %></i><%= Util.htmlize(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(file2[j]) %><br/><%
}
%><br/>--- <b><%= file1.length - ln1 - 8
%> unchanged lines hidden</b> ---</td>
</tr>
</tbody>
</table><%
}
} else if (type == DiffType.UNIFIED) {
if (full || file2.length - ln2 < 20) {
%>
<tr><td><%
for (int j = ln2; j < file2.length ; j++) {
%><i><%= j+1 %></i><%= Util.htmlize(file2[j]) %><br/><%
}
%></td>
</tr>
</tbody>
</table><%
} else {
%>
<tr><td><%
for (int j = ln2; j < ln2 + 8 ; j++) {
%><i><%= j+1 %></i><%= Util.htmlize(file2[j]) %><br/><%
}
%><br/>--- <b><%= file2.length - ln2 - 8
%> unchanged lines hidden</b> ---</td>
</tr>
</tbody>
</table><%
}
} else if (type == DiffType.OLD) {
if (full || file1.length - ln1 < 20) {
for (int j = ln1; j < file1.length ; j++) {
%><i><%= j+1 %></i><%= Util.htmlize(file1[j]) %><br/><%
}
} else {
for (int j = ln1; j < ln1 + 8 ; j++) {
%><i><%= j+1 %></i><%= Util.htmlize(file1[j]) %><br/><%
}
%><br/> --- <b><%= file1.length - ln1 - 8
%> unchanged lines hidden</b> ---<br/><%
}
} else if (type == DiffType.NEW) {
if (full || file2.length - ln2 < 20) {
for (int j = ln2; j < file2.length ; j++) {
%><i><%= j+1 %></i><%=Util.htmlize(file2[j])%><br/><%
}
} else {
for (int j = ln2; j < ln2 + 8 ; j++) {
%><i><%= j+1 %></i><%= Util.htmlize(file2[j]) %><br/><%
}
%><br/> --- <b><%= file2.length - ln2 - 8
%> unchanged lines hidden</b> ---<br/><%
}
}
}
//----DIFFS Done--------
%></div>
</div><%
}
}
/* ---------------------- diff.jsp end --------------------- */
%><%@
include file="foot.jspf"
%>