Skip to content

The Unified and Autonomous Development Platform

text diff panel.

robin shine71c11ac6f3c3
diff --git a/commons.git/src/main/java/com/pmease/commons/git/GitText.java b/commons.git/src/main/java/com/pmease/commons/git/GitText.java
index 5d28624bce..db18f9fda8 100644
--- a/commons.git/src/main/java/com/pmease/commons/git/GitText.java
+++ b/commons.git/src/main/java/com/pmease/commons/git/GitText.java
@@ -6,8 +6,12 @@ import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
+import javax.annotation.Nullable;
+
import org.apache.commons.lang3.StringUtils;
+import com.pmease.commons.util.Charsets;
+
@SuppressWarnings("serial")
public class GitText implements Serializable {
@@ -17,9 +21,12 @@ public class GitText implements Serializable {
private final boolean hasEolAtEof;
- public GitText(List<String> lines, boolean hasEolAtEof) {
+ private final String charset;
+
+ public GitText(List<String> lines, boolean hasEolAtEof, String charset) {
this.lines = lines;
this.hasEolAtEof = hasEolAtEof;
+ this.charset = charset;
}
public boolean isHasEolAtEof() {
@@ -30,6 +37,10 @@ public class GitText implements Serializable {
return lines;
}
+ public String getCharset() {
+ return charset;
+ }
+
public GitText ignoreEOL() {
List<String> processedLines = new ArrayList<>();
for (String line: lines) {
@@ -37,23 +48,23 @@ public class GitText implements Serializable {
line = line.substring(0, line.length()-1);
processedLines.add(line);
}
- return new GitText(processedLines, hasEolAtEof);
+ return new GitText(processedLines, hasEolAtEof, charset);
}
- public GitText ignoreEOLWhitespaces() {
+ public GitText ignoreEOLSpaces() {
List<String> processedLines = new ArrayList<>();
for (String line: lines)
processedLines.add(StringUtils.stripEnd(line, " \t\r"));
- return new GitText(processedLines, hasEolAtEof);
+ return new GitText(processedLines, hasEolAtEof, charset);
}
- public GitText ignoreWhitespaces() {
+ public GitText ignoreChangeSpaces() {
List<String> processedLines = new ArrayList<>();
for (String line: lines) {
line = WHITESPACE_PATTERN.matcher(line.trim()).replaceAll(" ");
processedLines.add(line);
}
- return new GitText(processedLines, hasEolAtEof);
+ return new GitText(processedLines, hasEolAtEof, charset);
}
/**
@@ -64,26 +75,31 @@ public class GitText implements Serializable {
* @param bytes
* bytes to read lines from
* @return
- * resulting GitText
+ * resulting GitText, <tt>null</tt> if charset can not be detected
*/
- public static GitText from(byte[] bytes, Charset charset) {
- List<String> lines = new ArrayList<>();
- StringBuilder builder = new StringBuilder();
- String string = new String(bytes, charset);
- for (int i=0; i<string.length(); i++) {
- char ch = string.charAt(i);
- if (ch == '\n') {
+ public static @Nullable GitText from(byte[] bytes) {
+ Charset charset = Charsets.detectFrom(bytes);
+ if (charset != null) {
+ List<String> lines = new ArrayList<>();
+ StringBuilder builder = new StringBuilder();
+ String string = new String(bytes, charset);
+ for (int i=0; i<string.length(); i++) {
+ char ch = string.charAt(i);
+ if (ch == '\n') {
+ lines.add(builder.toString());
+ builder = new StringBuilder();
+ } else {
+ builder.append(ch);
+ }
+ }
+ if (builder.length() != 0) {
lines.add(builder.toString());
- builder = new StringBuilder();
+ return new GitText(lines, false, charset.name());
} else {
- builder.append(ch);
+ return new GitText(lines, true, charset.name());
}
- }
- if (builder.length() != 0) {
- lines.add(builder.toString());
- return new GitText(lines, false);
} else {
- return new GitText(lines, true);
+ return null;
}
}
diff --git a/commons.git/src/test/java/com/pmease/commons/git/GitTest.java b/commons.git/src/test/java/com/pmease/commons/git/GitTest.java
index f568891339..d6c34a1a19 100644
--- a/commons.git/src/test/java/com/pmease/commons/git/GitTest.java
+++ b/commons.git/src/test/java/com/pmease/commons/git/GitTest.java
@@ -2,16 +2,10 @@ package com.pmease.commons.git;
import static org.junit.Assert.assertEquals;
-import java.io.File;
-import java.io.IOException;
import java.util.List;
-import org.apache.commons.io.FileUtils;
import org.junit.Test;
-import com.pmease.commons.util.Charsets;
-import com.pmease.commons.util.MediaTypes;
-
public class GitTest extends AbstractGitTest {
@Test
@@ -85,19 +79,4 @@ public class GitTest extends AbstractGitTest {
assertEquals(DiffTreeNode.Status.DELETE, diffs.get(0).getStatus());
}
- @Test
- public void test() {
- try {
- System.out.println(MediaTypes.detectFrom(FileUtils.readFileToByteArray(new File("w:\\temp\\file.txt")), null));
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- try {
- System.out.println(Charsets.detectFrom(FileUtils.readFileToByteArray(new File("w:\\temp\\file.txt"))));
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
}
diff --git a/commons.git/src/test/java/com/pmease/commons/git/GitTextTest.java b/commons.git/src/test/java/com/pmease/commons/git/GitTextTest.java
index 5a0bbc641b..d4a52cc031 100644
--- a/commons.git/src/test/java/com/pmease/commons/git/GitTextTest.java
+++ b/commons.git/src/test/java/com/pmease/commons/git/GitTextTest.java
@@ -1,19 +1,19 @@
package com.pmease.commons.git;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import org.junit.Test;
-import com.google.common.collect.Lists;
-
public class GitTextTest {
@Test
public void test() {
- GitText result = new GitText(Lists.newArrayList(" hello \tworld \t \r"), true);
+ GitText result = GitText.from(" hello \tworld \t \r".getBytes());
+ assertNotNull(result);
assertEquals(" hello \tworld \t ", result.ignoreEOL().getLines().get(0));
- assertEquals(" hello \tworld", result.ignoreEOLWhitespaces().getLines().get(0));
- assertEquals("hello world", result.ignoreWhitespaces().getLines().get(0));
+ assertEquals(" hello \tworld", result.ignoreEOLSpaces().getLines().get(0));
+ assertEquals("hello world", result.ignoreChangeSpaces().getLines().get(0));
}
}
diff --git a/commons.git/src/test/java/com/pmease/commons/git/GitUtilsTest.java b/commons.git/src/test/java/com/pmease/commons/git/GitUtilsTest.java
index 55a94c0915..7115a0faeb 100644
--- a/commons.git/src/test/java/com/pmease/commons/git/GitUtilsTest.java
+++ b/commons.git/src/test/java/com/pmease/commons/git/GitUtilsTest.java
@@ -5,18 +5,17 @@ import static org.junit.Assert.assertEquals;
import org.junit.Test;
import com.google.common.collect.Lists;
-import com.pmease.commons.util.Charsets;
public class GitUtilsTest {
@Test
public void testReadLines() {
String content = "中文测试\r\nsecond line";
- GitText result = GitText.from(content.getBytes(), Charsets.detectFrom(content.getBytes()));
+ GitText result = GitText.from(content.getBytes());
assertEquals(Lists.newArrayList("中文测试\r", "second line"), result.getLines());
assertEquals(false, result.isHasEolAtEof());
- result = GitText.from("\nhello\n\nworld\n".getBytes(), Charsets.UTF_8);
+ result = GitText.from("\nhello\n\nworld\n".getBytes());
assertEquals(Lists.newArrayList("", "hello", "", "world"), result.getLines());
}
diff --git a/commons.util/src/main/java/com/pmease/commons/util/diff/DiffChunk.java b/commons.util/src/main/java/com/pmease/commons/util/diff/DiffChunk.java
index fdd7fea686..1df8075786 100644
--- a/commons.util/src/main/java/com/pmease/commons/util/diff/DiffChunk.java
+++ b/commons.util/src/main/java/com/pmease/commons/util/diff/DiffChunk.java
@@ -1,10 +1,12 @@
package com.pmease.commons.util.diff;
+import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-public class DiffChunk {
+@SuppressWarnings("serial")
+public class DiffChunk implements Serializable {
private final int start1;
diff --git a/commons.util/src/main/java/com/pmease/commons/util/diff/DiffLine.java b/commons.util/src/main/java/com/pmease/commons/util/diff/DiffLine.java
index 6eb8764d9d..6fbd8c1d55 100644
--- a/commons.util/src/main/java/com/pmease/commons/util/diff/DiffLine.java
+++ b/commons.util/src/main/java/com/pmease/commons/util/diff/DiffLine.java
@@ -1,10 +1,12 @@
package com.pmease.commons.util.diff;
+import java.io.Serializable;
import java.util.List;
import com.google.common.collect.Lists;
-public class DiffLine {
+@SuppressWarnings("serial")
+public class DiffLine implements Serializable {
public enum Action {
diff --git a/commons.util/src/main/java/com/pmease/commons/util/diff/DiffUtils.java b/commons.util/src/main/java/com/pmease/commons/util/diff/DiffUtils.java
index dc771d41b2..c6e4848975 100644
--- a/commons.util/src/main/java/com/pmease/commons/util/diff/DiffUtils.java
+++ b/commons.util/src/main/java/com/pmease/commons/util/diff/DiffUtils.java
@@ -90,7 +90,7 @@ public class DiffUtils {
if (diffPartial.getAction() == DiffLine.Action.EQUAL)
equals++;
}
- if (equals*2 >= diffPartials.size()) {
+ if (equals*3 >= diffPartials.size()) {
for (int j=0; j<i; j++)
processedAdditions.add(new DiffLine(DiffLine.Action.ADD, additions.get(j)));
for (int j=0; j<=i; j++)
@@ -153,31 +153,35 @@ public class DiffUtils {
}
public static List<DiffChunk> chunksOf(List<DiffLine> diffLines, int contextLines) {
- List<RemovableDiffLine> removeAwareDiffLines = new ArrayList<>();
+ List<RemovableDiffLine> removableDiffLines = new ArrayList<>();
for (DiffLine diffLine: diffLines)
- removeAwareDiffLines.add(new RemovableDiffLine(diffLine, false));
+ removableDiffLines.add(new RemovableDiffLine(diffLine, false));
int equalCount = 0;
int index = 0;
- for (RemovableDiffLine each: removeAwareDiffLines) {
+ for (RemovableDiffLine each: removableDiffLines) {
if (each.diffLine.getAction() == Action.EQUAL) {
equalCount++;
+ } else if (index == equalCount) {
+ for (int i=index-equalCount; i<index-contextLines; i++)
+ removableDiffLines.get(i).removed = true;
+ equalCount = 0;
} else {
- for (int i=index-equalCount+contextLines; i<=index-contextLines-1; i++)
- removeAwareDiffLines.get(i).removed = true;
+ for (int i=index-equalCount+contextLines; i<index-contextLines; i++)
+ removableDiffLines.get(i).removed = true;
equalCount = 0;
}
index++;
}
- for (int i=index-equalCount+contextLines; i<=index-contextLines-1; i++)
- removeAwareDiffLines.get(i).removed = true;
+ for (int i=index-equalCount+contextLines; i<index; i++)
+ removableDiffLines.get(i).removed = true;
List<DiffChunk> diffChunks = new ArrayList<>();
int start1 = 0;
int start2 = 0;
DiffChunkBuilder chunkBuilder = new DiffChunkBuilder();
- for (RemovableDiffLine each: removeAwareDiffLines) {
+ for (RemovableDiffLine each: removableDiffLines) {
if (!each.removed) {
if (chunkBuilder.diffUnits.isEmpty()) {
chunkBuilder.start1 = start1;
diff --git a/commons.util/src/main/java/com/pmease/commons/util/diff/Partial.java b/commons.util/src/main/java/com/pmease/commons/util/diff/Partial.java
index b10d736d54..c26141edeb 100644
--- a/commons.util/src/main/java/com/pmease/commons/util/diff/Partial.java
+++ b/commons.util/src/main/java/com/pmease/commons/util/diff/Partial.java
@@ -1,6 +1,9 @@
package com.pmease.commons.util.diff;
-public class Partial {
+import java.io.Serializable;
+
+@SuppressWarnings("serial")
+public class Partial implements Serializable {
private final String content;
diff --git a/commons.util/src/test/java/com/pmease/commons/util/diff/DiffUtilsTest.java b/commons.util/src/test/java/com/pmease/commons/util/diff/DiffUtilsTest.java
index 4676ac5f48..74af6f13d4 100644
--- a/commons.util/src/test/java/com/pmease/commons/util/diff/DiffUtilsTest.java
+++ b/commons.util/src/test/java/com/pmease/commons/util/diff/DiffUtilsTest.java
@@ -114,6 +114,34 @@ public class DiffUtilsTest {
" this is the 10th line\n" +
"+this is the 11th line\n",
diffChunks.get(1).toString());
+
+ text1 = new ArrayList<>();
+ text1.add("this is the 1st line");
+ text1.add("this is the 2nd line");
+ text1.add("this is the 3rd line");
+ text1.add("this is the 4th line");
+ text1.add("this is the 5th line");
+ text1.add("this is the 6th line");
+ text1.add("this is the 7th line");
+ text1.add("this is the 8th line");
+ text1.add("this is the 9th line");
+ text1.add("this is the 10th line");
+
+ text2 = new ArrayList<>();
+ text2.add("this is the 1st line");
+ text2.add("this is the 2nd line");
+ text2.add("this is the 3rd line");
+ text2.add("this is the 4th line");
+ text2.add("this is the 5 line");
+ text2.add("this is the 6th line");
+ text2.add("this is the 7th line");
+ text2.add("this is the 8th line");
+ text2.add("this is the 9th line");
+ text2.add("this is the 10th line");
+
+ diffChunks = DiffUtils.diffAsChunks(text1, text2, null, 3);
+
+ assertEquals(1, diffChunks.size());
}
@Test
@@ -166,7 +194,6 @@ public class DiffUtilsTest {
"-this is the 4th line\n" +
"+I do not think this works\n",
diffChunks.get(0).toString());
-
}
@Test
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/asset/common.css b/commons.wicket/src/main/java/com/pmease/commons/wicket/asset/common.css
index 12daac7f9a..bcd88f1b17 100644
--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/asset/common.css
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/asset/common.css
@@ -105,13 +105,13 @@ table td, table th {text-align: left;}
.dropdown-panel.menu .content {padding: 4px 0; min-width: 120px;}
.dropdown-panel.menu ul {list-style: none outside none; margin:0; padding: 0;}
.dropdown-panel.menu a {clear: both; color: #333333; display: block; font-weight: normal; line-height: 20px;
- padding: 3px 20px; white-space: nowrap;}
+ padding: 3px 20px; white-space: nowrap; text-decoration: none;}
.dropdown-panel.menu li.submenu>a {margin-right: 2px; margin-left: 2px; padding-left: 18px; padding-right: 18px;}
.dropdown-panel.menu li.submenu>a:after {border-color: transparent transparent transparent #CCCCCC; border-style: solid;
border-width: 5px 0 5px 5px; content: " "; display: block; float: right; height: 0; margin-right: -10px; margin-top: 5px; width: 0;}
.dropdown-panel.menu li.submenu:hover > a:after {border-left-color: #FFFFFF;}
-.dropdown-panel.menu a:hover {color: #FFFFFF; text-decoration: none;}
-.dropdown-panel.menu li:hover {background-color: #0088CC;}
+.dropdown-panel.menu li:hover {background-color: #f5f5f5;}
+.dropdown-panel.menu li input[type=checkbox] {margin-right: 8px; vertical-align: text-bottom;}
.dropdown-panel.menu .divider {background-color: #E5E5E5; border-bottom: 1px solid #FFFFFF; height: 1px;
margin: 8px 1px; overflow: hidden;}
.dropdown-panel.menu li.divider:hover {background-color: #E5E5E5;}
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/menu/CheckMenuItem.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/menu/CheckMenuItem.java
new file mode 100644
index 0000000000..89017d03b9
--- /dev/null
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/menu/CheckMenuItem.java
@@ -0,0 +1,20 @@
+package com.pmease.commons.wicket.behavior.menu;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.model.IModel;
+
+@SuppressWarnings("serial")
+public abstract class CheckMenuItem extends MenuItem {
+
+ @Override
+ public Component newContent(String componentId) {
+ return new CheckMenuItemComponent(componentId, this);
+ }
+
+ protected abstract String getLabel();
+
+ protected abstract IModel<Boolean> getCheckModel();
+
+ protected abstract void onUpdate(AjaxRequestTarget target);
+}
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/menu/CheckMenuItemComponent.html b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/menu/CheckMenuItemComponent.html
new file mode 100644
index 0000000000..061a96b54a
--- /dev/null
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/menu/CheckMenuItemComponent.html
@@ -0,0 +1,3 @@
+<wicket:panel>
+ <input wicket:id="checkbox" type="checkbox"> <span wicket:id="label"></span>
+</wicket:panel>
\ No newline at end of file
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/menu/CheckMenuItemComponent.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/menu/CheckMenuItemComponent.java
new file mode 100644
index 0000000000..c446c0249a
--- /dev/null
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/menu/CheckMenuItemComponent.java
@@ -0,0 +1,35 @@
+package com.pmease.commons.wicket.behavior.menu;
+
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.markup.html.form.AjaxCheckBox;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.panel.Panel;
+
+@SuppressWarnings("serial")
+class CheckMenuItemComponent extends Panel {
+
+ private final CheckMenuItem menuItem;
+
+ public CheckMenuItemComponent(String id, CheckMenuItem menuItem) {
+ super(id);
+
+ this.menuItem = menuItem;
+ }
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ add(new AjaxCheckBox("checkbox", menuItem.getCheckModel()) {
+
+ @Override
+ protected void onUpdate(AjaxRequestTarget target) {
+ menuItem.onUpdate(target);
+ }
+
+ });
+
+ add(new Label("label", menuItem.getLabel()));
+ }
+
+}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/assets/css/page.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/assets/css/page.css
index 20b106e6eb..907dc70fce 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/assets/css/page.css
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/assets/css/page.css
@@ -898,17 +898,45 @@ h2.section-title { margin: 18px 0; font-size: 16px; }
.diff-tree .unchanged {color: #888;}
.diff-tree em span {font-style: normal;}
-/* BLOB DIFF*/
-.blob-diff>.content {font-family: Consolas, 'Liberation Mono', Courier, monospace;
- margin-bottom: 16px;}
-.blob-diff>.content>.original {border: 1px dashed #F83C3C; border-radius: 4px;
- margin-bottom: 16px;}
-.blob-diff>.content>.original>.head {background: #FDB7B7; color: #BF0707; padding: 4px 8px;
- border-bottom: 1px dashed #F83C3C;}
-.blob-diff>.content>.revised {border: 1px dashed #05B505; border-radius: 4px;}
-.blob-diff>.content>.revised>.head {background: #94E294; color: #1F731F; padding: 4px 8px;
- border-bottom: 1px dashed #05B505;}
-.blob-diff>.content>.original>.body, .blob-diff>.content>.revised>.body {padding: 4px 8px;}
+/* TEXT DIFF */
+.text-diff>.panel-heading .fa.action {cursor: pointer; margin-left: 8px;}
+.text-diff .hunk-line .content pre { background: transparent; margin: 0; padding: 0; word-break: normal;
+ word-wrap: normal; border: none; font-size: 12px; line-height: 20px; white-space: pre; }
+.table-diff {font-size: 12px;}
+.table-diff .hunk-head, .equal.hunk-line>td.info {color: #999;}
+.table-diff .hunk-head a {display: block; color: #999;}
+.table-diff .hunk-head a:hover {color: #444;}
+.table-diff .hunk-head td.info {text-align: center;}
+.table-diff>tbody>tr>td {padding: 0 8px; vertical-align: top;}
+.table-diff>tbody>tr>td.content, .table-diff>tbody>tr>td.revised {
+ border-left: 1px solid #E5E5E5;}
+.revised.hunk-line {background: none repeat scroll 0 0 #cfc;}
+.revised.hunk-line>td.info {background: none repeat scroll 0 0 #89FB89; color: #007f00;}
+.original.hunk-line>td.info {background: none repeat scroll 0 0 #faa; color: #8f0000;}
+.original.hunk-line {background: none repeat scroll 0 0 #fdd;}
+.hunk-line>td.info {width: 1%; text-align: right; white-space: nowrap;}
+.original.hunk-line .emphasize {background: #FC9090;}
+.revised.hunk-line .emphasize {background: #07C907;}
+.table-diff .hunk-head {background: none repeat scroll 0 0 #eef;}
+.table-diff .hunk-row:hover {background: #fea; }
+.table-diff .hunk-row:hover .info {background: #FBDE6D;}
+ul.diff-alerts li {text-align: left;}
+ul.diff-alerts {padding-left: 12px;}
+
+/* BLOB DIFF */
+.blob-diff {border: 1px solid #BBB; border-radius: 4px;}
+.blob-diff>.head {border-bottom: 1px solid #BBB; padding: 4px 8px; font-size: 16px;
+ border-radius: 4px 4px 0 0; background: #F2F2F2;}
+.blob-diff>.body {padding: 8px;}
+.blob-diff.original {margin-bottom: 16px;}
+.blob-diff.original, .blob-diff.original>.head {border-color: #FC9494;}
+.blob-diff.revised, .blob-diff.revised>.head {border-color: #07C707;}
+.blob-diff.original>.head {color: #FA5A5A; background: #FDBFBF;}
+.blob-diff.revised>.head {color: #059505; background: #B6F8A2;}
+.blob-diff .line {padding: 4px 8px;}
+.blob-diff .line>.fa {width: 16px;}
+.blob-diff .original.line {background: #FCA6A6; color: #8f0000;}
+.blob-diff .revised.line {background: #B6F8A2; color: #007f00;}
/* BRANCH CHOICE */
.affinal-branch-choice .connector {margin: 4px 0 0 0; color: #BBB; font-weight: bold;
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/BlobDiffInfo.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/BlobDiffInfo.java
index 0b20e11a82..bdd94d7cc9 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/BlobDiffInfo.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/BlobDiffInfo.java
@@ -1,10 +1,13 @@
package com.pmease.gitplex.web.component.diff;
+import java.io.Serializable;
+
import com.pmease.commons.git.DiffTreeNode;
import com.pmease.commons.git.FileChange;
import com.pmease.commons.git.Git;
-public class BlobDiffInfo {
+@SuppressWarnings("serial")
+public class BlobDiffInfo implements Serializable {
public enum Status {ADD, MODIFY, DELETE, RENAME, UNCHANGE}
@@ -22,19 +25,13 @@ public class BlobDiffInfo {
private final String newRevision;
- private final byte[] oldContent;
-
- private final byte[] newContent;
-
public BlobDiffInfo(Status status, String oldPath, String newPath, int oldMode, int newMode,
- String oldRevision, String newRevision, byte[] oldContent, byte[] newContent) {
+ String oldRevision, String newRevision) {
this.status = status;
this.oldPath = oldPath;
this.newPath = newPath;
this.oldMode = oldMode;
this.newMode = newMode;
- this.oldContent = oldContent;
- this.newContent = newContent;
this.oldRevision = oldRevision;
this.newRevision = newRevision;
}
@@ -67,60 +64,32 @@ public class BlobDiffInfo {
return newRevision;
}
- public byte[] getOldContent() {
- return oldContent;
- }
-
- public byte[] getNewContent() {
- return newContent;
- }
-
public static BlobDiffInfo from(Git git, DiffTreeNode node, String oldRevision, String newRevision) {
Status status;
- byte[] oldContent, newContent;
- if (node.getStatus() == DiffTreeNode.Status.ADD) {
+ if (node.getStatus() == DiffTreeNode.Status.ADD)
status = Status.ADD;
- oldContent = null;
- newContent = git.read(newRevision, node.getPath(), node.getNewMode());
- } else if (node.getStatus() == DiffTreeNode.Status.DELETE) {
+ else if (node.getStatus() == DiffTreeNode.Status.DELETE)
status = Status.DELETE;
- oldContent = git.read(oldRevision, node.getPath(), node.getOldMode());
- newContent = null;
- } else if (node.getStatus() == DiffTreeNode.Status.UNCHANGE) {
+ else if (node.getStatus() == DiffTreeNode.Status.UNCHANGE)
status = Status.UNCHANGE;
- oldContent = newContent = git.read(newRevision, node.getPath(), node.getNewMode());
- } else {
+ else
status = Status.MODIFY;
- oldContent = git.read(oldRevision, node.getPath(), node.getOldMode());
- newContent = git.read(newRevision, node.getPath(), node.getNewMode());
- }
return new BlobDiffInfo(status, node.getPath(), node.getPath(), node.getOldMode(),
- node.getNewMode(), oldRevision, newRevision, oldContent, newContent);
+ node.getNewMode(), oldRevision, newRevision);
}
public static BlobDiffInfo from(Git git, FileChange change, String oldRevision, String newRevision) {
Status status;
- byte[] oldContent, newContent;
- if (change.getStatus() == FileChange.Status.ADD) {
+ if (change.getStatus() == FileChange.Status.ADD)
status = Status.ADD;
- oldContent = null;
- newContent = git.show(newRevision, change.getNewPath());
- } else if (change.getStatus() == FileChange.Status.DELETE) {
+ else if (change.getStatus() == FileChange.Status.DELETE)
status = Status.DELETE;
- oldContent = git.show(oldRevision, change.getOldPath());
- newContent = null;
- } else if (change.getStatus() == FileChange.Status.MODIFY) {
+ else if (change.getStatus() == FileChange.Status.MODIFY)
status = Status.MODIFY;
- oldContent = git.show(oldRevision, change.getOldPath());
- newContent = git.show(newRevision, change.getNewPath());
- } else {
+ else
status = Status.RENAME;
- oldContent = git.show(oldRevision, change.getOldPath());
- newContent = git.show(newRevision, change.getNewPath());
- }
return new BlobDiffInfo(status, change.getOldPath(), change.getNewPath(),
- change.getOldMode(), change.getNewMode(), oldRevision, newRevision,
- oldContent, newContent);
+ change.getOldMode(), change.getNewMode(), oldRevision, newRevision);
}
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/BlobDiffPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/BlobDiffPanel.html
index 7fc38db43a..e87ef8372d 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/BlobDiffPanel.html
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/BlobDiffPanel.html
@@ -1,42 +1,64 @@
<wicket:panel>
- <div class="blob-diff">
- <div class="well well-sm">
- <div wicket:id="blobRenamed">
- <strong wicket:id="oldPath"></strong> is renamed to <strong wicket:id="newPath"></strong>
+ <wicket:enclosure child="originalContent">
+ <div class="blob-diff original">
+ <div class="head">
+ <i class="fa fa-minus"></i> <span wicket:id="originalTitle"></span>
</div>
- <div wicket:id="blobAdded">
- <strong wicket:id="newPath"></strong> is added
- </div>
- <div wicket:id="blobDeleted">
- <strong wicket:id="oldPath"></strong> is deleted
+ <div wicket:id="originalContent" class="body"></div>
+ </div>
+ </wicket:enclosure>
+ <wicket:enclosure child="revisedContent">
+ <div class="blob-diff revised">
+ <div class="head">
+ <i class="fa fa-plus"></i> <span wicket:id="revisedTitle"></span>
</div>
- <div wicket:id="blobModified">
- <strong wicket:id="oldPath"></strong> is modified
+ <div wicket:id="revisedContent" class="body"></div>
+ </div>
+ </wicket:enclosure>
+ <div wicket:id="blobContent"></div>
+ <wicket:fragment wicket:id="notChangedFrag">
+ <div class="panel panel-default">
+ <div class="panel-heading">
+ <div class="panel-title"><span wicket:id="title"></span> <em>is not changed</em></div>
</div>
- <div wicket:id="blobUnchanged">
- <strong wicket:id="oldPath"></strong> is unchanged
+ <div wicket:id="content" class="panel-body"></div>
+ </div>
+ </wicket:fragment>
+ <wicket:fragment wicket:id="emptyFileFrag">
+ <div class="panel panel-default">
+ <div class="panel-heading"><span wicket:id="summary"></span></div>
+ <div class="panel-body">
+ <i class='fa fa-info-circle'></i> <em>File is empty</em>
</div>
- <div wicket:id="blobTypeChanged">
- Blob type is changed from <strong wicket:id="oldType"></strong> to <strong wicket:id="newType"></strong>
+ </div>
+ </wicket:fragment>
+ <wicket:fragment wicket:id="binaryFileFrag">
+ <div class="panel panel-default">
+ <div class="panel-heading"><span wicket:id="summary"></span></div>
+ <div class="panel-body">
+ <i class='fa fa-info-circle'></i> <em>Binary files</em>
</div>
- <div wicket:id="fileModeChanged">
- File mode is changed from <strong wicket:id="oldMode"></strong> to <strong wicket:id="newMode"></strong>
+ </div>
+ </wicket:fragment>
+ <wicket:fragment wicket:id="nonFileDiffFrag">
+ <div class="blob-diff">
+ <div class="head">
+ <wicket:enclosure child="renamedTitle">
+ <span wicket:id="renamedTitle"></span>
+ <i class="fa fa-arrow-slim-right"></i>
+ </wicket:enclosure>
+ <span wicket:id="title"></span>
</div>
- </div>
- <div class="content">
- <wicket:enclosure child="originalContent">
- <div class="original">
- <div class="head"><i class="fa fa-minus"></i> old content</div>
- <div wicket:id="originalContent" class="body"></div>
+ <div class="body">
+ <div class="original line">
+ <i class="fa fa-minus"></i>
+ <span wicket:id="oldContent"></span>
</div>
- </wicket:enclosure>
- <wicket:enclosure child="revisedContent">
- <div class="revised">
- <div class="head"><i class="fa fa-plus"></i> new content</div>
- <div wicket:id="revisedContent" class="body"></div>
+ <div class="revised line">
+ <i class="fa fa-plus"></i>
+ <span wicket:id="newContent"></span>
</div>
- </wicket:enclosure>
- <div wicket:id="blobContent"></div>
- </div>
- </div>
+ </div>
+ </div>
+ </wicket:fragment>
</wicket:panel>
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/BlobDiffPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/BlobDiffPanel.java
index 59ab8fa3a7..a10f91d8e1 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/BlobDiffPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/BlobDiffPanel.java
@@ -1,21 +1,19 @@
package com.pmease.gitplex.web.component.diff;
-import java.nio.charset.Charset;
import java.util.ArrayList;
-import java.util.Arrays;
import org.apache.tika.mime.MediaType;
import org.apache.wicket.Component;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.panel.Fragment;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;
-import org.apache.wicket.model.Model;
import org.eclipse.jgit.lib.FileMode;
+import com.pmease.commons.git.Git;
import com.pmease.commons.git.GitText;
-import com.pmease.commons.git.GitUtils;
import com.pmease.commons.util.Charsets;
import com.pmease.commons.util.MediaTypes;
import com.pmease.gitplex.core.GitPlex;
@@ -24,10 +22,8 @@ import com.pmease.gitplex.web.component.gitlink.GitLink;
import com.pmease.gitplex.web.component.symbollink.SymbolLink;
import com.pmease.gitplex.web.component.view.BlobRenderInfo;
import com.pmease.gitplex.web.component.view.BlobViewPanel;
-import com.pmease.gitplex.web.component.view.TextRenderInfo;
import com.pmease.gitplex.web.extensionpoint.DiffRenderer;
import com.pmease.gitplex.web.extensionpoint.DiffRendererProvider;
-import com.pmease.gitplex.web.extensionpoint.MediaRenderInfo;
import com.pmease.gitplex.web.extensionpoint.TextConverter;
import com.pmease.gitplex.web.extensionpoint.TextConverterProvider;
@@ -36,209 +32,192 @@ public class BlobDiffPanel extends Panel {
private final IModel<Repository> repoModel;
- private final IModel<BlobDiffInfo> blobDiffModel;
+ private final BlobDiffInfo diffInfo;
- public BlobDiffPanel(String id, IModel<Repository> repoModel, IModel<BlobDiffInfo> blobDiffModel) {
+ private final IModel<byte[]> oldContentModel;
+
+ private final IModel<byte[]> newContentModel;
+
+ public BlobDiffPanel(String id, IModel<Repository> repoModel, final BlobDiffInfo diffInfo) {
super(id);
this.repoModel = repoModel;
- this.blobDiffModel = blobDiffModel;
+ this.diffInfo = diffInfo;
+
+ oldContentModel = new LoadableDetachableModel<byte[]>() {
+
+ @Override
+ protected byte[] load() {
+ Git git = BlobDiffPanel.this.repoModel.getObject().git();
+ if (diffInfo.getStatus() == BlobDiffInfo.Status.ADD)
+ return null;
+ else
+ return git.read(diffInfo.getOldRevision(), diffInfo.getOldPath(), diffInfo.getOldMode());
+
+ }
+
+ };
+ newContentModel = new LoadableDetachableModel<byte[]>() {
+
+ @Override
+ protected byte[] load() {
+ Git git = BlobDiffPanel.this.repoModel.getObject().git();
+ if (diffInfo.getStatus() == BlobDiffInfo.Status.DELETE)
+ return null;
+ else if (diffInfo.getStatus() != BlobDiffInfo.Status.UNCHANGE)
+ return git.read(diffInfo.getNewRevision(), diffInfo.getNewPath(), diffInfo.getNewMode());
+ else
+ return oldContentModel.getObject();
+ }
+
+ };
}
@Override
protected void onInitialize() {
super.onInitialize();
- BlobDiffInfo blobDiff = blobDiffModel.getObject();
-
- WebMarkupContainer blobRenamedContainer = new WebMarkupContainer("blobRenamed");
- blobRenamedContainer.setVisible(blobDiff.getStatus() == BlobDiffInfo.Status.RENAME);
- blobRenamedContainer.add(new Label("oldPath", blobDiff.getOldPath()));
- blobRenamedContainer.add(new Label("newPath", blobDiff.getNewPath()));
- add(blobRenamedContainer);
-
- WebMarkupContainer blobModifiedContainer = new WebMarkupContainer("blobModified");
- blobModifiedContainer.setVisible(blobDiff.getStatus() == BlobDiffInfo.Status.MODIFY);
- blobModifiedContainer.add(new Label("oldPath", blobDiff.getOldPath()));
- add(blobModifiedContainer);
-
- WebMarkupContainer blobAddedContainer = new WebMarkupContainer("blobAdded");
- blobAddedContainer.setVisible(blobDiff.getStatus() == BlobDiffInfo.Status.ADD);
- blobAddedContainer.add(new Label("newPath", blobDiff.getOldPath()));
- add(blobAddedContainer);
+ int oldBlobType = diffInfo.getOldMode() & FileMode.TYPE_MASK;
+ int newBlobType = diffInfo.getNewMode() & FileMode.TYPE_MASK;
- WebMarkupContainer blobDeletedContainer = new WebMarkupContainer("blobDeleted");
- blobDeletedContainer.setVisible(blobDiff.getStatus() == BlobDiffInfo.Status.DELETE);
- blobDeletedContainer.add(new Label("oldPath", blobDiff.getOldPath()));
- add(blobDeletedContainer);
-
- WebMarkupContainer blobUnchangedContainer = new WebMarkupContainer("blobUnchanged");
- blobUnchangedContainer.setVisible(blobDiff.getStatus() == BlobDiffInfo.Status.UNCHANGE);
- blobUnchangedContainer.add(new Label("oldPath", blobDiff.getOldPath()));
- add(blobUnchangedContainer);
-
- WebMarkupContainer blobTypeChangedContainer = new WebMarkupContainer("blobTypeChanged");
- int oldBlobType = blobDiff.getOldMode() & FileMode.TYPE_MASK;
- int newBlobType = blobDiff.getNewMode() & FileMode.TYPE_MASK;
- blobTypeChangedContainer.setVisible(blobDiff.getStatus() == BlobDiffInfo.Status.MODIFY
- && oldBlobType != newBlobType);
- blobTypeChangedContainer.add(new Label("oldType", GitUtils.getTypeName(oldBlobType)));
- blobTypeChangedContainer.add(new Label("newType", GitUtils.getTypeName(newBlobType)));
- add(blobTypeChangedContainer);
-
- WebMarkupContainer fileModeChangedContainer = new WebMarkupContainer("fileModeChanged");
- fileModeChangedContainer.setVisible(blobDiff.getStatus() == BlobDiffInfo.Status.MODIFY
- && oldBlobType == FileMode.TYPE_FILE && newBlobType == FileMode.TYPE_FILE
- && blobDiff.getOldMode() != blobDiff.getNewMode());
- fileModeChangedContainer.add(new Label("oldMode", Integer.toString(blobDiff.getOldMode(), 8)));
- fileModeChangedContainer.add(new Label("newMode", Integer.toString(blobDiff.getNewMode(), 8)));
- add(fileModeChangedContainer);
+ if (diffInfo.getStatus() == BlobDiffInfo.Status.UNCHANGE) {
+ add(new WebMarkupContainer("originalContent").setVisible(false));
+ add(new WebMarkupContainer("revisedContent").setVisible(false));
+ Fragment fragment = new Fragment("blobContent", "notChangedFrag", this);
+ fragment.add(new Label("title", diffInfo.getOldPath()));
+ BlobRenderInfo renderInfo = new BlobRenderInfo(diffInfo.getNewPath(),
+ diffInfo.getNewRevision(), diffInfo.getNewMode());
+ fragment.add(new BlobViewPanel("content", repoModel, renderInfo, newContentModel));
+ add(fragment);
+ } else if (oldBlobType == FileMode.TYPE_GITLINK && newBlobType == FileMode.TYPE_GITLINK) {
+ add(new WebMarkupContainer("originalContent").setVisible(false));
+ add(new WebMarkupContainer("revisedContent").setVisible(false));
- if (blobDiff.getStatus() == BlobDiffInfo.Status.UNCHANGE
- || oldBlobType == newBlobType && Arrays.equals(blobDiff.getOldContent(), blobDiff.getNewContent())) {
+ Fragment fragment = new Fragment("blobContent", "nonFileDiffFrag", this);
+ fragment.add(new Label("renamedTitle", diffInfo.getOldPath())
+ .setVisible(!diffInfo.getOldPath().equals(diffInfo.getNewPath())));
+ fragment.add(new Label("title", diffInfo.getNewPath()));
+ fragment.add(new GitLink("oldContent", new String(oldContentModel.getObject())));
+ fragment.add(new GitLink("newContent", new String(newContentModel.getObject())));
+ add(fragment);
+ } else if (oldBlobType == FileMode.TYPE_SYMLINK && newBlobType == FileMode.TYPE_SYMLINK) {
add(new WebMarkupContainer("originalContent").setVisible(false));
add(new WebMarkupContainer("revisedContent").setVisible(false));
- add(new BlobViewPanel("blobContent", repoModel, new LoadableDetachableModel<BlobRenderInfo>(){
- @Override
- protected BlobRenderInfo load() {
- BlobDiffInfo blobDiff = blobDiffModel.getObject();
- return new BlobRenderInfo(blobDiff.getNewPath(), blobDiff.getNewRevision(),
- blobDiff.getNewMode(), blobDiff.getNewContent());
- }
-
- }));
+ Fragment fragment = new Fragment("blobContent", "nonFileDiffFrag", this);
+ fragment.add(new Label("renamedTitle", diffInfo.getOldPath())
+ .setVisible(!diffInfo.getOldPath().equals(diffInfo.getNewPath())));
+ fragment.add(new Label("title", diffInfo.getNewPath()));
+ fragment.add(new SymbolLink("oldContent", repoModel, diffInfo.getOldRevision(),
+ diffInfo.getOldPath(), new String(oldContentModel.getObject())));
+ fragment.add(new SymbolLink("newContent", repoModel, diffInfo.getNewRevision(),
+ diffInfo.getNewPath(), new String(newContentModel.getObject())));
+ add(fragment);
} else if (oldBlobType == FileMode.TYPE_FILE && newBlobType == FileMode.TYPE_FILE) {
add(new WebMarkupContainer("originalContent").setVisible(false));
add(new WebMarkupContainer("revisedContent").setVisible(false));
- final MediaType originalMediaType = MediaTypes.detectFrom(blobDiff.getOldContent(), blobDiff.getOldPath());
- final MediaType revisedMediaType = MediaTypes.detectFrom(blobDiff.getNewContent(), blobDiff.getNewPath());
+ byte[] oldContent = oldContentModel.getObject();
+ byte[] newContent = newContentModel.getObject();
+ MediaType oldMediaType = MediaTypes.detectFrom(oldContent, diffInfo.getOldPath());
+ MediaType newMediaType = MediaTypes.detectFrom(newContent, diffInfo.getNewPath());
DiffRenderer renderer = null;
for (DiffRendererProvider provider: GitPlex.getExtensions(DiffRendererProvider.class)) {
- renderer = provider.getDiffRenderer(originalMediaType, revisedMediaType);
+ renderer = provider.getDiffRenderer(oldMediaType, newMediaType);
if (renderer != null)
break;
}
if (renderer != null) {
- add(renderer.render("blobContent", new LoadableDetachableModel<MediaRenderInfo>() {
-
- @Override
- protected MediaRenderInfo load() {
- BlobDiffInfo blobDiff = blobDiffModel.getObject();
- return new MediaRenderInfo(blobDiff.getOldPath(), blobDiff.getOldRevision(),
- originalMediaType, blobDiff.getOldContent());
- }
-
- }, new LoadableDetachableModel<MediaRenderInfo>() {
-
- @Override
- protected MediaRenderInfo load() {
- BlobDiffInfo blobDiff = blobDiffModel.getObject();
- return new MediaRenderInfo(blobDiff.getNewPath(), blobDiff.getNewRevision(),
- revisedMediaType, blobDiff.getNewContent());
- }
-
- }));
+ add(renderer.render("blobContent", diffInfo, oldContentModel, newContentModel));
} else {
Component diffPanel = null;
- if (originalMediaType == revisedMediaType) {
+ if (oldMediaType == newMediaType) {
TextConverter textConverter = null;
for (TextConverterProvider provider: GitPlex.getExtensions(TextConverterProvider.class)) {
- textConverter = provider.getTextConverter(originalMediaType);
+ textConverter = provider.getTextConverter(oldMediaType);
if (textConverter != null)
break;
}
if (textConverter != null) {
- GitText originalText = new GitText(textConverter.convert(blobDiff.getOldContent()), true);
- GitText revisedText = new GitText(textConverter.convert(blobDiff.getNewContent()), true);
- TextRenderInfo oldTextRenderInfo = new TextRenderInfo(blobDiff.getOldPath(),
- blobDiff.getOldRevision(), originalText, Charsets.UTF_8);
- TextRenderInfo newTextRenderInfo = new TextRenderInfo(blobDiff.getNewPath(),
- blobDiff.getNewRevision(), revisedText, Charsets.UTF_8);
- diffPanel = new TextDiffPanel("blobContent",
- Model.of(oldTextRenderInfo), Model.of(newTextRenderInfo));
+ GitText originalText = new GitText(textConverter.convert(oldContent),
+ true, Charsets.UTF_8.name());
+ GitText revisedText = new GitText(textConverter.convert(newContent),
+ true, Charsets.UTF_8.name());
+ diffPanel = new TextDiffPanel("blobContent", diffInfo, originalText, revisedText);
}
}
if (diffPanel == null) {
- if (blobDiff.getOldContent().length == 0) {
- Charset newCharset = Charsets.detectFrom(blobDiff.getNewContent());
- if (newCharset != null) {
- TextRenderInfo oldRenderInfo = new TextRenderInfo(blobDiff.getOldPath(),
- blobDiff.getOldRevision(), new GitText(new ArrayList<String>(), true), newCharset);
- TextRenderInfo newRenderInfo = new TextRenderInfo(blobDiff.getNewPath(),
- blobDiff.getNewRevision(), GitText.from(blobDiff.getNewContent(), newCharset), newCharset);
- diffPanel = new TextDiffPanel("blobContent", Model.of(oldRenderInfo), Model.of(newRenderInfo));
+ if (oldContent.length == 0) {
+ if (newContent.length == 0) {
+ Fragment fragment = new Fragment("blobContent", "emptyFileFrag", this);
+ fragment.add(new FileDiffTitle("summary", diffInfo));
+ diffPanel = fragment;
+ } else {
+ GitText newText = GitText.from(newContent);
+ if (newText != null) {
+ GitText oldText = new GitText(new ArrayList<String>(), true, newText.getCharset());
+ diffPanel = new TextDiffPanel("blobContent", diffInfo, oldText, newText);
+ } else {
+ Fragment fragment = new Fragment("blobContent", "binaryFileFrag", this);
+ fragment.add(new FileDiffTitle("summary", diffInfo));
+ diffPanel = fragment;
+ }
}
} else {
- Charset oldCharset = Charsets.detectFrom(blobDiff.getOldContent());
- if (blobDiff.getNewContent().length == 0) {
- if (oldCharset != null) {
- TextRenderInfo oldRenderInfo = new TextRenderInfo(blobDiff.getOldPath(),
- blobDiff.getOldRevision(), GitText.from(blobDiff.getOldContent(), oldCharset), oldCharset);
- TextRenderInfo newRenderInfo = new TextRenderInfo(blobDiff.getNewPath(),
- blobDiff.getNewRevision(), new GitText(new ArrayList<String>(), true), oldCharset);
- diffPanel = new TextDiffPanel("blobContent", Model.of(oldRenderInfo), Model.of(newRenderInfo));
+ if (newContent.length == 0) {
+ GitText oldText = GitText.from(oldContent);
+ if (oldText != null) {
+ GitText newText = new GitText(new ArrayList<String>(), true, oldText.getCharset());
+ diffPanel = new TextDiffPanel("blobContent", diffInfo, oldText, newText);
+ } else {
+ Fragment fragment = new Fragment("blobContent", "binaryFileFrag", this);
+ fragment.add(new FileDiffTitle("summary", diffInfo));
+ diffPanel = fragment;
}
} else {
- Charset newCharset = Charsets.detectFrom(blobDiff.getNewContent());
- if (oldCharset != null && newCharset != null) {
- TextRenderInfo oldRenderInfo = new TextRenderInfo(blobDiff.getOldPath(),
- blobDiff.getOldRevision(), GitText.from(blobDiff.getOldContent(), oldCharset), oldCharset);
- TextRenderInfo newRenderInfo = new TextRenderInfo(blobDiff.getNewPath(),
- blobDiff.getNewRevision(), GitText.from(blobDiff.getNewContent(), oldCharset), oldCharset);
- diffPanel = new TextDiffPanel("blobContent", Model.of(oldRenderInfo), Model.of(newRenderInfo));
+ GitText oldText = GitText.from(oldContent);
+ GitText newText = GitText.from(newContent);
+ if (oldText != null && newText != null) {
+ diffPanel = new TextDiffPanel("blobContent", diffInfo, oldText, newText);
+ } else {
+ Fragment fragment = new Fragment("blobContent", "binaryFileFrag", this);
+ fragment.add(new FileDiffTitle("summary", diffInfo));
+ diffPanel = fragment;
}
}
}
- if (diffPanel == null) {
- diffPanel = new Label("blobContent",
- "<i class='fa fa-info-circle'></i> <em>Binary files</em>").setEscapeModelStrings(false);
- }
}
add(diffPanel);
}
} else {
if (oldBlobType == FileMode.TYPE_SYMLINK) {
- add(new SymbolLink("originalContent", repoModel, blobDiff.getOldRevision(),
- blobDiff.getOldPath(), new String(blobDiff.getOldContent())));
+ add(new SymbolLink("originalContent", repoModel, diffInfo.getOldRevision(),
+ diffInfo.getOldPath(), new String(oldContentModel.getObject())));
} else if (oldBlobType == FileMode.TYPE_GITLINK) {
- add(new GitLink("originalContent", new String(blobDiff.getOldContent())));
+ add(new GitLink("originalContent", new String(oldContentModel.getObject())));
} else if (oldBlobType == FileMode.TYPE_FILE) {
- add(new BlobViewPanel("originalContent", repoModel, new LoadableDetachableModel<BlobRenderInfo>(){
-
- @Override
- protected BlobRenderInfo load() {
- BlobDiffInfo blobDiff = blobDiffModel.getObject();
- return new BlobRenderInfo(blobDiff.getOldPath(), blobDiff.getOldRevision(),
- blobDiff.getOldMode(), blobDiff.getOldContent());
- }
-
- }));
+ BlobRenderInfo renderInfo = new BlobRenderInfo(diffInfo.getOldPath(),
+ diffInfo.getOldRevision(), diffInfo.getOldMode());
+ add(new BlobViewPanel("originalContent", repoModel, renderInfo, oldContentModel));
} else {
add(new WebMarkupContainer("originalContent").setVisible(false));
}
+ add(new Label("originalTitle", diffInfo.getOldPath()));
if (newBlobType == FileMode.TYPE_SYMLINK) {
- add(new SymbolLink("revisedContent", repoModel, blobDiff.getNewRevision(),
- blobDiff.getNewPath(), new String(blobDiff.getNewContent())));
+ add(new SymbolLink("revisedContent", repoModel, diffInfo.getNewRevision(),
+ diffInfo.getNewPath(), new String(newContentModel.getObject())));
} else if (newBlobType == FileMode.TYPE_GITLINK) {
- add(new GitLink("revisedContent", new String(blobDiff.getNewContent())));
+ add(new GitLink("revisedContent", new String(newContentModel.getObject())));
} else if (newBlobType == FileMode.TYPE_FILE) {
- add(new BlobViewPanel("revisedContent", repoModel, new LoadableDetachableModel<BlobRenderInfo>(){
-
- @Override
- protected BlobRenderInfo load() {
- BlobDiffInfo blobDiff = blobDiffModel.getObject();
- return new BlobRenderInfo(blobDiff.getNewPath(), blobDiff.getNewRevision(),
- blobDiff.getNewMode(), blobDiff.getNewContent());
- }
-
- }));
+ BlobRenderInfo renderInfo = new BlobRenderInfo(diffInfo.getNewPath(),
+ diffInfo.getNewRevision(), diffInfo.getNewMode());
+ add(new BlobViewPanel("revisedContent", repoModel, renderInfo, newContentModel));
} else {
add(new WebMarkupContainer("revisedContent").setVisible(false));
}
+ add(new Label("revisedTitle", diffInfo.getNewPath()));
add(new WebMarkupContainer("blobContent").setVisible(false));
}
@@ -247,7 +226,8 @@ public class BlobDiffPanel extends Panel {
protected void onDetach() {
repoModel.detach();
- blobDiffModel.detach();
+ oldContentModel.detach();
+ newContentModel.detach();
super.onDetach();
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/DiffHunk.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/DiffHunk.java
new file mode 100644
index 0000000000..d7014d74a0
--- /dev/null
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/DiffHunk.java
@@ -0,0 +1,44 @@
+package com.pmease.gitplex.web.component.diff;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+import com.pmease.commons.util.diff.DiffChunk;
+import com.pmease.commons.util.diff.DiffLine;
+
+@SuppressWarnings("serial")
+class DiffHunk implements Serializable {
+
+ private HunkHeader header;
+
+ private List<HunkLine> lines;
+
+ public DiffHunk(HunkHeader hunkHeader, List<HunkLine> lines) {
+ this.header = hunkHeader;
+ this.lines = lines;
+ }
+
+ public HunkHeader getHeader() {
+ return header;
+ }
+
+ public List<HunkLine> getLines() {
+ return lines;
+ }
+
+ public static DiffHunk from(DiffChunk chunk) {
+ List<HunkLine> hunkLines = new ArrayList<>();
+ int oldLineNo = chunk.getStart1(), newLineNo = chunk.getStart2();
+ for (DiffLine diffLine: chunk.getDiffLines()) {
+ if (diffLine.getAction() == DiffLine.Action.ADD)
+ hunkLines.add(new HunkLine(0, newLineNo++, diffLine));
+ else if (diffLine.getAction() == DiffLine.Action.DELETE)
+ hunkLines.add(new HunkLine(oldLineNo++, 0, diffLine));
+ else
+ hunkLines.add(new HunkLine(oldLineNo++, newLineNo++, diffLine));
+ }
+ return new DiffHunk(new HunkHeader(chunk.getStart1(), oldLineNo, chunk.getStart2(), newLineNo), hunkLines);
+ }
+
+}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/FileDiffTitle.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/FileDiffTitle.html
new file mode 100644
index 0000000000..2b19ee0bc6
--- /dev/null
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/FileDiffTitle.html
@@ -0,0 +1,8 @@
+<wicket:panel>
+ <wicket:enclosure child="renamedTitle">
+ <span wicket:id="renamedTitle"></span>
+ <i class="fa fa-arrow-slim-right"></i>
+ </wicket:enclosure>
+ <span wicket:id="title"></span>
+ <span wicket:id="alerts"><i class="fa fa-warning-circle"></i></span>
+</wicket:panel>
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/FileDiffTitle.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/FileDiffTitle.java
new file mode 100644
index 0000000000..ad178e2ee7
--- /dev/null
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/FileDiffTitle.java
@@ -0,0 +1,78 @@
+package com.pmease.gitplex.web.component.diff;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.wicket.behavior.AttributeAppender;
+import org.apache.wicket.markup.html.WebMarkupContainer;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.panel.Panel;
+import org.apache.wicket.model.Model;
+import org.eclipse.jgit.lib.FileMode;
+
+import com.google.common.base.Preconditions;
+import com.pmease.commons.wicket.behavior.TooltipBehavior;
+
+import de.agilecoders.wicket.core.markup.html.bootstrap.components.TooltipConfig;
+import de.agilecoders.wicket.core.markup.html.bootstrap.components.TooltipConfig.Placement;
+
+@SuppressWarnings("serial")
+public class FileDiffTitle extends Panel {
+
+ private final BlobDiffInfo diffInfo;
+
+ private final List<String> alerts;
+
+ public FileDiffTitle(String id, BlobDiffInfo diffInfo, List<String> alerts) {
+ super(id);
+
+ int oldBlobType = diffInfo.getOldMode() & FileMode.TYPE_MASK;
+ int newBlobType = diffInfo.getNewMode() & FileMode.TYPE_MASK;
+
+ Preconditions.checkArgument(oldBlobType == FileMode.TYPE_FILE && newBlobType == FileMode.TYPE_FILE);
+
+ this.diffInfo = diffInfo;
+
+ this.alerts = new ArrayList<>();
+ if (diffInfo.getOldMode() != diffInfo.getNewMode()) {
+ this.alerts.add("File mode is changed from " + Integer.toString(diffInfo.getOldMode(), 8)
+ + " to " + Integer.toString(diffInfo.getNewMode(), 8));
+ }
+ if (alerts != null)
+ this.alerts.addAll(alerts);
+ }
+
+ public FileDiffTitle(String id, BlobDiffInfo diffInfo) {
+ this(id, diffInfo, null);
+ }
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ add(new Label("renamedTitle", diffInfo.getOldPath())
+ .setVisible(!diffInfo.getOldPath().equals(diffInfo.getNewPath())));
+ add(new Label("title", diffInfo.getNewPath()));
+
+ if (alerts.size() == 0) {
+ add(new WebMarkupContainer("alerts").setVisible(false));
+ } else if (alerts.size() == 1) {
+ WebMarkupContainer alertsTrigger = new WebMarkupContainer("alerts");
+ TooltipConfig config = new TooltipConfig().withPlacement(Placement.right);
+ alertsTrigger.add(new TooltipBehavior(Model.of(alerts.get(0)), config));
+ add(alertsTrigger);
+ } else {
+ WebMarkupContainer alertsTrigger = new WebMarkupContainer("alerts");
+ alertsTrigger.add(AttributeAppender.append("data-html", "true"));
+ StringBuffer html = new StringBuffer();
+ html.append("<ul class='diff-alerts'>");
+ for (String alert: alerts)
+ html.append("<li>").append(alert).append("</li>");
+ html.append("</ul>");
+ TooltipConfig config = new TooltipConfig().withPlacement(Placement.right);
+ alertsTrigger.add(new TooltipBehavior(Model.of(html.toString()), config));
+ add(alertsTrigger);
+ }
+ }
+
+}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/HunkHeader.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/HunkHeader.java
new file mode 100644
index 0000000000..00574b76a5
--- /dev/null
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/HunkHeader.java
@@ -0,0 +1,66 @@
+package com.pmease.gitplex.web.component.diff;
+
+import java.io.Serializable;
+
+@SuppressWarnings("serial")
+class HunkHeader implements Serializable {
+
+ private int oldStart, oldEnd, newStart, newEnd;
+
+ public HunkHeader(int oldStart, int oldEnd, int newStart, int newEnd) {
+ this.oldStart = oldStart;
+ this.oldEnd = oldEnd;
+ this.newStart = newStart;
+ this.newEnd = newEnd;
+ }
+
+ public int getOldStart() {
+ return oldStart;
+ }
+
+ public int getOldEnd() {
+ return oldEnd;
+ }
+
+ public int getNewStart() {
+ return newStart;
+ }
+
+ public int getNewEnd() {
+ return newEnd;
+ }
+
+ public void setOldStart(int oldStart) {
+ this.oldStart = oldStart;
+ }
+
+ public void setOldEnd(int oldEnd) {
+ this.oldEnd = oldEnd;
+ }
+
+ public void setNewStart(int newStart) {
+ this.newStart = newStart;
+ }
+
+ public void setNewEnd(int newEnd) {
+ this.newEnd = newEnd;
+ }
+
+ @Override
+ public String toString() {
+ int oldStart = this.oldStart;
+ int newStart = this.newStart;
+ int oldCount = oldEnd - oldStart;
+ int newCount = newEnd - newStart;
+
+ if (oldCount == 0)
+ oldStart = 0;
+ else
+ oldStart++;
+ if (newCount == 0)
+ newStart = 0;
+ else
+ newStart++;
+ return "@@ -" + oldStart + "," + oldCount + " +" + newStart + "," + newCount + " @@";
+ }
+}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/HunkLine.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/HunkLine.java
new file mode 100644
index 0000000000..75b00bc6cd
--- /dev/null
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/HunkLine.java
@@ -0,0 +1,46 @@
+package com.pmease.gitplex.web.component.diff;
+
+import java.io.Serializable;
+
+import com.pmease.commons.util.diff.DiffLine;
+
+@SuppressWarnings("serial")
+class HunkLine implements Serializable {
+
+ private int originalLineNo;
+
+ private int revisedLineNo;
+
+ private DiffLine diffLine;
+
+ public HunkLine(int originalLineNo, int revisedLineNo, DiffLine diffLine) {
+ this.originalLineNo = originalLineNo;
+ this.revisedLineNo = revisedLineNo;
+ this.diffLine = diffLine;
+ }
+
+ public int getOriginalLineNo() {
+ return originalLineNo;
+ }
+
+ public int getRevisedLineNo() {
+ return revisedLineNo;
+ }
+
+ public DiffLine getDiffLine() {
+ return diffLine;
+ }
+
+ public void setOriginalLineNo(int originalLineNo) {
+ this.originalLineNo = originalLineNo;
+ }
+
+ public void setRevisedLineNo(int revisedLineNo) {
+ this.revisedLineNo = revisedLineNo;
+ }
+
+ public void setDiffLine(DiffLine diffLine) {
+ this.diffLine = diffLine;
+ }
+
+}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.html
index 53bbedf2c4..12776bc4f9 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.html
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.html
@@ -1,3 +1,38 @@
<wicket:panel>
- text diffs here
+ <div class="text-diff panel panel-default">
+ <div class="panel-heading clearfix">
+ <div wicket:id="title" class="pull-left panel-title"></div>
+ <div class="pull-right">
+ <span wicket:id="identical"><i class="fa fa-info-circle fa-lg"></i> <em>content is identical</em></span>
+ <span wicket:id="viewFull" class="fa fa-file-txt fa-lg action" title="View full file"></span>
+ <span wicket:id="diffOptionsTrigger" class="fa fa-gear fa-lg action" title="Diff options"></span>
+ <div wicket:id="diffOptions"></div>
+ </div>
+ </div>
+ <table class="table-diff">
+ <wicket:container wicket:id="hunks">
+ <tr wicket:id="hunkHead" class="hunk-head hunk-row">
+ <td colspan="2" class="info">
+ <a wicket:id="expand"><i class="fa fa-expand"></i></a>
+ </td>
+ <td class="content"><span wicket:id="content"></span></td>
+ </tr>
+ <tr wicket:id="hunkLines" class="hunk-line hunk-row">
+ <td class="original info">
+ <span wicket:id="originalLineNo"></span>
+ </td>
+ <td class="revised info">
+ <span wicket:id="revisedLineNo"></span>
+ </td>
+ <td class="content">
+ <pre><wicket:container wicket:id="partials"><span wicket:id="partial"></span></wicket:container></pre>
+ </td>
+ </tr>
+ </wicket:container>
+ <tr wicket:id="hunkFoot" class="hunk-head hunk-row">
+ <td colspan="2" class="info"><a wicket:id="expand"><i class="fa fa-expand"></i></a></td>
+ <td class="content">&nbsp;</td>
+ </tr>
+ </table>
+ </div>
</wicket:panel>
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.java
index e91550da4d..921d485984 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.java
@@ -1,34 +1,541 @@
package com.pmease.gitplex.web.component.diff;
+import static de.agilecoders.wicket.jquery.JQuery.$;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.markup.html.AjaxLink;
+import org.apache.wicket.behavior.AttributeAppender;
+import org.apache.wicket.markup.html.WebMarkupContainer;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.list.ListItem;
+import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.markup.html.panel.Panel;
+import org.apache.wicket.markup.repeater.RepeatingView;
+import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.Model;
+
+import com.pmease.commons.git.GitText;
+import com.pmease.commons.util.diff.DiffChunk;
+import com.pmease.commons.util.diff.DiffLine;
+import com.pmease.commons.util.diff.DiffUtils;
+import com.pmease.commons.util.diff.Partial;
+import com.pmease.commons.util.diff.WordSplitter;
+import com.pmease.commons.wicket.behavior.TooltipBehavior;
+import com.pmease.commons.wicket.behavior.menu.CheckMenuItem;
+import com.pmease.commons.wicket.behavior.menu.MenuBehavior;
+import com.pmease.commons.wicket.behavior.menu.MenuItem;
+import com.pmease.commons.wicket.behavior.menu.MenuPanel;
+import com.pmease.commons.wicket.jquery.FunctionWithParams;
-import com.pmease.gitplex.web.component.view.TextRenderInfo;
+import de.agilecoders.wicket.jquery.JQuery;
@SuppressWarnings("serial")
public class TextDiffPanel extends Panel {
- private final IModel<TextRenderInfo> originalTextModel;
+ private enum DiffOption {IGNORE_NOTHING, IGNORE_EOL, IGNORE_EOL_SPACES, IGNORE_CHANGE_SPACES};
+
+ private static final int DEFAULT_CONTEXT_LINES = 5;
+
+ private static final String HUNK_BODY_ID = "hunkLines";
+
+ private static final String HUNK_HEAD_ID = "hunkHead";
+
+ private final BlobDiffInfo diffInfo;
+
+ private final GitText oldText;
+
+ private final GitText newText;
+
+ private GitText effectiveOldText;
+
+ private GitText effectiveNewText;
+
+ private DiffOption diffOption = DiffOption.IGNORE_NOTHING;
+
+ private List<DiffLine> diffs;
+
+ private List<DiffHunk> hunks;
+
+ private int contextLines;
- private final IModel<TextRenderInfo> revisedTextModel;
+ private ListView<DiffHunk> hunksContainer;
- public TextDiffPanel(String id, IModel<TextRenderInfo> originalTextModel, IModel<TextRenderInfo> revisedTextModel) {
+ private AjaxLink<Void> viewFullLink;
+
+ public TextDiffPanel(String id, BlobDiffInfo diffInfo, GitText oldText, GitText newText) {
super(id);
- this.originalTextModel = originalTextModel;
- this.revisedTextModel = revisedTextModel;
+ this.diffInfo = diffInfo;
+ this.oldText = oldText;
+ this.newText = newText;
+
+ contextLines = DEFAULT_CONTEXT_LINES;
+
+ onDiffOptionChanged();
}
+
+ private void onDiffOptionChanged() {
+ if (diffOption == DiffOption.IGNORE_EOL) {
+ effectiveOldText = oldText.ignoreEOL();
+ effectiveNewText = newText.ignoreEOL();
+ } else if (diffOption == DiffOption.IGNORE_EOL_SPACES) {
+ effectiveOldText = oldText.ignoreEOLSpaces();
+ effectiveNewText = newText.ignoreEOLSpaces();
+ } else if (diffOption == DiffOption.IGNORE_CHANGE_SPACES) {
+ effectiveOldText = oldText.ignoreChangeSpaces();
+ effectiveNewText = newText.ignoreChangeSpaces();
+ } else {
+ effectiveOldText = oldText;
+ effectiveNewText = newText;
+ }
+
+ diffs = DiffUtils.diff(effectiveOldText.getLines(), effectiveNewText.getLines(), new WordSplitter());
+ onContextLineChanged();
+ }
+
+ private void onContextLineChanged() {
+ hunks = new ArrayList<>();
+ if (contextLines != 0) {
+ for (DiffChunk chunk: DiffUtils.chunksOf(diffs, contextLines))
+ hunks.add(DiffHunk.from(chunk));
+ } else {
+ hunks.add(DiffHunk.from(new DiffChunk(0, 0, diffs)));
+ }
+ }
+
+ private boolean isIdentical() {
+ for (DiffLine diffLine: diffs) {
+ if (diffLine.getAction() != DiffLine.Action.EQUAL)
+ return false;
+ }
+ return true;
+ }
+
@Override
protected void onInitialize() {
super.onInitialize();
+
+ setOutputMarkupId(true);
+
+ List<String> alerts = new ArrayList<>();
+ if (!oldText.getCharset().equals(newText.getCharset()))
+ alerts.add("Charset is changed from " + oldText.getCharset() + " to " + newText.getCharset());
+ if (!oldText.isHasEolAtEof())
+ alerts.add("Original text does not have EOL character at EOF");
+ if (!newText.isHasEolAtEof())
+ alerts.add("Revised text does not have EOL character at EOF");
+
+ add(new FileDiffTitle("title", diffInfo, alerts));
+
+ add(new WebMarkupContainer("identical") {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+ setVisible(isIdentical());
+ }
+
+ });
+
+ add(viewFullLink = new AjaxLink<Void>("viewFull") {
+
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ contextLines = 0;
+ onContextLineChanged();
+ target.add(TextDiffPanel.this);
+ }
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+
+ int lines = 0;
+ for (DiffHunk hunk: hunks)
+ lines += hunk.getLines().size();
+
+ setVisible(lines < diffs.size());
+ }
+
+ });
+ viewFullLink.setOutputMarkupId(true);
+
+ MenuPanel diffOptionMenuPanel = new MenuPanel("diffOptions") {
+
+ @Override
+ protected List<MenuItem> getMenuItems() {
+ List<MenuItem> menuItems = new ArrayList<>();
+
+ menuItems.add(new CheckMenuItem() {
+
+ @Override
+ protected void onUpdate(AjaxRequestTarget target) {
+ onDiffOptionChanged();
+ close(target);
+ target.add(TextDiffPanel.this);
+ }
+
+ @Override
+ protected String getLabel() {
+ return "Ignore end of line differences";
+ }
+
+ @Override
+ protected IModel<Boolean> getCheckModel() {
+ return new IModel<Boolean>() {
+
+ @Override
+ public void detach() {
+ }
+
+ @Override
+ public Boolean getObject() {
+ return diffOption == DiffOption.IGNORE_EOL;
+ }
+
+ @Override
+ public void setObject(Boolean object) {
+ if (object)
+ diffOption = DiffOption.IGNORE_EOL;
+ else
+ diffOption = DiffOption.IGNORE_NOTHING;
+ }
+
+ };
+ }
+ });
+
+ menuItems.add(new CheckMenuItem() {
+
+ @Override
+ protected void onUpdate(AjaxRequestTarget target) {
+ onDiffOptionChanged();
+ close(target);
+ target.add(TextDiffPanel.this);
+ }
+
+ @Override
+ protected String getLabel() {
+ return "Ignore white spaces at line end";
+ }
+
+ @Override
+ protected IModel<Boolean> getCheckModel() {
+ return new IModel<Boolean>() {
+
+ @Override
+ public void detach() {
+ }
+
+ @Override
+ public Boolean getObject() {
+ return diffOption == DiffOption.IGNORE_EOL_SPACES;
+ }
+
+ @Override
+ public void setObject(Boolean object) {
+ if (object)
+ diffOption = DiffOption.IGNORE_EOL_SPACES;
+ else
+ diffOption = DiffOption.IGNORE_NOTHING;
+ }
+
+ };
+ }
+ });
+
+ menuItems.add(new CheckMenuItem() {
+
+ @Override
+ protected void onUpdate(AjaxRequestTarget target) {
+ onDiffOptionChanged();
+ close(target);
+ target.add(TextDiffPanel.this);
+ }
+
+ @Override
+ protected String getLabel() {
+ return "Ignore white space changes";
+ }
+
+ @Override
+ protected IModel<Boolean> getCheckModel() {
+ return new IModel<Boolean>() {
+
+ @Override
+ public void detach() {
+ }
+
+ @Override
+ public Boolean getObject() {
+ return diffOption == DiffOption.IGNORE_CHANGE_SPACES;
+ }
+
+ @Override
+ public void setObject(Boolean object) {
+ if (object)
+ diffOption = DiffOption.IGNORE_CHANGE_SPACES;
+ else
+ diffOption = DiffOption.IGNORE_NOTHING;
+ }
+
+ };
+ }
+ });
+
+ return menuItems;
+ }
+
+ };
+
+ add(diffOptionMenuPanel);
+
+ add(new WebMarkupContainer("diffOptionsTrigger").add(new MenuBehavior(diffOptionMenuPanel)));
+
+ hunksContainer = new ListView<DiffHunk>("hunks", new AbstractReadOnlyModel<List<DiffHunk>>() {
+
+ @Override
+ public List<DiffHunk> getObject() {
+ return hunks;
+ }
+
+ }) {
+
+ @Override
+ protected void populateItem(final ListItem<DiffHunk> item) {
+ DiffHunk hunk = item.getModelObject();
+
+ RepeatingView hunkBody = new RepeatingView(HUNK_BODY_ID);
+ item.add(newHeadComponent(HUNK_HEAD_ID, item.getIndex()));
+ for (HunkLine line: hunk.getLines())
+ hunkBody.add(newLineComponent(hunkBody.newChildId(), line));
+ item.add(hunkBody);
+ }
+
+ };
+ add(hunksContainer);
+
+ final WebMarkupContainer hunkFoot = new WebMarkupContainer("hunkFoot") {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+
+ if (hunks.isEmpty()) {
+ setVisible(false);
+ } else {
+ int lines = 0;
+ for (DiffLine diffLine: diffs) {
+ if (diffLine.getAction() != DiffLine.Action.DELETE)
+ lines++;
+ }
+ DiffHunk hunk = hunks.get(hunks.size()-1);
+ setVisible(hunk.getHeader().getNewEnd() < lines);
+ }
+ }
+
+ };
+ hunkFoot.setOutputMarkupId(true);
+ add(hunkFoot);
+ hunkFoot.add(new AjaxLink<Void>("expand") {
+
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ expandBelow(target, hunks.size()-1, diffs.size());
+ target.add(findPreviousVisibleHunkHead(hunks.size()));
+ target.add(hunkFoot);
+ target.add(viewFullLink);
+ }
+
+ }.add(new TooltipBehavior(Model.of("Show more lines"))));
}
+
+ private WebMarkupContainer newLineComponent(String id, HunkLine line) {
+ WebMarkupContainer lineContainer = new WebMarkupContainer(id);
+ if (line.getDiffLine().getAction() == DiffLine.Action.ADD) {
+ lineContainer.add(AttributeAppender.append("class", " revised"));
+ lineContainer.add(new Label("originalLineNo"));
+ lineContainer.add(new Label("revisedLineNo", "+ " + (line.getRevisedLineNo()+1)));
+ } else if (line.getDiffLine().getAction() == DiffLine.Action.DELETE) {
+ lineContainer.add(AttributeAppender.append("class", " original"));
+ lineContainer.add(new Label("originalLineNo", "- " + (line.getOriginalLineNo()+1)));
+ lineContainer.add(new Label("revisedLineNo"));
+ } else {
+ lineContainer.add(AttributeAppender.append("class", " equal"));
+ lineContainer.add(new Label("originalLineNo", " " + (line.getOriginalLineNo()+1)));
+ lineContainer.add(new Label("revisedLineNo", " " + (line.getRevisedLineNo()+1)));
+ }
+ lineContainer.add(new ListView<Partial>("partials", line.getDiffLine().getPartials()) {
- @Override
- protected void onDetach() {
- originalTextModel.detach();
- revisedTextModel.detach();
- super.onDetach();
+ @Override
+ protected void populateItem(ListItem<Partial> item) {
+ Partial partial = item.getModelObject();
+ Label label;
+ if (partial.getContent().equals("\r"))
+ label = new Label("partial", " ");
+ else
+ label = new Label("partial", partial.getContent());
+ if (partial.isEmphasized())
+ label.add(AttributeAppender.append("class", "emphasize"));
+ item.add(label);
+ }
+
+ });
+ lineContainer.setOutputMarkupId(true);
+ return lineContainer;
}
+
+ private WebMarkupContainer newHeadComponent(String id, final int index) {
+ final DiffHunk hunk = hunks.get(index);
+ final WebMarkupContainer headComponent = new WebMarkupContainer(id) {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+ setVisible(index == 0 || hunk.getHeader().getNewStart() > hunks.get(index-1).getHeader().getNewEnd());
+ }
+
+ };
+ headComponent.add(new AjaxLink<Void>("expand") {
+
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ if (index == 0) {
+ expandAbove(target, index, 0);
+ target.add(headComponent);
+ } else {
+ int diffPos = locateDiffPos(hunk.getHeader().getNewStart(), DiffLine.Action.DELETE);
+ expandBelow(target, index-1, diffPos);
+
+ diffPos = locateDiffPos(hunks.get(index-1).getHeader().getNewEnd(), DiffLine.Action.DELETE);
+ expandAbove(target, index, diffPos);
+
+ target.add(headComponent);
+ target.add(findPreviousVisibleHunkHead(index));
+ }
+ target.add(viewFullLink);
+ }
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+
+ if (index == 0) {
+ setVisible(hunk.getHeader().getOldStart() != 0 && hunk.getHeader().getNewStart() != 0);
+ } else {
+ DiffHunk previousHunk = hunks.get(index-1);
+ setVisible(previousHunk.getHeader().getNewEnd() < hunk.getHeader().getNewStart());
+ }
+ }
+
+ }.add(new TooltipBehavior(Model.of("Show more lines"))));
+
+ headComponent.add(new Label("content", new AbstractReadOnlyModel<String>() {
+ @Override
+ public String getObject() {
+ int oldStart = hunk.getHeader().getOldStart();
+ int newStart = hunk.getHeader().getNewStart();
+ int oldEnd = hunk.getHeader().getOldEnd();
+ int newEnd = hunk.getHeader().getNewEnd();
+ for (int i=index+1; i<hunks.size(); i++) {
+ HunkHeader nextHunkHeader = hunks.get(i).getHeader();
+ if (newEnd == nextHunkHeader.getNewStart()) {
+ newEnd = nextHunkHeader.getNewEnd();
+ oldEnd = nextHunkHeader.getOldEnd();
+ } else {
+ break;
+ }
+ }
+ return new HunkHeader(oldStart, oldEnd, newStart, newEnd).toString();
+ }
+
+ }));
+
+ headComponent.setOutputMarkupId(true);
+
+ return headComponent;
+ }
+
+ private int locateDiffPos(int lineNo, DiffLine.Action excludeAction) {
+ int index = 0;
+ for (int i=0; i<diffs.size(); i++) {
+ if (index < lineNo) {
+ if (diffs.get(i).getAction() != excludeAction)
+ index++;
+ } else {
+ return i;
+ }
+ }
+ throw new IllegalStateException();
+ }
+
+ private void expandBelow(AjaxRequestTarget target, int hunkIndex, int diffLimit) {
+ DiffHunk hunk = hunks.get(hunkIndex);
+ RepeatingView hunkBody = (RepeatingView) hunksContainer.get(hunkIndex).get(HUNK_BODY_ID);
+
+ HunkHeader header = hunk.getHeader();
+
+ int diffPos = locateDiffPos(header.getNewEnd(), DiffLine.Action.DELETE);
+ for (int i = diffPos; i<diffs.size(); i++) {
+ if (i-diffPos < DEFAULT_CONTEXT_LINES && i<diffLimit) {
+ HunkLine line = new HunkLine(header.getOldEnd(), header.getNewEnd(), diffs.get(i));
+ hunk.getLines().add(line);
+ header.setNewEnd(header.getNewEnd()+1);
+ header.setOldEnd(header.getOldEnd()+1);
+
+ WebMarkupContainer lineComponent = newLineComponent(hunkBody.newChildId(), line);
+ JQuery script = $(String.format("<tr id=\"%s\"></tr>", lineComponent.getMarkupId()));
+ Component lastComponent = hunkBody.get(hunkBody.size()-1);
+ script.chain(new FunctionWithParams("insertAfter", "'#" + lastComponent.getMarkupId() + "'"));
+ target.prependJavaScript(script.get());
+ hunkBody.add(lineComponent);
+ target.add(lineComponent);
+ } else {
+ break;
+ }
+ }
+ }
+
+ private Component findPreviousVisibleHunkHead(int index) {
+ for (int i=index-1; i>=0; i--) {
+ Component hunkHead = hunksContainer.get(i).get(HUNK_HEAD_ID);
+ hunkHead.configure();
+ if (hunkHead.isVisible())
+ return hunkHead;
+ }
+ throw new IllegalStateException();
+ }
+
+ private void expandAbove(AjaxRequestTarget target, int hunkIndex, int diffLimit) {
+ DiffHunk hunk = hunks.get(hunkIndex);
+ RepeatingView hunkBody = (RepeatingView) hunksContainer.get(hunkIndex).get(HUNK_BODY_ID);
+ HunkHeader header = hunk.getHeader();
+
+ int diffPos = locateDiffPos(header.getNewStart(), DiffLine.Action.DELETE);
+ for (int i=diffPos-1; i>=diffLimit; i--) {
+ if (diffPos-i <= DEFAULT_CONTEXT_LINES) {
+ header.setOldStart(header.getOldStart()-1);
+ header.setNewStart(header.getNewStart()-1);
+ HunkLine line = new HunkLine(header.getOldStart(), header.getNewStart(), diffs.get(i));
+ hunk.getLines().add(0, line);
+ WebMarkupContainer lineComponent = newLineComponent(hunkBody.newChildId(), line);
+ JQuery script = $(String.format("<tr id=\"%s\"></tr>", lineComponent.getMarkupId()));
+ script.chain(new FunctionWithParams("insertBefore", "'#" + hunkBody.get(0).getMarkupId() + "'"));
+ target.prependJavaScript(script.get());
+ hunkBody.add(lineComponent);
+ for (int j=hunkBody.size()-1;j>0;j--)
+ hunkBody.swap(j, j-1);
+ target.add(lineComponent);
+ } else {
+ break;
+ }
+ }
+ }
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/view/BlobRenderInfo.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/view/BlobRenderInfo.java
index 8234c18275..19f9158cae 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/view/BlobRenderInfo.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/view/BlobRenderInfo.java
@@ -1,28 +1,22 @@
package com.pmease.gitplex.web.component.view;
-import org.eclipse.jgit.lib.FileMode;
+import java.io.Serializable;
-import com.google.common.base.Preconditions;
-import com.pmease.commons.git.Git;
-import com.pmease.commons.git.TreeNode;
+@SuppressWarnings("serial")
+public class BlobRenderInfo implements Serializable {
-public class BlobRenderInfo {
-
private final String path;
private final String revision;
private final int mode;
-
- private final byte[] content;
-
- public BlobRenderInfo(String path, String revision, int mode, byte[] content) {
+
+ public BlobRenderInfo(String path, String revision, int mode) {
this.path = path;
this.revision = revision;
this.mode = mode;
- this.content = content;
}
-
+
public String getPath() {
return path;
}
@@ -34,15 +28,5 @@ public class BlobRenderInfo {
public int getMode() {
return mode;
}
-
- public byte[] getContent() {
- return content;
- }
- public static BlobRenderInfo from(Git git, TreeNode node, String revision) {
- Preconditions.checkArgument(node.getMode() != FileMode.TYPE_TREE);
-
- byte[] content = git.read(revision, node.getPath(), node.getMode());
- return new BlobRenderInfo(node.getPath(), revision, node.getMode(), content);
- }
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/view/BlobViewPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/view/BlobViewPanel.java
index 87c2b50754..b1b639c8c5 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/view/BlobViewPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/view/BlobViewPanel.java
@@ -1,22 +1,17 @@
package com.pmease.gitplex.web.component.view;
-import java.nio.charset.Charset;
-
import org.apache.tika.mime.MediaType;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
-import org.apache.wicket.model.LoadableDetachableModel;
-import org.apache.wicket.model.Model;
import org.eclipse.jgit.lib.FileMode;
-import com.pmease.commons.util.Charsets;
+import com.pmease.commons.git.GitText;
import com.pmease.commons.util.MediaTypes;
import com.pmease.gitplex.core.GitPlex;
import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.web.component.gitlink.GitLink;
import com.pmease.gitplex.web.component.symbollink.SymbolLink;
-import com.pmease.gitplex.web.extensionpoint.MediaRenderInfo;
import com.pmease.gitplex.web.extensionpoint.MediaRenderer;
import com.pmease.gitplex.web.extensionpoint.MediaRendererProvider;
@@ -25,29 +20,33 @@ public class BlobViewPanel extends Panel {
private final IModel<Repository> repoModel;
- private final IModel<BlobRenderInfo> blobModel;
+ private final BlobRenderInfo blobInfo;
+
+ private final IModel<byte[]> blobContentModel;
- public BlobViewPanel(String id, IModel<Repository> repoModel, IModel<BlobRenderInfo> blobModel) {
+ public BlobViewPanel(String id, IModel<Repository> repoModel, BlobRenderInfo blobInfo,
+ IModel<byte[]> blobContentModel) {
super(id);
this.repoModel = repoModel;
- this.blobModel = blobModel;
+ this.blobInfo = blobInfo;
+ this.blobContentModel = blobContentModel;
}
@Override
protected void onInitialize() {
super.onInitialize();
- BlobRenderInfo blob = blobModel.getObject();
- if (blob.getMode() == FileMode.TYPE_GITLINK) {
- add(new GitLink("blob", new String(blob.getContent())));
- } else if (blob.getMode() == FileMode.TYPE_SYMLINK) {
- add(new SymbolLink("blob", repoModel, blob.getRevision(),
- blob.getPath(), new String(blob.getContent())));
- } else if (blob.getContent().length == 0) {
+ byte[] content = blobContentModel.getObject();
+ if (blobInfo.getMode() == FileMode.TYPE_GITLINK) {
+ add(new GitLink("blob", new String(content)));
+ } else if (blobInfo.getMode() == FileMode.TYPE_SYMLINK) {
+ add(new SymbolLink("blob", repoModel, blobInfo.getRevision(),
+ blobInfo.getPath(), new String(content)));
+ } else if (blobContentModel.getObject().length == 0) {
add(new Label("blob", "<i class='fa fa-info-circle'></i> <em>File is empty</em>").setEscapeModelStrings(false));
} else {
- final MediaType mediaType = MediaTypes.detectFrom(blob.getContent(), blob.getPath());
+ final MediaType mediaType = MediaTypes.detectFrom(content, blobInfo.getPath());
MediaRenderer renderer = null;
for (MediaRendererProvider provider: GitPlex.getExtensions(MediaRendererProvider.class)) {
renderer = provider.getMediaRenderer(mediaType);
@@ -55,18 +54,11 @@ public class BlobViewPanel extends Panel {
break;
}
if (renderer != null) {
- add(renderer.render("blob", new LoadableDetachableModel<MediaRenderInfo>() {
-
- @Override
- protected MediaRenderInfo load() {
- return MediaRenderInfo.from(blobModel.getObject(), mediaType);
- }
-
- }));
+ add(renderer.render("blob", blobInfo, blobContentModel));
} else {
- Charset charset = Charsets.detectFrom(blob.getContent());
- if (charset != null) {
- add(new TextViewPanel("blob", Model.of(TextRenderInfo.from(blobModel.getObject(), charset))));
+ GitText text = GitText.from(content);
+ if (text != null) {
+ add(new TextViewPanel("blob", blobInfo, text));
} else {
add(new Label("blob",
"<i class='fa fa-info-circle'></i> <em>Binary file</em>").setEscapeModelStrings(false));
@@ -77,7 +69,8 @@ public class BlobViewPanel extends Panel {
@Override
protected void onDetach() {
- blobModel.detach();
+ repoModel.detach();
+ blobContentModel.detach();
super.onDetach();
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/view/TextRenderInfo.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/view/TextRenderInfo.java
deleted file mode 100644
index 6639e36f3b..0000000000
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/view/TextRenderInfo.java
+++ /dev/null
@@ -1,46 +0,0 @@
-package com.pmease.gitplex.web.component.view;
-
-import java.io.Serializable;
-import java.nio.charset.Charset;
-
-import com.pmease.commons.git.GitText;
-
-@SuppressWarnings("serial")
-public class TextRenderInfo implements Serializable {
-
- private final String path;
-
- private final String revision;
-
- private final GitText text;
-
- private final Charset charset;
-
- public TextRenderInfo(String path, String revision, GitText text, Charset charset) {
- this.path = path;
- this.revision = revision;
- this.text = text;
- this.charset = charset;
- }
-
- public String getPath() {
- return path;
- }
-
- public String getRevision() {
- return revision;
- }
-
- public GitText getText() {
- return text;
- }
-
- public Charset getCharset() {
- return charset;
- }
-
- public static TextRenderInfo from(BlobRenderInfo blob, Charset charset) {
- return new TextRenderInfo(blob.getPath(), blob.getRevision(),
- GitText.from(blob.getContent(), charset), charset);
- }
-}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/view/TextViewPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/view/TextViewPanel.java
index 5c99a32c9c..117b70eec5 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/view/TextViewPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/view/TextViewPanel.java
@@ -1,17 +1,23 @@
package com.pmease.gitplex.web.component.view;
import org.apache.wicket.markup.html.panel.Panel;
-import org.apache.wicket.model.IModel;
+
+import com.pmease.commons.git.GitText;
@SuppressWarnings("serial")
public class TextViewPanel extends Panel {
- private final IModel<TextRenderInfo> textModel;
+ @SuppressWarnings("unused")
+ private final BlobRenderInfo blobInfo;
+
+ @SuppressWarnings("unused")
+ private final GitText blobText;
- public TextViewPanel(String id, IModel<TextRenderInfo> textModel) {
+ public TextViewPanel(String id, BlobRenderInfo blobInfo, GitText blobText) {
super(id);
- this.textModel = textModel;
+ this.blobInfo = blobInfo;
+ this.blobText = blobText;
}
@Override
@@ -19,10 +25,4 @@ public class TextViewPanel extends Panel {
super.onInitialize();
}
- @Override
- protected void onDetach() {
- textModel.detach();
- super.onDetach();
- }
-
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/extensionpoint/DiffRenderer.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/extensionpoint/DiffRenderer.java
index 28ed00f203..9a275825da 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/extensionpoint/DiffRenderer.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/extensionpoint/DiffRenderer.java
@@ -3,6 +3,9 @@ package com.pmease.gitplex.web.extensionpoint;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
+import com.pmease.gitplex.web.component.diff.BlobDiffInfo;
+
public interface DiffRenderer {
- Panel render(String panelId, IModel<MediaRenderInfo> originalMediaModel, IModel<MediaRenderInfo> revisedMediaModel);
+ Panel render(String panelId, BlobDiffInfo diffInfo,
+ IModel<byte[]> originalBlobContentModel, IModel<byte[]> revisedBlobContentModel);
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/extensionpoint/MediaRenderInfo.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/extensionpoint/MediaRenderInfo.java
deleted file mode 100644
index 59aeef403b..0000000000
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/extensionpoint/MediaRenderInfo.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package com.pmease.gitplex.web.extensionpoint;
-
-import org.apache.tika.mime.MediaType;
-
-import com.pmease.gitplex.web.component.view.BlobRenderInfo;
-
-public class MediaRenderInfo {
-
- private final String path;
-
- private final String revision;
-
- private final byte[] content;
-
- private final MediaType mediaType;
-
- public MediaRenderInfo(String path, String revision, MediaType mediaType, byte[] content) {
- this.path = path;
- this.revision = revision;
- this.mediaType = mediaType;
- this.content = content;
- }
-
- public String getPath() {
- return path;
- }
-
- public String getRevision() {
- return revision;
- }
-
- public MediaType getMediaType() {
- return mediaType;
- }
-
- public byte[] getContent() {
- return content;
- }
-
- public static MediaRenderInfo from(BlobRenderInfo blob, MediaType mediaType) {
- return new MediaRenderInfo(blob.getPath(), blob.getRevision(), mediaType, blob.getContent());
- }
-}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/extensionpoint/MediaRenderer.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/extensionpoint/MediaRenderer.java
index 3c80ac24cf..a6827e8354 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/extensionpoint/MediaRenderer.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/extensionpoint/MediaRenderer.java
@@ -3,6 +3,8 @@ package com.pmease.gitplex.web.extensionpoint;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
+import com.pmease.gitplex.web.component.view.BlobRenderInfo;
+
public interface MediaRenderer {
- Panel render(String panelId, IModel<MediaRenderInfo> mediaModel);
+ Panel render(String panelId, BlobRenderInfo blobInfo, IModel<byte[]> blobContentModel);
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/TestPage.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/TestPage.html
index 4848ec8970..60ec6598e0 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/TestPage.html
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/TestPage.html
@@ -1,5 +1,5 @@
<wicket:extend>
- <div class="padder">
+ <div class="padder" style="background: white;">
<p wicket:id="test">test</p>
<div wicket:id="diff"></div>
</div>
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/TestPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/TestPage.java
index da9d217eb2..ec8c9a8693 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/TestPage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/TestPage.java
@@ -36,7 +36,7 @@ public class TestPage extends BasePage {
protected void onInitialize() {
super.onInitialize();
- add(new DiffTreePanel("test", repoModel, "master", "dev") {
+ add(new DiffTreePanel("test", repoModel, "dev~1", "dev") {
@Override
protected Link<Void> newFileLink(String id, final DiffTreeNode node) {
@@ -44,14 +44,8 @@ public class TestPage extends BasePage {
@Override
public void onClick() {
- TestPage.this.replace(new BlobDiffPanel("diff", repoModel, new LoadableDetachableModel<BlobDiffInfo>() {
-
- @Override
- protected BlobDiffInfo load() {
- return BlobDiffInfo.from(repoModel.getObject().git(), node, "master", "dev");
- }
-
- }));
+ TestPage.this.replace(new BlobDiffPanel("diff", repoModel,
+ BlobDiffInfo.from(repoModel.getObject().git(), node, "dev~1", "dev")));
}
};