Skip to content

The Unified and Autonomous Development Platform

Cleaning up BlobDiffPanel and make TextDiffPanel able to display unchanged files.

robin shineb3d5fd0efb68
diff --git a/commons.git/src/main/java/com/pmease/commons/git/command/ListChangedFilesCommand.java b/commons.git/src/main/java/com/pmease/commons/git/command/ListChangedFilesCommand.java
index 382dce7de7..82b51c7069 100644
--- a/commons.git/src/main/java/com/pmease/commons/git/command/ListChangedFilesCommand.java
+++ b/commons.git/src/main/java/com/pmease/commons/git/command/ListChangedFilesCommand.java
@@ -5,6 +5,7 @@ import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
+import org.eclipse.jgit.util.QuotedString;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -60,7 +61,7 @@ public class ListChangedFilesCommand extends GitCommand<Collection<String>> {
@Override
public void consume(String line) {
if (line.trim().length() != 0)
- changedFiles.add(line);
+ changedFiles.add(QuotedString.GIT_PATH.dequote(line));
}
}, new LineConsumer() {
diff --git a/commons.git/src/main/java/com/pmease/commons/git/command/ListTreeCommand.java b/commons.git/src/main/java/com/pmease/commons/git/command/ListTreeCommand.java
index 1ff32cde56..46f49bbeaf 100644
--- a/commons.git/src/main/java/com/pmease/commons/git/command/ListTreeCommand.java
+++ b/commons.git/src/main/java/com/pmease/commons/git/command/ListTreeCommand.java
@@ -7,6 +7,7 @@ import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
+import org.eclipse.jgit.util.QuotedString;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -62,7 +63,7 @@ public class ListTreeCommand extends GitCommand<List<TreeNode>> {
String sizeStr = StringUtils.substringBefore(line.trim(), "\t");
if (NumberUtils.isNumber(sizeStr))
size = Integer.parseInt(sizeStr);
- String path = StringUtils.substringAfter(line.trim(), "\t");
+ String path = QuotedString.GIT_PATH.dequote(StringUtils.substringAfter(line.trim(), "\t"));
treeNodes.add(new TreeNode(Integer.parseInt(mode, 8), path, hash, size));
}
diff --git a/commons.util/src/main/java/com/pmease/commons/util/Charsets.java b/commons.util/src/main/java/com/pmease/commons/util/Charsets.java
index 126579a36c..cc99391267 100644
--- a/commons.util/src/main/java/com/pmease/commons/util/Charsets.java
+++ b/commons.util/src/main/java/com/pmease/commons/util/Charsets.java
@@ -34,10 +34,14 @@ public class Charsets extends org.apache.commons.io.Charsets {
* charset of the content, or <tt>null</tt> if charset can not be detected
*/
public static @Nullable Charset detectFrom(byte[] contentBytes) {
- try {
- return UniversalEncodingDetector.detect(contentBytes);
- } catch (IOException e) {
- throw new RuntimeException(e);
+ if (contentBytes.length != 0) {
+ try {
+ return UniversalEncodingDetector.detect(contentBytes);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ } else {
+ return Charsets.UTF_8;
}
}
@@ -50,10 +54,14 @@ public class Charsets extends org.apache.commons.io.Charsets {
}
public static boolean isBinary(byte[] contentBytes) {
- try {
- return UniversalEncodingDetector.isBinary(contentBytes);
- } catch (IOException e) {
- throw new RuntimeException(e);
+ if (contentBytes.length != 0) {
+ try {
+ return UniversalEncodingDetector.isBinary(contentBytes);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ } else {
+ return false;
}
}
diff --git a/commons.util/src/main/java/com/pmease/commons/util/MediaTypes.java b/commons.util/src/main/java/com/pmease/commons/util/MediaTypes.java
index 6fb546b15b..028460d7e1 100644
--- a/commons.util/src/main/java/com/pmease/commons/util/MediaTypes.java
+++ b/commons.util/src/main/java/com/pmease/commons/util/MediaTypes.java
@@ -51,7 +51,7 @@ public class MediaTypes {
mediaType = MediaType.parse(type);
else
mediaType = MediaType.OCTET_STREAM;
-
+
if (mediaType.equals(MediaType.OCTET_STREAM)) {
Charset charset = Charsets.detectFrom(contentBytes);
if (charset != null)
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 09962973c0..6c26896508 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
@@ -87,6 +87,8 @@ table td, table th {text-align: left;}
background-color: #999; border-color: #999; color: #FFF;}
.nav li.dropdown .dropdown-hover:hover .caret {border-bottom-color: #FFF; border-top-color: #FFF; opacity: 1;}
+.dropdown-trigger {cursor: pointer;}
+
.dropdown-trigger.pill {border-radius: 4px; margin: 2px 2px 2px 0; padding: 4px 6px; line-height: 12px;}
.dropdown-trigger.pill .caret {border-bottom-color: #0088CC; border-top-color: #0088CC; margin-top: 8px;}
.dropdown-trigger.pill:hover {background-color: #EEE; text-decoration: none;}
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/ScrollBehavior.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/ScrollBehavior.java
index 3cec9355ef..fd70c57006 100644
--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/ScrollBehavior.java
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/ScrollBehavior.java
@@ -4,7 +4,7 @@ import org.apache.wicket.AttributeModifier;
import org.apache.wicket.Component;
import org.apache.wicket.behavior.Behavior;
import org.apache.wicket.markup.head.IHeaderResponse;
-import org.apache.wicket.markup.head.OnDomReadyHeaderItem;
+import org.apache.wicket.markup.head.OnLoadHeaderItem;
@SuppressWarnings("serial")
public class ScrollBehavior extends Behavior {
@@ -58,7 +58,7 @@ public class ScrollBehavior extends Behavior {
+ "$(window).trigger('scrollStopped');",
component.getMarkupId(), function, selector, margin);
- response.render(OnDomReadyHeaderItem.forScript(script));
+ response.render(OnLoadHeaderItem.forScript(script));
}
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/ChangeComments.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/ChangeComments.java
index 49aa48e0ea..3e7a5c0754 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/ChangeComments.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/ChangeComments.java
@@ -128,10 +128,12 @@ public class ChangeComments implements Serializable {
}
}
- List<InlineComment> commentsOnFile = getCommentsOnCommit(comments, change.getOldRevision(), request).get(change.getOldPath());
- if (commentsOnFile != null) {
- for (InlineComment comment: commentsOnFile)
- addLineComment(oldComments, comment.getLine(), comment);
+ if (!change.getOldRevision().equals(change.getNewRevision())) {
+ List<InlineComment> commentsOnFile = getCommentsOnCommit(comments, change.getOldRevision(), request).get(change.getOldPath());
+ if (commentsOnFile != null) {
+ for (InlineComment comment: commentsOnFile)
+ addLineComment(oldComments, comment.getLine(), comment);
+ }
}
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestUpdate.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestUpdate.java
index ca46c5ec76..8256f1c8e9 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestUpdate.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestUpdate.java
@@ -12,6 +12,7 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.locks.Lock;
+import javax.annotation.Nullable;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
@@ -75,6 +76,7 @@ public class PullRequestUpdate extends AbstractEntity {
this.headCommitHash = headCommitHash;
}
+ @Nullable
public User getUser() {
return user;
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/setting/SystemSetting.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/setting/SystemSetting.java
index 03ee3bd864..c10a4e12a2 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/setting/SystemSetting.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/setting/SystemSetting.java
@@ -16,7 +16,7 @@ public class SystemSetting implements Serializable {
private static final long serialVersionUID = -5181868087749961733L;
- private String repoPath;
+ private String storagePath;
private GitConfig gitConfig = new SystemGit();
@@ -26,11 +26,11 @@ public class SystemSetting implements Serializable {
@Directory
@NotEmpty
public String getStoragePath() {
- return repoPath;
+ return storagePath;
}
- public void setRepoPath(String repoPath) {
- this.repoPath = repoPath;
+ public void setStoragePath(String storagePath) {
+ this.storagePath = storagePath;
}
@Editable(order=200, description="GitPlex relies on git command line to operate managed repositories. The minimum "
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/WebModule.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/WebModule.java
index 8574170e15..0ad780549b 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/WebModule.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/WebModule.java
@@ -59,7 +59,7 @@ public class WebModule extends AbstractPluginModule {
contribute(DiffRendererProvider.class, new DiffRendererProvider() {
@Override
- public DiffRenderer getDiffRenderer(MediaType originalMediaType, MediaType revisedMediaType) {
+ public DiffRenderer getDiffRenderer(MediaType mediaType) {
return null;
}
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 f7d2905046..fb04619bd4 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
@@ -768,7 +768,7 @@ h2.section-title { margin: 18px 0; font-size: 16px; }
/* COMPARE RESULT */
.compare-result>tbody>tr>td {border: 1px solid #DDD;}
-.compare-result>tbody>tr>td.nav {width: 20%; padding: 8px;}
+.compare-result>tbody>tr>td.nav {width: 20%; padding: 8px; white-space: nowrap;}
.compare-result>tbody>tr>td.nav a.active {background: #0F89E7; color: white; border-radius: 2px; padding: 2px;}
.compare-result>tbody>tr>td.content>div>div.error {padding: 20px; font-size: 24px; font-style: italic;}
@@ -812,22 +812,12 @@ form#add-comment {margin: 16px 4px;}
.table-diff tr:hover a.add-comment .fa {display:inline;}
ul.diff-alerts li {text-align: left;}
-ul.diff-alerts {padding-left: 12px;}
+ul.diff-alerts {margin: 0 0 0 8px; padding: 4px 8px 4px 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.old {margin-bottom: 16px;}
-.blob-diff.old, .blob-diff.old>.head {border-color: #FC9494;}
-.blob-diff.new, .blob-diff.new>.head {border-color: #07C707;}
-.blob-diff.old>.head {color: #FA5A5A; background: #FDBFBF;}
-.blob-diff.new>.head {color: #059505; background: #B6F8A2;}
-.blob-diff .line {padding: 4px 8px;}
-.blob-diff .line>.fa {width: 16px;}
-.blob-diff .old.line {background: #FCA6A6; color: #8f0000;}
-.blob-diff .new.line {background: #B6F8A2; color: #007f00;}
+.binary-file {border: 1px solid #DDD;}
+.binary-file>.head {padding: 8px; font-size: 16px; border-bottom: 1px solid #DDD;}
+.binary-file>.body {padding: 8px;}
/* DIFF STAT */
.diff-stat {font-family: 'PontIcons'; color: #ddd; }
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 4d9186489b..1003fabc12 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,58 +1,13 @@
<wicket:panel>
- <wicket:enclosure child="oldContent">
- <div class="blob-diff old">
+ <div wicket:id="content"></div>
+ <wicket:fragment wicket:id="binaryFrag">
+ <div class="binary-file">
<div class="head">
- <i class="fa fa-minus"></i> <span wicket:id="oldTitle"></span>
- </div>
- <div wicket:id="oldContent" class="body"></div>
- </div>
- </wicket:enclosure>
- <wicket:enclosure child="newContent">
- <div class="blob-diff new">
- <div class="head">
- <i class="fa fa-plus"></i> <span wicket:id="newTitle"></span>
- </div>
- <div wicket:id="newContent" class="body"></div>
- </div>
- </wicket:enclosure>
- <div wicket:id="blobContent"></div>
- <wicket:fragment wicket:id="notChangedFrag">
- <div class="head">
- <div class="title"><span wicket:id="title"></span> <span class="label label-warning">unchanged</span></div>
- <div wicket:id="content" class="body"></div>
- </div>
- </wicket:fragment>
- <wicket:fragment wicket:id="emptyFileFrag">
- <div class="head"><span wicket:id="summary"></span></div>
- <div class="body">
- <i class='fa fa-info-circle'></i> <em>File is empty</em>
- </div>
- </wicket:fragment>
- <wicket:fragment wicket:id="binaryFileFrag">
- <div class="head"><span wicket:id="summary"></span></div>
- <div class="body">
- <i class='fa fa-info-circle'></i> <em>Binary files</em>
- </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 wicket:id="title"></div>
</div>
<div class="body">
- <div class="old line">
- <i class="fa fa-minus"></i>
- <span wicket:id="oldContent"></span>
- </div>
- <div class="new line">
- <i class="fa fa-plus"></i>
- <span wicket:id="newContent"></span>
- </div>
+ <div class="fa fa-info-circle"> Binary file</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 f220f619d8..0ddaf4fda9 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,11 +1,7 @@
package com.pmease.gitplex.web.component.diff;
-import static com.pmease.commons.git.Change.Status.UNCHANGED;
-
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;
@@ -14,7 +10,6 @@ import org.apache.wicket.util.visit.IVisitor;
import org.eclipse.jgit.lib.FileMode;
import com.google.common.base.Preconditions;
-import com.pmease.commons.git.BlobInfo;
import com.pmease.commons.git.BlobText;
import com.pmease.commons.git.RevAwareChange;
import com.pmease.commons.util.MediaTypes;
@@ -24,9 +19,6 @@ import com.pmease.gitplex.core.comment.InlineCommentSupport;
import com.pmease.gitplex.core.comment.InlineContext;
import com.pmease.gitplex.core.comment.InlineContextAware;
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.component.view.BlobViewPanel;
import com.pmease.gitplex.web.extensionpoint.DiffRenderer;
import com.pmease.gitplex.web.extensionpoint.DiffRendererProvider;
@@ -53,126 +45,79 @@ public class BlobDiffPanel extends Panel implements InlineContextAware {
super.onInitialize();
setOutputMarkupId(true);
-
+
int oldBlobType = change.getOldMode() & FileMode.TYPE_MASK;
int newBlobType = change.getNewMode() & FileMode.TYPE_MASK;
-
- if (change.getStatus() == UNCHANGED) {
- add(new WebMarkupContainer("oldContent").setVisible(false));
- add(new WebMarkupContainer("newContent").setVisible(false));
- Fragment fragment = new Fragment("blobContent", "notChangedFrag", this);
- fragment.add(new Label("title", change.getOldPath()));
- BlobInfo renderInfo = new BlobInfo(change.getNewRevision(),
- change.getNewPath(), change.getNewMode());
- fragment.add(new BlobViewPanel("content", repoModel, renderInfo));
- add(fragment);
- } else if (oldBlobType == FileMode.TYPE_GITLINK && newBlobType == FileMode.TYPE_GITLINK) {
- add(new WebMarkupContainer("oldContent").setVisible(false));
- add(new WebMarkupContainer("newContent").setVisible(false));
-
- Fragment fragment = new Fragment("blobContent", "nonFileDiffFrag", this);
- fragment.add(new Label("renamedTitle", change.getOldPath())
- .setVisible(!change.getOldPath().equals(change.getNewPath())));
- fragment.add(new Label("title", change.getNewPath()));
- BlobText oldText = repoModel.getObject().getBlobText(change.getOldBlobInfo());
- BlobText newText = repoModel.getObject().getBlobText(change.getNewBlobInfo());
- fragment.add(new GitLink("oldContent", oldText.getLines().get(0)));
- fragment.add(new GitLink("newContent", newText.getLines().get(0)));
- add(fragment);
- } else if (oldBlobType == FileMode.TYPE_SYMLINK && newBlobType == FileMode.TYPE_SYMLINK) {
- add(new WebMarkupContainer("oldContent").setVisible(false));
- add(new WebMarkupContainer("newContent").setVisible(false));
- Fragment fragment = new Fragment("blobContent", "nonFileDiffFrag", this);
- fragment.add(new Label("renamedTitle", change.getOldPath())
- .setVisible(!change.getOldPath().equals(change.getNewPath())));
- fragment.add(new Label("title", change.getNewPath()));
- BlobText oldText = repoModel.getObject().getBlobText(change.getOldBlobInfo());
- BlobText newText = repoModel.getObject().getBlobText(change.getNewBlobInfo());
- fragment.add(new SymbolLink("oldContent", repoModel, change.getOldRevision(),
- change.getOldPath(), oldText.getLines().get(0)));
- fragment.add(new SymbolLink("newContent", repoModel, change.getNewRevision(),
- change.getNewPath(), newText.getLines().get(0)));
- add(fragment);
- } else if (oldBlobType == FileMode.TYPE_FILE && newBlobType == FileMode.TYPE_FILE) {
- add(new WebMarkupContainer("oldContent").setVisible(false));
- add(new WebMarkupContainer("newContent").setVisible(false));
-
+ MediaType oldMediaType, newMediaType;
+
+ if (oldBlobType == FileMode.TYPE_GITLINK || oldBlobType == FileMode.TYPE_SYMLINK) {
+ oldMediaType = MediaType.TEXT_PLAIN;
+ } else if (oldBlobType == FileMode.TYPE_FILE) {
byte[] oldContent = repoModel.getObject().getBlobContent(change.getOldBlobInfo());
+ oldMediaType = MediaTypes.detectFrom(oldContent, change.getOldPath());
+ } else {
+ oldMediaType = null;
+ }
+
+ if (newBlobType == FileMode.TYPE_GITLINK || newBlobType == FileMode.TYPE_SYMLINK) {
+ newMediaType = MediaType.TEXT_PLAIN;
+ } else if (newBlobType == FileMode.TYPE_FILE) {
byte[] newContent = repoModel.getObject().getBlobContent(change.getNewBlobInfo());
- MediaType oldMediaType = MediaTypes.detectFrom(oldContent, change.getOldPath());
- MediaType newMediaType = MediaTypes.detectFrom(newContent, change.getNewPath());
-
+ newMediaType = MediaTypes.detectFrom(newContent, change.getNewPath());
+ } else {
+ newMediaType = null;
+ }
+
+ MediaType mediaType;
+ if (oldMediaType != null) {
+ if (newMediaType != null) {
+ if (oldMediaType.equals(newMediaType))
+ mediaType = oldMediaType;
+ else
+ mediaType = null;
+ } else {
+ mediaType = oldMediaType;
+ }
+ } else {
+ mediaType = newMediaType;
+ }
+
+ boolean rendered = false;
+ if (mediaType != null) {
DiffRenderer renderer = null;
for (DiffRendererProvider provider: GitPlex.getExtensions(DiffRendererProvider.class)) {
- renderer = provider.getDiffRenderer(oldMediaType, newMediaType);
+ renderer = provider.getDiffRenderer(mediaType);
if (renderer != null)
break;
}
if (renderer != null) {
- add(renderer.render("blobContent", repoModel, change));
- } else {
- BlobText oldText = repoModel.getObject().getBlobText(change.getOldBlobInfo());
- BlobText newText = repoModel.getObject().getBlobText(change.getNewBlobInfo());
- if (oldText != null) {
- if (newText != null) {
- add(new TextDiffPanel("blobContent", repoModel, oldText, newText, change, commentSupport));
- } else if (newContent.length == 0) {
- add(new TextDiffPanel("blobContent", repoModel, oldText, new BlobText(), change, commentSupport));
- } else {
- Fragment fragment = new Fragment("blobContent", "binaryFileFrag", this);
- fragment.add(new FileDiffTitle("summary", change));
- add(fragment);
- }
- } else if (newText != null) {
- if (oldContent.length == 0) {
- add(new TextDiffPanel("blobContent", repoModel, new BlobText(), newText, change, commentSupport));
- } else {
- Fragment fragment = new Fragment("blobContent", "binaryFileFrag", this);
- fragment.add(new FileDiffTitle("summary", change));
- add(fragment);
- }
- } else if (oldContent.length == 0 && newContent.length == 0) {
- Fragment fragment = new Fragment("blobContent", "emptyFileFrag", this);
- fragment.add(new FileDiffTitle("summary", change));
- add(fragment);
- } else {
- Fragment fragment = new Fragment("blobContent", "binaryFileFrag", this);
- fragment.add(new FileDiffTitle("summary", change));
- add(fragment);
- }
+ add(renderer.render("content", repoModel, change));
+ rendered = true;
}
- } else {
- if (oldBlobType == FileMode.TYPE_SYMLINK) {
- BlobText oldText = repoModel.getObject().getBlobText(change.getOldBlobInfo());
- add(new SymbolLink("oldContent", repoModel, change.getOldRevision(),
- change.getOldPath(), oldText.getLines().get(0)));
- } else if (oldBlobType == FileMode.TYPE_GITLINK) {
- BlobText oldText = repoModel.getObject().getBlobText(change.getOldBlobInfo());
- add(new GitLink("oldContent", oldText.getLines().get(0)));
- } else if (oldBlobType == FileMode.TYPE_FILE) {
- add(new BlobViewPanel("oldContent", repoModel, change.getOldBlobInfo()));
- } else {
- add(new WebMarkupContainer("oldContent").setVisible(false));
- }
- add(new Label("oldTitle", change.getOldPath()));
+ }
+
+ if (!rendered) {
+ BlobText oldText;
+ if (change.getOldPath() != null)
+ oldText = repoModel.getObject().getBlobText(change.getOldBlobInfo());
+ else
+ oldText = null;
- if (newBlobType == FileMode.TYPE_SYMLINK) {
- BlobText newText = repoModel.getObject().getBlobText(change.getNewBlobInfo());
- add(new SymbolLink("newContent", repoModel, change.getNewRevision(),
- change.getNewPath(), newText.getLines().get(0)));
- } else if (newBlobType == FileMode.TYPE_GITLINK) {
- BlobText newText = repoModel.getObject().getBlobText(change.getNewBlobInfo());
- add(new GitLink("newContent", newText.getLines().get(0)));
- } else if (newBlobType == FileMode.TYPE_FILE) {
- add(new BlobViewPanel("newContent", repoModel, change.getNewBlobInfo()));
+ BlobText newText;
+ if (change.getNewPath() != null)
+ newText = repoModel.getObject().getBlobText(change.getNewBlobInfo());
+ else
+ newText = null;
+
+ if (change.getOldPath() != null && oldText == null || change.getNewPath() != null && newText == null) {
+ Fragment fragment = new Fragment("content", "binaryFrag", this);
+ fragment.add(new FileDiffTitle("title", change));
+ add(fragment);
} else {
- add(new WebMarkupContainer("newContent").setVisible(false));
+ add(new TextDiffPanel("content", repoModel, change, commentSupport));
}
- add(new Label("newTitle", change.getNewPath()));
-
- add(new WebMarkupContainer("blobContent").setVisible(false));
- }
+ }
}
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
index 1981f00188..828493bea1 100644
--- 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
@@ -8,9 +8,8 @@ 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.git.Change;
import com.pmease.commons.git.RevAwareChange;
import com.pmease.commons.wicket.behavior.TooltipBehavior;
@@ -26,17 +25,12 @@ public class FileDiffTitle extends Panel {
public FileDiffTitle(String id, RevAwareChange change, List<String> alerts) {
super(id);
-
- int oldBlobType = change.getOldMode() & FileMode.TYPE_MASK;
- int newBlobType = change.getNewMode() & FileMode.TYPE_MASK;
-
- Preconditions.checkArgument(oldBlobType == FileMode.TYPE_FILE && newBlobType == FileMode.TYPE_FILE);
-
+
this.change = change;
this.alerts = new ArrayList<>();
- if (change.getOldMode() != change.getNewMode()) {
- this.alerts.add("File mode is changed from " + Integer.toString(change.getOldMode(), 8)
+ if (change.getOldMode() != 0 && change.getNewMode() != 0 && change.getOldMode() != change.getNewMode()) {
+ this.alerts.add("Blob mode is changed from " + Integer.toString(change.getOldMode(), 8)
+ " to " + Integer.toString(change.getNewMode(), 8));
}
if (alerts != null)
@@ -52,8 +46,8 @@ public class FileDiffTitle extends Panel {
super.onInitialize();
add(new Label("renamedTitle", change.getOldPath())
- .setVisible(!change.getOldPath().equals(change.getNewPath())));
- add(new Label("title", change.getNewPath()));
+ .setVisible(change.getStatus() == Change.Status.RENAMED));
+ add(new Label("title", change.getPath()));
if (alerts.size() == 0) {
add(new WebMarkupContainer("alerts").setVisible(false));
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 c7f12f9da2..39e1e3e2ec 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
@@ -12,7 +12,7 @@
<div class="pull-right">
<span wicket:id="displayFull" class="btn btn-xs btn-default" title="Expand to display full file"><i class="fa fa-file-txt"></i> </span>
</div>
- <div class="btn-group pull-right">
+ <div wicket:id="commentNavs" class="btn-group pull-right">
<span wicket:id="prevComment" class="btn btn-default btn-xs comments-nav" title="Previous comment not in view"><i class="fa fa-arrow-up"></i> <i class="fa fa-comments"></i></span>
<span wicket:id="nextComment" class="btn btn-default btn-xs comments-nav" title="Next comment not in view"><i class="fa fa-arrow-down"></i> <i class="fa fa-comments"></i></span>
<span wicket:id="showComments" class="btn btn-default btn-xs show-comments" title="Show comments"><i class="fa fa-eye-open"></i> <i class="fa fa-comments"></i></span>
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 ef5b9ca87a..44ebff70cd 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
@@ -82,19 +82,15 @@ public class TextDiffPanel extends Panel implements InlineContextAware {
private final IModel<Repository> repoModel;
- private final BlobText oldText;
-
- private final BlobText newText;
-
private final RevAwareChange change;
private final InlineCommentSupport commentSupport;
private final IModel<Boolean> allowToAddCommentModel;
- private BlobText effectiveOldText;
+ private BlobText oldText;
- private BlobText effectiveNewText;
+ private BlobText newText;
private DiffOption diffOption = DiffOption.IGNORE_NOTHING;
@@ -120,20 +116,15 @@ public class TextDiffPanel extends Panel implements InlineContextAware {
private String autoScrollScript;
- public TextDiffPanel(String id, final IModel<Repository> repoModel,
- BlobText oldText, BlobText newText, RevAwareChange change,
+ public TextDiffPanel(String id, final IModel<Repository> repoModel, RevAwareChange change,
final @Nullable InlineCommentSupport commentSupport) {
super(id);
this.repoModel = repoModel;
- Preconditions.checkArgument(!change.getOldRevision().equals(change.getNewRevision()));
this.change = change;
this.commentSupport = commentSupport;
- this.oldText = oldText;
- this.newText = newText;
-
// cache add comment permission check in model to avoid recalculation for every line
allowToAddCommentModel = new LoadableDetachableModel<Boolean>() {
@@ -203,20 +194,20 @@ public class TextDiffPanel extends Panel implements InlineContextAware {
private void onDiffOptionChanged() {
if (diffOption == DiffOption.IGNORE_EOL) {
- effectiveOldText = oldText.ignoreEOL();
- effectiveNewText = newText.ignoreEOL();
+ oldText = readOldText().ignoreEOL();
+ newText = readNewText().ignoreEOL();
} else if (diffOption == DiffOption.IGNORE_EOL_SPACES) {
- effectiveOldText = oldText.ignoreEOLSpaces();
- effectiveNewText = newText.ignoreEOLSpaces();
+ oldText = readOldText().ignoreEOLSpaces();
+ newText = readNewText().ignoreEOLSpaces();
} else if (diffOption == DiffOption.IGNORE_CHANGE_SPACES) {
- effectiveOldText = oldText.ignoreChangeSpaces();
- effectiveNewText = newText.ignoreChangeSpaces();
+ oldText = readOldText().ignoreChangeSpaces();
+ newText = readNewText().ignoreChangeSpaces();
} else {
- effectiveOldText = oldText;
- effectiveNewText = newText;
+ oldText = readOldText();
+ newText = readNewText();
}
- diffs = DiffUtils.diff(effectiveOldText.getLines(), effectiveNewText.getLines(), new WordSplitter());
+ diffs = DiffUtils.diff(oldText.getLines(), newText.getLines(), new WordSplitter());
identical = true;
for (DiffLine diffLine: diffs) {
@@ -225,12 +216,17 @@ public class TextDiffPanel extends Panel implements InlineContextAware {
break;
}
}
-
- if (commentSupport != null) {
- hunks = DiffUtils.hunksOf(diffs, commentSupport.getOldComments().keySet(),
- commentSupport.getNewComments().keySet(), CONTEXT_SIZE);
+
+ if (!identical) {
+ if (commentSupport != null) {
+ hunks = DiffUtils.hunksOf(diffs, commentSupport.getOldComments().keySet(),
+ commentSupport.getNewComments().keySet(), CONTEXT_SIZE);
+ } else {
+ hunks = DiffUtils.hunksOf(diffs, CONTEXT_SIZE);
+ }
} else {
- hunks = DiffUtils.hunksOf(diffs, CONTEXT_SIZE);
+ hunks = new ArrayList<>();
+ hunks.add(new DiffHunk(0, 0, diffs));
}
}
@@ -271,7 +267,8 @@ public class TextDiffPanel extends Panel implements InlineContextAware {
add(head);
List<String> alerts = new ArrayList<>();
- if (!oldText.getCharset().equals(newText.getCharset()))
+ if (change.getOldPath() != null && change.getNewPath() != null
+ && !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");
@@ -303,8 +300,19 @@ public class TextDiffPanel extends Panel implements InlineContextAware {
diffNavs.add(new WebMarkupContainer("prevDiff").add(new ScrollBehavior(".diff-block", SCROLL_MARGIN, false)));
diffNavs.add(new WebMarkupContainer("nextDiff").add(new ScrollBehavior(".diff-block", SCROLL_MARGIN, true)));
+
+ WebMarkupContainer commentNavs = new WebMarkupContainer("commentNavs") {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+ setVisible(!commentsModel.getObject().isEmpty());
+ }
+
+ };
+ head.add(commentNavs);
- head.add(new WebMarkupContainer("prevComment") {
+ commentNavs.add(new WebMarkupContainer("prevComment") {
@Override
protected void onConfigure() {
@@ -314,7 +322,7 @@ public class TextDiffPanel extends Panel implements InlineContextAware {
}.add(new ScrollBehavior(".comments.line", 50, false)));
- head.add(new WebMarkupContainer("nextComment") {
+ commentNavs.add(new WebMarkupContainer("nextComment") {
@Override
protected void onConfigure() {
@@ -324,7 +332,7 @@ public class TextDiffPanel extends Panel implements InlineContextAware {
}.add(new ScrollBehavior(".comments.line", 50, true)));
- head.add(new AjaxLink<Void>("showComments") {
+ commentNavs.add(new AjaxLink<Void>("showComments") {
@Override
public void onClick(AjaxRequestTarget target) {
@@ -338,7 +346,7 @@ public class TextDiffPanel extends Panel implements InlineContextAware {
}
});
- head.add(new AjaxLink<Void>("hideComments") {
+ commentNavs.add(new AjaxLink<Void>("hideComments") {
@Override
public void onClick(AjaxRequestTarget target) {
@@ -554,6 +562,9 @@ public class TextDiffPanel extends Panel implements InlineContextAware {
commentsRow.getMarkupId());
target.prependJavaScript(prependScript);
target.appendJavaScript(String.format("gitplex.comments.afterAdd(%d);", index));
+
+ if (commentsView.size() == 1)
+ target.add(head);
}
});
@@ -643,7 +654,8 @@ public class TextDiffPanel extends Panel implements InlineContextAware {
}
private String renderDiffs(List<DiffLine> diffLines) {
- Preconditions.checkArgument(!diffLines.isEmpty());
+ if (diffLines.isEmpty())
+ return "";
StringBuilder builder = new StringBuilder();
@@ -880,6 +892,20 @@ public class TextDiffPanel extends Panel implements InlineContextAware {
super.onDetach();
}
+ private BlobText readOldText() {
+ if (change.getOldPath() != null)
+ return Preconditions.checkNotNull(repoModel.getObject().getBlobText(change.getOldBlobInfo()));
+ else
+ return new BlobText();
+ }
+
+ private BlobText readNewText() {
+ if (change.getNewPath() != null)
+ return Preconditions.checkNotNull(repoModel.getObject().getBlobText(change.getNewBlobInfo()));
+ else
+ return new BlobText();
+ }
+
@Override
public InlineContext getInlineContext(InlineComment comment) {
int oldLine = -1;
@@ -931,7 +957,6 @@ public class TextDiffPanel extends Panel implements InlineContextAware {
return new InlineContext(contextDiffs, index-start, start>0, end<diffs.size()-1);
}
-
private int locateDiffPos(int lineNo, DiffLine.Action excludeAction) {
int index = 0;
for (int i=0; i<diffs.size(); i++) {
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/extensionpoint/DiffRendererProvider.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/extensionpoint/DiffRendererProvider.java
index b2257265c8..86a516e6e7 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/extensionpoint/DiffRendererProvider.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/extensionpoint/DiffRendererProvider.java
@@ -8,5 +8,5 @@ import com.pmease.commons.loader.ExtensionPoint;
@ExtensionPoint
public interface DiffRendererProvider {
- @Nullable DiffRenderer getDiffRenderer(MediaType originalMediaType, MediaType revisedMediaType);
+ @Nullable DiffRenderer getDiffRenderer(MediaType mediaType);
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/activity/PullRequestActivity.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/activity/PullRequestActivity.java
index 5f6b044396..a850fed205 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/activity/PullRequestActivity.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/activity/PullRequestActivity.java
@@ -3,6 +3,8 @@ package com.pmease.gitplex.web.page.repository.info.pullrequest.activity;
import java.io.Serializable;
import java.util.Date;
+import javax.annotation.Nullable;
+
import org.apache.wicket.markup.html.panel.Panel;
import com.pmease.gitplex.core.model.User;
@@ -11,6 +13,7 @@ public interface PullRequestActivity extends Serializable {
Date getDate();
+ @Nullable
User getUser();
Panel render(String panelId);