The Unified and Autonomous Development Platform
Locate specific comment in request compare page.
robin shine8ff937dd8682
diff --git a/commons.git/src/main/java/com/pmease/commons/git/RevAwareChange.java b/commons.git/src/main/java/com/pmease/commons/git/RevAwareChange.javaindex 7ba33ea335..e3beaec02a 100644--- a/commons.git/src/main/java/com/pmease/commons/git/RevAwareChange.java+++ b/commons.git/src/main/java/com/pmease/commons/git/RevAwareChange.java@@ -9,6 +9,10 @@ public class RevAwareChange extends Change {private final String newRevision;+ public RevAwareChange(RevAwareChange change) {+ this(change, change.getOldRevision(), change.getNewRevision());+ }+public RevAwareChange(Change change, @Nullable String oldRevision, @Nullable String newRevision) {super(change);this.oldRevision = oldRevision;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/CommentAwareChange.javasimilarity index 84%rename from gitplex.core/src/main/java/com/pmease/gitplex/core/comment/ChangeComments.javarename to gitplex.core/src/main/java/com/pmease/gitplex/core/comment/CommentAwareChange.javaindex a92ebfd11d..991f667886 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/CommentAwareChange.java@@ -1,6 +1,5 @@package com.pmease.gitplex.core.comment;-import java.io.Serializable;import java.util.ArrayList;import java.util.Date;import java.util.HashMap;@@ -20,7 +19,7 @@ import com.pmease.gitplex.core.model.CommentPosition;import com.pmease.gitplex.core.model.CommitComment;@SuppressWarnings("serial")-public class ChangeComments implements Serializable {+public class CommentAwareChange extends RevAwareChange {private final Map<String, Date> commits;@@ -28,21 +27,16 @@ public class ChangeComments implements Serializable {private Map<Integer, List<CommitComment>> newComments;- public ChangeComments(RevAwareChange change, LinkedHashMap<String, Date> commits,+ public CommentAwareChange(RevAwareChange change, LinkedHashMap<String, Date> commits,CommentLoader commentLoader, BlobLoader blobLoader) {-+ super(change);+Map<String, Map<String, List<CommitComment>>> comments = new HashMap<>();Map<BlobInfo, List<String>> blobs = new HashMap<>();-+this.commits = commits;List<String> commitHashes = new ArrayList<>(commits.keySet());- int begin = -1;- if (change.getOldPath() != null) {- begin = commitHashes.indexOf(change.getOldRevision());- if (begin != -1 && getBlob(blobs, change.getOldBlobInfo(), blobLoader).isEmpty())- begin = -1;- }int end = -1;if (change.getNewPath() != null) {end = commitHashes.indexOf(change.getNewRevision());@@ -50,64 +44,72 @@ public class ChangeComments implements Serializable {end = -1;}- if (begin != -1) {- oldComments = new HashMap<>();+ int begin = -1;+ if (change.getOldPath() != null) {+ begin = commitHashes.indexOf(change.getOldRevision());+ if (begin != -1 && getBlob(blobs, change.getOldBlobInfo(), blobLoader).isEmpty())+ begin = -1;+ }++ if (end != -1) {+ newComments = new HashMap<>();- for (int i=begin+1; i<(end!=-1?end:commits.size()); i++) {+ for (int i=end-1; i>begin; i--) {String commit = commitHashes.get(i);Map<String, List<CommitComment>> commentsOnCommit = getCommentsOnCommit(comments, commit, commentLoader);BlobInfo blobInfo = null;- List<CommitComment> commentsOnFile = commentsOnCommit.get(change.getOldPath());+ List<CommitComment> commentsOnFile = commentsOnCommit.get(change.getNewPath());if (commentsOnFile != null) {- blobInfo = new BlobInfo(commit, change.getOldPath(), change.getOldMode());+ blobInfo = new BlobInfo(commit, change.getNewPath(), change.getNewMode());} else {- commentsOnFile = commentsOnCommit.get(change.getNewPath());+ commentsOnFile = commentsOnCommit.get(change.getOldPath());if (commentsOnFile != null)- blobInfo = new BlobInfo(commit, change.getNewPath(), change.getNewMode());+ blobInfo = new BlobInfo(commit, change.getOldPath(), change.getOldMode());}if (blobInfo != null) {- List<String> fileContent = blobLoader.loadBlob(blobInfo);+ List<String> fileContent = getBlob(blobs, blobInfo, blobLoader);if (!fileContent.isEmpty()) {- List<String> oldContent = getBlob(blobs, change.getOldBlobInfo(), blobLoader);- Map<Integer, Integer> lineMap = DiffUtils.mapLines(fileContent, oldContent);+ List<String> newContent = getBlob(blobs, change.getNewBlobInfo(), blobLoader);+ Map<Integer, Integer> lineMap = DiffUtils.mapLines(fileContent, newContent);for (CommitComment comment: commentsOnFile) {Integer lineNo = lineMap.get(comment.getPosition().getLineNo());if (lineNo != null)- addLineComment(oldComments, lineNo, comment);+ addLineComment(newComments, lineNo, comment);}}}}- List<CommitComment> commentsOnFile = getCommentsOnCommit(comments, change.getOldRevision(), commentLoader).get(change.getOldPath());+ List<CommitComment> commentsOnFile = getCommentsOnCommit(comments, change.getNewRevision(), commentLoader).get(change.getNewPath());if (commentsOnFile != null) {for (CommitComment comment: commentsOnFile)- addLineComment(oldComments, comment.getPosition().getLineNo(), comment);+ addLineComment(newComments, comment.getPosition().getLineNo(), comment);}}-- if (end != -1) {- newComments = new HashMap<>();++ if (begin != -1) {+ oldComments = new HashMap<>();Set<CommentKey> appliedComments = new HashSet<>();- if (oldComments != null) {- for (List<CommitComment> list: oldComments.values()) {+ if (newComments != null) {+ for (List<CommitComment> list: newComments.values()) {for (CommitComment comment: list)appliedComments.add(new CommentKey(comment.getCommit(), comment.getPosition()));}}- for (int i=end-1; i>begin; i--) {++ for (int i=begin+1; i<(end!=-1?end:commits.size()); i++) {String commit = commitHashes.get(i);Map<String, List<CommitComment>> commentsOnCommit = getCommentsOnCommit(comments, commit, commentLoader);BlobInfo blobInfo = null;- List<CommitComment> commentsOnFile = commentsOnCommit.get(change.getNewPath());+ List<CommitComment> commentsOnFile = commentsOnCommit.get(change.getOldPath());if (commentsOnFile != null) {- blobInfo = new BlobInfo(commit, change.getNewPath(), change.getNewMode());+ blobInfo = new BlobInfo(commit, change.getOldPath(), change.getOldMode());} else {- commentsOnFile = commentsOnCommit.get(change.getOldPath());+ commentsOnFile = commentsOnCommit.get(change.getNewPath());if (commentsOnFile != null)- blobInfo = new BlobInfo(commit, change.getOldPath(), change.getOldMode());+ blobInfo = new BlobInfo(commit, change.getNewPath(), change.getNewMode());}if (blobInfo != null) {@@ -120,25 +122,25 @@ public class ChangeComments implements Serializable {}}if (!allApplied) {- List<String> fileContent = getBlob(blobs, blobInfo, blobLoader);+ List<String> fileContent = blobLoader.loadBlob(blobInfo);if (!fileContent.isEmpty()) {- List<String> newContent = getBlob(blobs, change.getNewBlobInfo(), blobLoader);- Map<Integer, Integer> lineMap = DiffUtils.mapLines(fileContent, newContent);+ List<String> oldContent = getBlob(blobs, change.getOldBlobInfo(), blobLoader);+ Map<Integer, Integer> lineMap = DiffUtils.mapLines(fileContent, oldContent);for (CommitComment comment: commentsOnFile) {CommentKey key = new CommentKey(comment.getCommit(), comment.getPosition());Integer lineNo = lineMap.get(comment.getPosition().getLineNo());if (!appliedComments.contains(key) && lineNo != null)- addLineComment(newComments, lineNo, comment);+ addLineComment(oldComments, lineNo, comment);}}}}}- List<CommitComment> commentsOnFile = getCommentsOnCommit(comments, change.getNewRevision(), commentLoader).get(change.getNewPath());+ List<CommitComment> commentsOnFile = getCommentsOnCommit(comments, change.getOldRevision(), commentLoader).get(change.getOldPath());if (commentsOnFile != null) {for (CommitComment comment: commentsOnFile)- addLineComment(newComments, comment.getPosition().getLineNo(), comment);+ addLineComment(oldComments, comment.getPosition().getLineNo(), comment);}}@@ -197,6 +199,26 @@ public class ChangeComments implements Serializable {}return blob;}++ public boolean contains(CommitComment comment) {+ if (getOldComments() != null) {+ for (List<CommitComment> lineComments: getOldComments().values()) {+ for (CommitComment each: lineComments) {+ if (each.getId().equals(comment.getId()))+ return true;+ }+ }+ }+ if (getNewComments() != null) {+ for (List<CommitComment> lineComments: getNewComments().values()) {+ for (CommitComment each: lineComments) {+ if (each.getId().equals(comment.getId()))+ return true;+ }+ }+ }+ return false;+ }private static class CommentKey extends Pair<String, CommentPosition> {diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/CommentVisit.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/CommentVisit.javaindex 2bc82b9700..83a381e813 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/CommentVisit.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/CommentVisit.java@@ -16,7 +16,7 @@ import com.pmease.commons.hibernate.AbstractEntity;@SuppressWarnings("serial")@Entity@Table(uniqueConstraints={- @UniqueConstraint(columnNames={"repository", "commit", "position.filePath", "position.lineNo"})+ @UniqueConstraint(columnNames={"repository", "commit", "filePath", "lineNo"})})public class CommentVisit extends AbstractEntity {diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequest.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequest.javaindex 0473998eee..b52d2e19bb 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequest.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequest.java@@ -38,8 +38,8 @@ import com.pmease.gitplex.core.gatekeeper.checkresult.Disapproved;import com.pmease.gitplex.core.gatekeeper.checkresult.Ignored;import com.pmease.gitplex.core.gatekeeper.checkresult.Pending;import com.pmease.gitplex.core.gatekeeper.checkresult.PendingAndBlock;-import com.pmease.gitplex.core.manager.CommitCommentManager;import com.pmease.gitplex.core.manager.CommentVisitManager;+import com.pmease.gitplex.core.manager.CommitCommentManager;@SuppressWarnings("serial")@Entity@@ -545,7 +545,7 @@ public class PullRequest extends AbstractEntity {}return commitComments;}-+public Map<String, Map<CommentPosition, Date>> getCommentVisits() {if (commentVisits == null) {commentVisits = new HashMap<>();@@ -569,5 +569,5 @@ public class PullRequest extends AbstractEntity {}return commentVisits;}-+}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/Repository.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/Repository.javaindex e416359365..29f9cd178b 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/Repository.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/Repository.java@@ -27,11 +27,13 @@ import org.hibernate.validator.constraints.NotEmpty;import com.google.common.base.Optional;import com.pmease.commons.editable.annotation.Editable;import com.pmease.commons.git.BlobInfo;+import com.pmease.commons.git.Change;import com.pmease.commons.git.Git;import com.pmease.commons.git.BlobText;import com.pmease.commons.hibernate.AbstractEntity;import com.pmease.commons.loader.AppLoader;import com.pmease.commons.util.FileUtils;+import com.pmease.commons.util.Pair;import com.pmease.gitplex.core.GitPlex;import com.pmease.gitplex.core.gatekeeper.AndGateKeeper;import com.pmease.gitplex.core.gatekeeper.GateKeeper;@@ -95,9 +97,11 @@ public class Repository extends AbstractEntity implements UserBelonging {@OneToMany(mappedBy="forkedFrom")private Collection<Repository> forks = new ArrayList<>();- private transient Map<BlobInfo, byte[]> blobContents = new HashMap<>();+ private transient Map<BlobInfo, byte[]> blobContentCache = new HashMap<>();- private transient Map<BlobInfo, Optional<BlobText>> blobTexts = new HashMap<>();+ private transient Map<BlobInfo, Optional<BlobText>> blobTextCache = new HashMap<>();++ private transient Map<CommitRange, List<Change>> changesCache = new HashMap<>();public User getOwner() {return owner;@@ -361,10 +365,10 @@ public class Repository extends AbstractEntity implements UserBelonging {* content of the blob*/public byte[] getBlobContent(BlobInfo blobInfo) {- byte[] blobContent = blobContents.get(blobInfo);+ byte[] blobContent = blobContentCache.get(blobInfo);if (blobContent == null) {blobContent = git().readBlob(blobInfo);- blobContents.put(blobInfo, blobContent);+ blobContentCache.put(blobInfo, blobContent);}return blobContent;}@@ -385,13 +389,28 @@ public class Repository extends AbstractEntity implements UserBelonging {*/@Nullablepublic BlobText getBlobText(BlobInfo blobInfo) {- Optional<BlobText> optional = blobTexts.get(blobInfo);+ Optional<BlobText> optional = blobTextCache.get(blobInfo);if (optional == null) {byte[] blobContent = getBlobContent(blobInfo);optional = Optional.fromNullable(BlobText.from(blobContent, blobInfo.getPath(), blobInfo.getMode()));- blobTexts.put(blobInfo, optional);+ blobTextCache.put(blobInfo, optional);}return optional.orNull();}++ public List<Change> getChanges(String fromCommit, String toCommit) {+ CommitRange range = new CommitRange(fromCommit, toCommit);+ List<Change> changes = changesCache.get(range);+ if (changes == null) {+ changes = git().listFileChanges(fromCommit, toCommit, null, true);+ changesCache.put(range, changes);+ }+ return changes;+ }+ private static class CommitRange extends Pair<String, String> {+ CommitRange(String fromCommit, String toCommit) {+ super(fromCommit, toCommit);+ }+ }}diff --git a/gitplex.core/src/test/java/com/pmease/gitplex/core/comment/ChangeCommentsTest.java b/gitplex.core/src/test/java/com/pmease/gitplex/core/comment/CommentAwareChangeTest.javasimilarity index 84%rename from gitplex.core/src/test/java/com/pmease/gitplex/core/comment/ChangeCommentsTest.javarename to gitplex.core/src/test/java/com/pmease/gitplex/core/comment/CommentAwareChangeTest.javaindex 00425a01a9..498760d10d 100644--- a/gitplex.core/src/test/java/com/pmease/gitplex/core/comment/ChangeCommentsTest.java+++ b/gitplex.core/src/test/java/com/pmease/gitplex/core/comment/CommentAwareChangeTest.java@@ -20,7 +20,7 @@ import com.pmease.commons.git.RevAwareChange;import com.pmease.gitplex.core.model.CommentPosition;import com.pmease.gitplex.core.model.CommitComment;-public class ChangeCommentsTest extends AbstractGitTest {+public class CommentAwareChangeTest extends AbstractGitTest {@Testpublic void test() {@@ -29,7 +29,7 @@ public class ChangeCommentsTest extends AbstractGitTest {+ "11\n" //comment1+ "22\n"+ "33\n"- + "44\n" //comment5+ + "44\n"+ "55\n" //comment3, comment6+ "66\n"+ "77\n"@@ -59,7 +59,7 @@ public class ChangeCommentsTest extends AbstractGitTest {+ "111\n"+ "222\n" //comment2+ "33\n"- + "44\n"+ + "44\n" //comment5+ "555\n"+ "66\n"+ "77\n"@@ -178,16 +178,16 @@ public class ChangeCommentsTest extends AbstractGitTest {RevAwareChange change = new RevAwareChange(Change.Status.MODIFIED, "file1", "file1",0, 0, commitHashes.get(0), commitHashes.get(3));- ChangeComments comments = new ChangeComments(change, commits, commentLoader, fileLoader);+ CommentAwareChange commentAwareChange = new CommentAwareChange(change, commits, commentLoader, fileLoader);- assertEquals("comment1", comments.getOldComments().get(0).get(0).getContent());- assertEquals("comment2", comments.getNewComments().get(1).get(0).getContent());- assertEquals("comment3", comments.getOldComments().get(4).get(0).getContent());- assertEquals("comment4", comments.getOldComments().get(7).get(0).getContent());- assertEquals("comment5", comments.getOldComments().get(3).get(0).getContent());- assertEquals("comment6", comments.getOldComments().get(4).get(1).getContent());- assertEquals("comment8", comments.getNewComments().get(8).get(0).getContent());- assertEquals("comment9", comments.getNewComments().get(8).get(1).getContent());+ assertEquals("comment1", commentAwareChange.getOldComments().get(0).get(0).getContent());+ assertEquals("comment2", commentAwareChange.getNewComments().get(1).get(0).getContent());+ assertEquals("comment3", commentAwareChange.getOldComments().get(4).get(0).getContent());+ assertEquals("comment4", commentAwareChange.getOldComments().get(7).get(0).getContent());+ assertEquals("comment5", commentAwareChange.getNewComments().get(3).get(0).getContent());+ assertEquals("comment6", commentAwareChange.getOldComments().get(4).get(1).getContent());+ assertEquals("comment8", commentAwareChange.getNewComments().get(8).get(0).getContent());+ assertEquals("comment9", commentAwareChange.getNewComments().get(8).get(1).getContent());}}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.cssindex 1d76d53e21..12a314d0ef 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@@ -924,14 +924,19 @@ ul.status-help li:last-child .description {border-bottom: none;}.request-detail .base-threads>.title {margin-bottom: 12px;}.request-detail .base-threads>.content {margin-left: 6px;}-.request-detail .compare>.head .original {margin-right: 32px;}+.request-detail .compare>.head .comment {margin-right: 20px;}+.request-detail .compare>.head .old {margin-right: 20px;}.request-detail .compare>.head {border-bottom: 1px dashed #BBB; padding-bottom: 16px;}+.content>.commit-choice {max-height: 600px; padding: 8px 0; overflow-y: scroll;}.content>.commit-choice a {text-decoration: none; color: #333; display: block; padding: 8px;}.content>.commit-choice li {border-bottom: 1px dotted #BBB;}+.content>.commit-choice li.special {background: #F0F0F0;}+.content>.commit-choice li.concerned {background: #B1D0FB;}.content>.commit-choice li:hover {background: #FDF2C3;}.content>.commit-choice a .name {font-family: Consolas, 'Liberation Mono', Courier, monospace;}.content>.commit-choice a .subject {font-size: 12px; color: #999;}+.request-detail .compare>.body {margin-top: 16px;}.request-detail .compare>.body>tbody>tr>td.nav {width: 1%;}.request-detail .compare>.body>tbody>tr>td.nav .panel-heading {white-space: nowrap;}@@ -968,8 +973,7 @@ table.verifications tr.ongoing .fa-cog {display: inline; color: #F0AD4E;}.conflict-resolve-instruction {padding: 8px; width: 400px;}.integration-setting form {color: #666;}-.branch-strategies.editor {- margin-bottom: 16px;}+.branch-strategies.editor {margin-bottom: 16px;}.integration-setting fieldset {border: 1px solid #DDD !important; margin-bottom: 16px;padding: 16px !important;}.integration-setting legend {width:auto; margin-bottom: 0; border-bottom:none;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.javaindex 16bdea16cc..b053f04ec2 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@@ -2,8 +2,6 @@ package com.pmease.gitplex.web.component.diff;import static com.pmease.commons.git.Change.Status.UNCHANGED;-import javax.annotation.Nullable;-import org.apache.tika.mime.MediaType;import org.apache.wicket.markup.html.WebMarkupContainer;import org.apache.wicket.markup.html.basic.Label;@@ -14,10 +12,9 @@ import org.eclipse.jgit.lib.FileMode;import com.pmease.commons.git.BlobInfo;import com.pmease.commons.git.BlobText;-import com.pmease.commons.git.RevAwareChange;import com.pmease.commons.util.MediaTypes;import com.pmease.gitplex.core.GitPlex;-import com.pmease.gitplex.core.comment.ChangeComments;+import com.pmease.gitplex.core.comment.CommentAwareChange;import com.pmease.gitplex.core.model.Repository;import com.pmease.gitplex.web.component.gitlink.GitLink;import com.pmease.gitplex.web.component.symbollink.SymbolLink;@@ -30,20 +27,16 @@ public class BlobDiffPanel extends Panel {private final IModel<Repository> repoModel;- private final RevAwareChange change;-- private final ChangeComments comments;+ private final CommentAwareChange change;- public BlobDiffPanel(String id, IModel<Repository> repoModel, RevAwareChange change,- @Nullable ChangeComments comments, int lineNo) {+ public BlobDiffPanel(String id, IModel<Repository> repoModel, CommentAwareChange change, int lineNo) {super(id);this.repoModel = repoModel;this.change = change;- this.comments = comments;}- public RevAwareChange getChange() {+ public CommentAwareChange getChange() {return change;}@@ -51,6 +44,8 @@ public class BlobDiffPanel extends Panel {protected void onInitialize() {super.onInitialize();+ setOutputMarkupId(true);+int oldBlobType = change.getOldMode() & FileMode.TYPE_MASK;int newBlobType = change.getNewMode() & FileMode.TYPE_MASK;@@ -113,9 +108,9 @@ public class BlobDiffPanel extends Panel {BlobText newText = repoModel.getObject().getBlobText(change.getNewBlobInfo());if (oldText != null) {if (newText != null) {- add(new TextDiffPanel("blobContent", repoModel, change, oldText, newText, comments));+ add(new TextDiffPanel("blobContent", repoModel, oldText, newText, change));} else if (newContent.length == 0) {- add(new TextDiffPanel("blobContent", repoModel, change, oldText, new BlobText(), comments));+ add(new TextDiffPanel("blobContent", repoModel, oldText, new BlobText(), change));} else {Fragment fragment = new Fragment("blobContent", "binaryFileFrag", this);fragment.add(new FileDiffTitle("summary", change));@@ -123,7 +118,7 @@ public class BlobDiffPanel extends Panel {}} else if (newText != null) {if (oldContent.length == 0) {- add(new TextDiffPanel("blobContent", repoModel, change, new BlobText(), newText, comments));+ add(new TextDiffPanel("blobContent", repoModel, new BlobText(), newText, change));} else {Fragment fragment = new Fragment("blobContent", "binaryFileFrag", this);fragment.add(new FileDiffTitle("summary", change));diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/ChangedFilesPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/ChangedFilesPanel.htmlindex 8db431d733..45a6ba902c 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/ChangedFilesPanel.html+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/ChangedFilesPanel.html@@ -1,7 +1,13 @@<wicket:panel>- <ul class="changed-files list-unstyled">- <li wicket:id="changes">- <a wicket:id="link"><span wicket:id="label"></span></a>- </li>- </ul>+ <div wicket:id="content"></div>+ <wicket:fragment wicket:id="changesFrag">+ <ul class="changed-files list-unstyled">+ <li wicket:id="changes">+ <a wicket:id="link"><span wicket:id="label"></span></a>+ </li>+ </ul>+ </wicket:fragment>+ <wicket:fragment wicket:id="noChangesFrag">+ <i class='fa fa-info-circle'></i> <em>Nothing changed</em>+ </wicket:fragment></wicket:panel>\ No newline at end of filediff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/ChangedFilesPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/ChangedFilesPanel.javaindex 3428bff713..a3a60d7e89 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/ChangedFilesPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/ChangedFilesPanel.java@@ -7,41 +7,64 @@ 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.Fragment;import org.apache.wicket.markup.html.panel.Panel;import org.apache.wicket.model.IModel;import com.pmease.commons.git.Change;+import com.pmease.gitplex.core.model.Repository;@SuppressWarnings("serial")public abstract class ChangedFilesPanel extends Panel {- private final IModel<List<Change>> changesModel;+ private final IModel<Repository> repoModel;- public ChangedFilesPanel(String id, IModel<List<Change>> changesModel) {+ private final String fromRev;++ private final String toRev;++ public ChangedFilesPanel(String id, IModel<Repository> repoModel, String fromRev, String toRev) {super(id);- this.changesModel = changesModel;+ this.repoModel = repoModel;+ this.fromRev = fromRev;+ this.toRev = toRev;}@Overrideprotected void onInitialize() {super.onInitialize();- add(new ListView<Change>("changes", changesModel) {-- @Override- protected void populateItem(ListItem<Change> item) {- Change change = item.getModelObject();- WebMarkupContainer link = newBlobLink("link", change);- link.add(new Label("label", change.getPath()));- link.add(AttributeAppender.append("title", change.getHint()));- item.add(link);- item.add(AttributeAppender.append("class", " file " + change.getStatus().name().toLowerCase()));- }-- });+ List<Change> changes = repoModel.getObject().getChanges(fromRev, toRev);+ Fragment fragment;+ if (!changes.isEmpty()) {+ fragment = new Fragment("content", "changesFrag", this);+ fragment.add(new ListView<Change>("changes", repoModel.getObject().getChanges(fromRev, toRev)) {++ @Override+ protected void populateItem(ListItem<Change> item) {+ Change change = item.getModelObject();+ WebMarkupContainer link = newBlobLink("link", change);+ link.add(new Label("label", change.getPath()));+ link.add(AttributeAppender.append("title", change.getHint()));+ item.add(link);+ item.add(AttributeAppender.append("class", " file " + change.getStatus().name().toLowerCase()));+ }++ });+ } else {+ fragment = new Fragment("content", "noChangesFrag", this);+ }+ add(fragment);}protected abstract WebMarkupContainer newBlobLink(String id, Change change);+ @Override+ protected void onDetach() {+ repoModel.detach();++ super.onDetach();+ }+}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/DiffTreePanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/DiffTreePanel.javaindex e240c0eeb0..51f322c22e 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/DiffTreePanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/DiffTreePanel.java@@ -28,20 +28,16 @@ public abstract class DiffTreePanel extends Panel {private final IModel<Repository> repoModel;- private final IModel<List<Change>> changesModel;-private final String fromRev;private final String toRev;private NestedTree<DiffTreeNode> tree;- public DiffTreePanel(String id, IModel<Repository> repoModel, IModel<List<Change>> changesModel,- String fromRev, String toRev) {+ public DiffTreePanel(String id, IModel<Repository> repoModel, String fromRev, String toRev) {super(id);this.repoModel = repoModel;- this.changesModel = changesModel;this.fromRev = fromRev;this.toRev = toRev;}@@ -71,7 +67,8 @@ public abstract class DiffTreePanel extends Panel {@Overridepublic Iterator<? extends DiffTreeNode> getRoots() {List<DiffTreeNode> roots = new ArrayList<>();- for (Change change: repoModel.getObject().git().listTree(fromRev, toRev, null, changesModel.getObject())) {+ List<Change> changes = repoModel.getObject().getChanges(fromRev, toRev);+ for (Change change: repoModel.getObject().git().listTree(fromRev, toRev, null, changes)) {roots.add(new DiffTreeNode(change));}return roots.iterator();@@ -85,8 +82,9 @@ public abstract class DiffTreePanel extends Panel {@Overridepublic Iterator<? extends DiffTreeNode> getChildren(DiffTreeNode node) {List<DiffTreeNode> children = new ArrayList<>();+ List<Change> changes = repoModel.getObject().getChanges(fromRev, toRev);for (Change change: repoModel.getObject().git().listTree(- fromRev, toRev, node.getChange().getPath(), changesModel.getObject())) {+ fromRev, toRev, node.getChange().getPath(), changes)) {children.add(new DiffTreeNode(change));}return children.iterator();@@ -146,7 +144,6 @@ public abstract class DiffTreePanel extends Panel {@Overrideprotected void onDetach() {repoModel.detach();- changesModel.detach();super.onDetach();}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.javaindex f0c3f160e3..2a3edd2ad7 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@@ -10,13 +10,12 @@ import java.util.Date;import java.util.List;import java.util.Map;-import javax.annotation.Nullable;-import org.apache.shiro.SecurityUtils;import org.apache.wicket.ajax.AjaxRequestTarget;import org.apache.wicket.ajax.markup.html.AjaxLink;import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;import org.apache.wicket.behavior.AttributeAppender;+import org.apache.wicket.event.Broadcast;import org.apache.wicket.markup.html.WebMarkupContainer;import org.apache.wicket.markup.html.basic.Label;import org.apache.wicket.markup.html.form.Form;@@ -30,8 +29,6 @@ import org.apache.wicket.model.LoadableDetachableModel;import org.apache.wicket.model.Model;import com.pmease.commons.git.BlobText;-import com.pmease.commons.git.GitUtils;-import com.pmease.commons.git.RevAwareChange;import com.pmease.commons.hibernate.dao.Dao;import com.pmease.commons.util.diff.DiffLine;import com.pmease.commons.util.diff.DiffUtils;@@ -45,7 +42,7 @@ 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.gitplex.core.GitPlex;-import com.pmease.gitplex.core.comment.ChangeComments;+import com.pmease.gitplex.core.comment.CommentAwareChange;import com.pmease.gitplex.core.manager.AuthorizationManager;import com.pmease.gitplex.core.manager.UserManager;import com.pmease.gitplex.core.model.CommentPosition;@@ -58,6 +55,7 @@ import com.pmease.gitplex.web.component.label.AgeLabel;import com.pmease.gitplex.web.component.markdown.MarkdownPanel;import com.pmease.gitplex.web.component.user.AvatarMode;import com.pmease.gitplex.web.component.user.UserLink;+import com.pmease.gitplex.web.event.CommitCommentRemoved;import com.pmease.gitplex.web.model.UserModel;@SuppressWarnings("serial")@@ -79,13 +77,11 @@ public class TextDiffPanel extends Panel {private final IModel<Repository> repoModel;- private final RevAwareChange change;-private final BlobText oldText;private final BlobText newText;- private final ChangeComments comments;+ private final CommentAwareChange change;private final IModel<Boolean> allowToAddCommentModel;@@ -99,22 +95,12 @@ public class TextDiffPanel extends Panel {private List<DiffLine> diffs;- public TextDiffPanel(String id, final IModel<Repository> repoModel, RevAwareChange change,- BlobText oldText, BlobText newText, @Nullable ChangeComments comments) {+ public TextDiffPanel(String id, final IModel<Repository> repoModel, BlobText oldText, BlobText newText,+ CommentAwareChange change) {super(id);this.repoModel = repoModel;- this.comments = comments;-- String oldCommitHash = change.getOldRevision();- if (!GitUtils.isHash(oldCommitHash))- oldCommitHash = repoModel.getObject().git().parseRevision(oldCommitHash, true);- String newCommitHash = change.getNewRevision();- if (!GitUtils.isHash(newCommitHash))- newCommitHash = repoModel.getObject().git().parseRevision(newCommitHash, true);-- this.change = new RevAwareChange(change.getStatus(), change.getOldPath(), change.getNewPath(),- change.getOldMode(), change.getNewMode(), oldCommitHash, newCommitHash);+ this.change= change;this.oldText = oldText;this.newText = newText;@@ -240,7 +226,7 @@ public class TextDiffPanel extends Panel {@Overrideprotected void onConfigure() {super.onConfigure();- setVisible((getOldComments() != null || getNewComments() != null) && showComments);+ setVisible((change.getOldComments() != null || change.getNewComments() != null) && showComments);}}.add(new ScrollBehavior(head, ".comments.line", 50, false)));@@ -250,7 +236,7 @@ public class TextDiffPanel extends Panel {@Overrideprotected void onConfigure() {super.onConfigure();- setVisible((getOldComments() != null || getNewComments() != null) && showComments);+ setVisible((change.getOldComments() != null || change.getNewComments() != null) && showComments);}}.add(new ScrollBehavior(head, ".comments.line", 50, true)));@@ -265,7 +251,7 @@ public class TextDiffPanel extends Panel {@Overrideprotected void onConfigure() {super.onConfigure();- setVisible((getOldComments() != null || getNewComments() != null) && !showComments);+ setVisible((change.getOldComments() != null || change.getNewComments() != null) && !showComments);}});@@ -279,7 +265,7 @@ public class TextDiffPanel extends Panel {@Overrideprotected void onConfigure() {super.onConfigure();- setVisible((getOldComments() != null || getNewComments() != null) && showComments);+ setVisible((change.getOldComments() != null || change.getNewComments() != null) && showComments);}});@@ -435,15 +421,15 @@ public class TextDiffPanel extends Panel {@Overrideprotected List<CommitComment> load() {List<CommitComment> oldLineComments = null;- if (getOldComments() != null)- oldLineComments = getOldComments().get(diffLine.getOldLineNo());+ if (change.getOldComments() != null)+ oldLineComments = change.getOldComments().get(diffLine.getOldLineNo());if (oldLineComments == null)oldLineComments = new ArrayList<>();List<CommitComment> newLineComments = null;- if (getNewComments() != null)- newLineComments = getNewComments().get(diffLine.getNewLineNo());+ if (change.getNewComments() != null)+ newLineComments = change.getNewComments().get(diffLine.getNewLineNo());if (newLineComments == null)newLineComments = new ArrayList<>();@@ -569,23 +555,24 @@ public class TextDiffPanel extends Panel {@Overridepublic void onClick(AjaxRequestTarget target) {GitPlex.getInstance(Dao.class).remove(comment);- if (comments.getOldComments() != null) {- List<CommitComment> lineComments = comments.getOldComments().get(diffLine.getOldLineNo());+ if (change.getOldComments() != null) {+ List<CommitComment> lineComments = change.getOldComments().get(diffLine.getOldLineNo());if (lineComments != null) {lineComments.remove(comment);if (lineComments.isEmpty())- comments.getOldComments().remove(diffLine.getOldLineNo());+ change.getOldComments().remove(diffLine.getOldLineNo());}}- if (comments.getNewComments() != null) {- List<CommitComment> lineComments = comments.getNewComments().get(diffLine.getNewLineNo());+ if (change.getNewComments() != null) {+ List<CommitComment> lineComments = change.getNewComments().get(diffLine.getNewLineNo());if (lineComments != null) {lineComments.remove(comment);if (lineComments.isEmpty())- comments.getOldComments().remove(diffLine.getNewLineNo());+ change.getOldComments().remove(diffLine.getNewLineNo());}}target.add(commentsRow);+ send(getPage(), Broadcast.BUBBLE, new CommitCommentRemoved(target, comment));}@Override@@ -739,7 +726,7 @@ public class TextDiffPanel extends Panel {} else if (diffLine.getAction() == ADD) {commit = change.getNewRevision();position = new CommentPosition(change.getNewPath(), diffLine.getNewLineNo());- } else if (getNewComments() != null) {+ } else if (change.getNewComments() != null) {commit = change.getNewRevision();position = new CommentPosition(change.getNewPath(), diffLine.getNewLineNo());} else {@@ -750,17 +737,17 @@ public class TextDiffPanel extends Panel {comment.setPosition(position);comment.setContent(input.getModelObject());comment.setCommentDate(new Date());- comment.setCommitDate(comments.getCommits().get(commit));+ comment.setCommitDate(change.getCommits().get(commit));GitPlex.getInstance(Dao.class).persist(comment);if (diffLine.getAction() == DELETE)- addToComments(getOldComments(), diffLine.getOldLineNo(), comment);+ addToComments(change.getOldComments(), diffLine.getOldLineNo(), comment);else if (diffLine.getAction() == ADD)- addToComments(getNewComments(), diffLine.getNewLineNo(), comment);- else if (getNewComments() != null)- addToComments(getNewComments(), diffLine.getNewLineNo(), comment);+ addToComments(change.getNewComments(), diffLine.getNewLineNo(), comment);+ else if (change.getNewComments() != null)+ addToComments(change.getNewComments(), diffLine.getNewLineNo(), comment);else- addToComments(getOldComments(), diffLine.getOldLineNo(), comment);+ addToComments(change.getOldComments(), diffLine.getOldLineNo(), comment);commentsRow.replace(new WebMarkupContainer(NEW_COMMENT_ID));target.add(commentsRow);@@ -796,30 +783,16 @@ public class TextDiffPanel extends Panel {} else {DiffLine.Action action = item.getModelObject().getAction();if (action == DELETE)- setVisible(getOldComments() != null);+ setVisible(change.getOldComments() != null);else if (action == ADD)- setVisible(getNewComments() != null);+ setVisible(change.getNewComments() != null);else- setVisible(getOldComments() != null || getNewComments() != null);+ setVisible(change.getOldComments() != null || change.getNewComments() != null);}}}- private Map<Integer, List<CommitComment>> getOldComments() {- if (comments != null)- return comments.getOldComments();- else- return null;- }-- private Map<Integer, List<CommitComment>> getNewComments() {- if (comments != null)- return comments.getNewComments();- else- return null;- }-@Overrideprotected void onDetach() {repoModel.detach();diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/event/CommitCommentRemoved.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/event/CommitCommentRemoved.javanew file mode 100644index 0000000000..1dcd8f2211--- /dev/null+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/event/CommitCommentRemoved.java@@ -0,0 +1,22 @@+package com.pmease.gitplex.web.event;++import org.apache.wicket.ajax.AjaxRequestTarget;++import com.pmease.gitplex.core.model.CommitComment;+import com.pmease.gitplex.web.common.wicket.event.AjaxEvent;++public class CommitCommentRemoved extends AjaxEvent {++ private final CommitComment comment;++ public CommitCommentRemoved(AjaxRequestTarget target, CommitComment comment) {+ super(target);++ this.comment = comment;+ }++ public CommitComment getComment() {+ return comment;+ }++}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestComparePage.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestComparePage.htmlindex 1e9b9ce986..da48f30268 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestComparePage.html+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestComparePage.html@@ -1,30 +1,22 @@<wicket:extend><div class="compare">- <div class="head clearfix">- <div wicket:id="commentActions" class="comment pull-left btn-group">- <button wicket:id="prev" class="btn btn-default" title="Previous commented line in this pull request">- <i class="fa fa-arrow-left"></i>- </button>- <button wicket:id="current" class="btn">- <i class="fa fa-comments"></i> <span wicket:id="label"></span>- </button>- <button wicket:id="next" class="btn btn-default" title="Next commented line in this pull request">- <i class="fa fa-arrow-right"></i>- </button>- </div>- <div class="original pull-left">+ <div wicket:id="compareHead" class="head clearfix">+ <button wicket:id="locateComment" class="comment btn pull-left">+ <i class="fa fa-comments"></i> <span wicket:id="label"></span>+ </button>+ <div class="old pull-left"><label>Original:</label>- <span class="btn btn-default" wicket:id="originalSelector">+ <span class="btn btn-default" wicket:id="oldSelector"><i class="fa fa-commit"></i> <span wicket:id="label"></span> <i class="caret"></i></span>- <div wicket:id="originalChoices"></div>+ <div wicket:id="oldChoices"></div></div>- <div class="revised pull-left">+ <div class="new pull-left"><label>Revised:</label>- <span class="btn btn-default" wicket:id="revisedSelector">+ <span class="btn btn-default" wicket:id="newSelector"><i class="fa fa-commit"></i> <span wicket:id="label"></span> <i class="caret"></i></span>- <div wicket:id="revisedChoices"></div>+ <div wicket:id="newChoices"></div></div></div><table class="body">@@ -32,7 +24,7 @@<td class="nav"><div class="panel panel-default"><div class="panel-heading">- <span class="panel-title">Compare Result</span> <input wicket:id="changedOnly" type="checkbox"> changed only</input>+ <span class="panel-title">Compare Result</span> <input wicket:id="changesOnly" type="checkbox"> changes only</input></div><div wicket:id="compareResult" class="panel-body"></div></div>diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestComparePage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestComparePage.javaindex 1f445ae814..dbd27d03d2 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestComparePage.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestComparePage.java@@ -17,6 +17,8 @@ import org.apache.wicket.Component;import org.apache.wicket.ajax.AjaxRequestTarget;import org.apache.wicket.ajax.form.OnChangeAjaxBehavior;import org.apache.wicket.ajax.markup.html.AjaxLink;+import org.apache.wicket.behavior.AttributeAppender;+import org.apache.wicket.event.IEvent;import org.apache.wicket.markup.ComponentTag;import org.apache.wicket.markup.head.IHeaderResponse;import org.apache.wicket.markup.head.OnDomReadyHeaderItem;@@ -27,9 +29,9 @@ import org.apache.wicket.markup.html.link.Link;import org.apache.wicket.markup.html.list.ListItem;import org.apache.wicket.markup.html.list.ListView;import org.apache.wicket.markup.html.panel.Fragment;+import org.apache.wicket.model.AbstractReadOnlyModel;import org.apache.wicket.model.IModel;import org.apache.wicket.model.LoadableDetachableModel;-import org.apache.wicket.model.PropertyModel;import org.apache.wicket.request.mapper.parameter.PageParameters;import org.eclipse.jgit.lib.FileMode;@@ -47,7 +49,7 @@ import com.pmease.commons.wicket.behavior.dropdown.DropdownBehavior;import com.pmease.commons.wicket.behavior.dropdown.DropdownPanel;import com.pmease.gitplex.core.GitPlex;import com.pmease.gitplex.core.comment.BlobLoader;-import com.pmease.gitplex.core.comment.ChangeComments;+import com.pmease.gitplex.core.comment.CommentAwareChange;import com.pmease.gitplex.core.comment.CommentLoader;import com.pmease.gitplex.core.model.CommitComment;import com.pmease.gitplex.core.model.IntegrationInfo;@@ -56,20 +58,27 @@ import com.pmease.gitplex.core.model.PullRequestUpdate;import com.pmease.gitplex.web.component.diff.BlobDiffPanel;import com.pmease.gitplex.web.component.diff.ChangedFilesPanel;import com.pmease.gitplex.web.component.diff.DiffTreePanel;+import com.pmease.gitplex.web.event.CommitCommentRemoved;@SuppressWarnings("serial")public class RequestComparePage extends RequestDetailPage {- private String originalCommit;+ private static final String HEAD_ID = "compareHead";- private String revisedCommit;+ private static final String LOCATE_COMMENT_ID = "locateComment";++ private static final String COMPARE_RESULT_ID = "compareResult";++ private static final String BLOB_DIFF_ID = "blobDiff";++ private String oldCommit;++ private String newCommit;private String filePath;private Long commentId;- private boolean changedOnly = true;-private IModel<CommitComment> commentModel = new LoadableDetachableModel<CommitComment>() {@Override@@ -80,7 +89,6 @@ public class RequestComparePage extends RequestDetailPage {};- // map commit name to comit hashprivate IModel<Map<String, CommitDescription>> commitsModel =new LoadableDetachableModel<Map<String, CommitDescription>>() {@@ -88,8 +96,17 @@ public class RequestComparePage extends RequestDetailPage {protected LinkedHashMap<String, CommitDescription> load() {LinkedHashMap<String, CommitDescription> choices = new LinkedHashMap<>();PullRequest request = getPullRequest();-- CommitDescription description = new CommitDescription("Base of Pull Request",++ String concernedCommit;+ if (commentId != null)+ concernedCommit = commentModel.getObject().getCommit();+ else+ concernedCommit = null;++ String name = "Base of Pull Request";+ if (request.getBaseCommit().equals(concernedCommit))+ name += " - Concerned";+ CommitDescription description = new CommitDescription(name,getRepository().git().showRevision(request.getBaseCommit()).getSubject());choices.put(request.getBaseCommit(), description);@@ -98,10 +115,17 @@ public class RequestComparePage extends RequestDetailPage {int updateNo = request.getSortedUpdates().size()-i;int j = 0;for (Commit commit: update.getCommits()) {- if (j == update.getCommits().size()-1)- description = new CommitDescription("Head of Update #" + updateNo, commit.getSubject());- else- description = new CommitDescription(null, commit.getSubject());+ if (j == update.getCommits().size()-1) {+ name = "Head of Update #" + updateNo;+ if (commit.getHash().equals(concernedCommit))+ name += " - Concerned";+ description = new CommitDescription(name, commit.getSubject());+ } else {+ if (commit.getHash().equals(concernedCommit))+ description = new CommitDescription("Concerned", commit.getSubject());+ else+ description = new CommitDescription(null, commit.getSubject());+ }j++;choices.put(commit.getHash(), description);}@@ -128,38 +152,29 @@ public class RequestComparePage extends RequestDetailPage {};- private IModel<List<Change>> changesModel = new LoadableDetachableModel<List<Change>>() {-- @Override- protected List<Change> load() {- return getRepository().git().listFileChanges(originalCommit, revisedCommit, null, true);- }-- };-public RequestComparePage(PageParameters params) {super(params);filePath = params.get("path").toString();- commentId = params.get("comment").toLongObject();+ commentId = params.get("comment").toOptionalLong();- originalCommit = params.get("original").toString();- revisedCommit = params.get("revised").toString();+ oldCommit = params.get("original").toString();+ newCommit = params.get("revised").toString();- if (!(originalCommit == null && revisedCommit == null || originalCommit != null && revisedCommit != null))+ if (!(oldCommit == null && newCommit == null || oldCommit != null && newCommit != null))throw new IllegalArgumentException("Param 'original' and 'revised' should be specified both or none.");- if (originalCommit != null) {- if (!commitsModel.getObject().containsKey(originalCommit))- throw new IllegalArgumentException("Commit '" + originalCommit + "' is not relevant to current pull request.");+ if (oldCommit != null) {+ if (!commitsModel.getObject().containsKey(oldCommit))+ throw new IllegalArgumentException("Commit '" + oldCommit + "' is not relevant to current pull request.");}- if (revisedCommit != null) {- if (!commitsModel.getObject().containsKey(revisedCommit))- throw new IllegalArgumentException("Commit '" + revisedCommit + "' is not relevant to current pull request.");+ if (newCommit != null) {+ if (!commitsModel.getObject().containsKey(newCommit))+ throw new IllegalArgumentException("Commit '" + newCommit + "' is not relevant to current pull request.");}- if (filePath != null && originalCommit == null)+ if (filePath != null && oldCommit == null)throw new IllegalArgumentException("Param 'path' can only be used together with param 'original' and 'revised'.");}@@ -167,26 +182,92 @@ public class RequestComparePage extends RequestDetailPage {protected void onInitialize() {super.onInitialize();- WebMarkupContainer commentActions = new WebMarkupContainer("commentActions");- commentActions.setOutputMarkupId(true);- add(commentActions);-- WebMarkupContainer baseSelector = new WebMarkupContainer("originalSelector");- add(baseSelector);- baseSelector.add(new Label("label", new LoadableDetachableModel<String>() {+ WebMarkupContainer head = new WebMarkupContainer(HEAD_ID);+ head.setOutputMarkupId(true);+ add(head);++ AjaxLink<Void> link = new AjaxLink<Void>(LOCATE_COMMENT_ID) {++ @Override+ public void onClick(AjaxRequestTarget target) {+ filePath = null;+ CommitComment comment = commentModel.getObject();+ CommentAwareChange change = getActiveChange();+ if (change == null || !change.contains(comment)) {+ change = locateChange(comment);+ if (change != null) {+ Component compareResult = newCompareResult(change.getStatus() != UNCHANGED);+ getPage().replace(compareResult);+ target.add(compareResult);++ BlobDiffPanel diffPanel = new BlobDiffPanel(BLOB_DIFF_ID, repoModel, change, -1);+ getPage().replace(diffPanel);+ target.add(diffPanel);++ target.add(this);+ } else {+ PageParameters params = params4(getPullRequest(), null, null, null, commentId);+ setResponsePage(RequestComparePage.class, params);+ }+ }+ }++ @Override+ protected void onConfigure() {+ super.onConfigure();++ setVisible(commentId != null);+ }++ };+ link.add(new Label("label", new AbstractReadOnlyModel<String>() {++ @Override+ public String getObject() {+ Component panel = getPage().get(BLOB_DIFF_ID);+ if (panel instanceof BlobDiffPanel) {+ CommentAwareChange change = ((BlobDiffPanel) panel).getChange();+ if (change.contains(commentModel.getObject()))+ return "Displaying concerned comment line by comparing";+ }++ return "Click to display concerned comment line";+ }++ }));+ link.add(AttributeAppender.append("class", new AbstractReadOnlyModel<String>() {++ @Override+ public String getObject() {+ Component panel = getPage().get(BLOB_DIFF_ID);+ if (panel instanceof BlobDiffPanel) {+ CommentAwareChange change = ((BlobDiffPanel) panel).getChange();+ if (change.contains(commentModel.getObject()))+ return "btn-default";+ }++ return "btn-warning";+ }++ }));+ head.add(link);++ WebMarkupContainer oldSelector = new WebMarkupContainer("oldSelector");+ head.add(oldSelector);+ oldSelector.add(new Label("label", new LoadableDetachableModel<String>() {@Overrideprotected String load() {- CommitDescription description = commitsModel.getObject().get(originalCommit);+ CommitDescription description = commitsModel.getObject().get(oldCommit);Preconditions.checkNotNull(description);if (description.getName() != null)- return GitUtils.abbreviateSHA(originalCommit) + " - " + description.getName();+ return GitUtils.abbreviateSHA(oldCommit) + " - " + description.getName();else- return GitUtils.abbreviateSHA(originalCommit);+ return GitUtils.abbreviateSHA(oldCommit);}}));- DropdownPanel baseChoicesDropdown = new DropdownPanel("originalChoices", false) {+ DropdownPanel oldChoicesDropdown = new DropdownPanel("oldChoices", false) {@Overrideprotected Component newContent(String id) {@@ -194,36 +275,37 @@ public class RequestComparePage extends RequestDetailPage {}};- add(baseChoicesDropdown);- baseSelector.add(new DropdownBehavior(baseChoicesDropdown).alignWithTrigger(0, 0, 0, 100));+ head.add(oldChoicesDropdown);+ oldSelector.add(new DropdownBehavior(oldChoicesDropdown).alignWithTrigger(0, 0, 0, 100));- baseSelector.add(new TooltipBehavior(new LoadableDetachableModel<String>() {+ oldSelector.add(new TooltipBehavior(new LoadableDetachableModel<String>() {@Overrideprotected String load() {- CommitDescription description = commitsModel.getObject().get(originalCommit);+ CommitDescription description = commitsModel.getObject().get(oldCommit);Preconditions.checkNotNull(description);return description.getSubject();}}));- WebMarkupContainer headSelector = new WebMarkupContainer("revisedSelector");- add(headSelector);- headSelector.add(new Label("label", new LoadableDetachableModel<String>() {+ WebMarkupContainer newSelector = new WebMarkupContainer("newSelector");+ head.add(newSelector);+ newSelector.add(new Label("label", new LoadableDetachableModel<String>() {@Overrideprotected String load() {- CommitDescription description = commitsModel.getObject().get(revisedCommit);+ CommitDescription description = commitsModel.getObject().get(newCommit);Preconditions.checkNotNull(description);+if (description.getName() != null)- return GitUtils.abbreviateSHA(revisedCommit) + " - " + description.getName();+ return GitUtils.abbreviateSHA(newCommit) + " - " + description.getName();else- return GitUtils.abbreviateSHA(revisedCommit);+ return GitUtils.abbreviateSHA(newCommit);}}));- DropdownPanel headChoicesDropdown = new DropdownPanel("revisedChoices", false) {+ DropdownPanel newChoicesDropdown = new DropdownPanel("newChoices", false) {@Overrideprotected Component newContent(String id) {@@ -231,96 +313,132 @@ public class RequestComparePage extends RequestDetailPage {}};- add(headChoicesDropdown);- headSelector.add(new DropdownBehavior(headChoicesDropdown).alignWithTrigger(0, 0, 0, 100));+ head.add(newChoicesDropdown);+ newSelector.add(new DropdownBehavior(newChoicesDropdown).alignWithTrigger(0, 0, 0, 100));- headSelector.add(new TooltipBehavior(new LoadableDetachableModel<String>() {+ newSelector.add(new TooltipBehavior(new LoadableDetachableModel<String>() {@Overrideprotected String load() {- CommitDescription description = commitsModel.getObject().get(revisedCommit);+ CommitDescription description = commitsModel.getObject().get(newCommit);Preconditions.checkNotNull(description);return description.getSubject();}}));- add(new CheckBox("changedOnly", new PropertyModel<Boolean>(this, "changedOnly"))- .add(new OnChangeAjaxBehavior() {+ add(new CheckBox("changesOnly").add(new OnChangeAjaxBehavior() {- @Override- protected void onUpdate(AjaxRequestTarget target) {- Component compareResult = newCompareResultComponent();- RequestComparePage.this.replace(compareResult);- target.add(compareResult);- }-- }));-- int lineNo = -1;- ChangeComments comments = null;- RevAwareChange change = null;- if (originalCommit != null) {- List<Change> changes = changesModel.getObject();- if (filePath != null) {- for (Change each: changes) {- if (filePath.equals(each.getOldPath()) || filePath.equals(each.getNewPath())) {- change = new RevAwareChange(each, originalCommit, revisedCommit);- break;- }- }- if (change == null) {- List<TreeNode> result = getRepository().git().listTree(revisedCommit, filePath);- if (!result.isEmpty() && result.get(0).getMode() != FileMode.TYPE_TREE) {- TreeNode blobNode = result.get(0);- change = new RevAwareChange(UNCHANGED, filePath, filePath,- blobNode.getMode(), blobNode.getMode(), originalCommit, revisedCommit);- changedOnly = false;- }- }- } else {- if (commentId != null) {- CommitComment comment = commentModel.getObject();- }- if (change == null && !changes.isEmpty())- change = new RevAwareChange(changes.get(0), originalCommit, revisedCommit);+ @Override+ protected void onUpdate(AjaxRequestTarget target) {+ Component compareResult = getPage().get(COMPARE_RESULT_ID);+ compareResult = newCompareResult(!(compareResult instanceof ChangedFilesPanel));+ RequestComparePage.this.replace(compareResult);+ target.add(compareResult);}- } else if (commentId == null) {- originalCommit = getPullRequest().getBaseCommit();- revisedCommit = getPullRequest().getLatestUpdate().getHeadCommit();- } else {- }+ }));+ CommentAwareChange change = locateChange();if (change != null) {- BlobDiffPanel blobDiffPanel = new BlobDiffPanel("blobDiff", repoModel,- change, loadComments(change), lineNo);+ BlobDiffPanel blobDiffPanel = new BlobDiffPanel(BLOB_DIFF_ID, repoModel, change, -1);blobDiffPanel.setOutputMarkupId(true);add(blobDiffPanel);} else {- add(new WebMarkupContainer("blobDiff").setOutputMarkupId(true));+ add(new WebMarkupContainer(BLOB_DIFF_ID).setOutputMarkupId(true));}- add(newCompareResultComponent());+ add(newCompareResult(change == null || change.getStatus() != UNCHANGED));}- private Component newCompareResultComponent() {- Component compareResult;- if (changedOnly) {- if (!changesModel.getObject().isEmpty()) {- compareResult = new ChangedFilesPanel("compareResult", changesModel) {-- @Override- protected WebMarkupContainer newBlobLink(String id, Change change) {- return new BlobLink(id, change);- }- };+ private CommentAwareChange locateChange() {+ CommentAwareChange change = null;+ if (oldCommit != null) {+ if (filePath != null) {+ change = locateChange(filePath);} else {- compareResult = new Label("compareResult", "<i class='fa fa-info-circle'></i> <em>Nothing changed</em>");- compareResult.setEscapeModelStrings(false);+ if (commentId != null)+ change = locateChange(commentModel.getObject());+ if (change == null) {+ List<Change> changes = getRepository().getChanges(oldCommit, newCommit);+ if (!changes.isEmpty())+ change = loadComments(new RevAwareChange(changes.get(0), oldCommit, newCommit));+ }}+ } else if (commentId == null) {+ oldCommit = getPullRequest().getBaseCommit();+ newCommit = getPullRequest().getLatestUpdate().getHeadCommit();+ List<Change> changes = getRepository().getChanges(oldCommit, newCommit);+ if (!changes.isEmpty())+ change = loadComments(new RevAwareChange(changes.get(0), oldCommit, newCommit));} else {- compareResult = new DiffTreePanel("compareResult", repoModel, changesModel, originalCommit, revisedCommit) {+ CommitComment comment = commentModel.getObject();+ oldCommit = getPullRequest().getBaseCommit();+ newCommit = getPullRequest().getLatestUpdate().getHeadCommit();+ change = locateChange(comment);+ if (change == null) {+ oldCommit = comment.getCommit();+ newCommit = getPullRequest().getLatestUpdate().getHeadCommit();+ change = locateChange(comment);+ Preconditions.checkNotNull(change);+ }+ }++ return change;+ }++ private CommentAwareChange locateChange(CommitComment comment) {+ String path = comment.getPosition().getFilePath();+ for (Change each: getRepository().getChanges(oldCommit, newCommit)) {+ if (path.equals(each.getPath())) {+ CommentAwareChange change = loadComments(new RevAwareChange(each, oldCommit, newCommit));+ if (change.contains(comment))+ return change;+ else+ return null;+ }+ }+ List<TreeNode> nodes = getRepository().git().listTree(newCommit, comment.getPosition().getFilePath());+ if (!nodes.isEmpty() && nodes.get(0).getMode() != FileMode.TYPE_TREE) {+ RevAwareChange change = new RevAwareChange(UNCHANGED, path, path,+ nodes.get(0).getMode(), nodes.get(0).getMode(), oldCommit, newCommit);+ CommentAwareChange commentAwareChange = loadComments(change);+ if (commentAwareChange.contains(comment))+ return commentAwareChange;+ else+ return null;+ } else {+ return null;+ }+ }++ private CommentAwareChange locateChange(String filePath) {+ for (Change each: getRepository().getChanges(oldCommit, newCommit)) {+ if (filePath.equals(each.getPath()))+ return loadComments(new RevAwareChange(each, oldCommit, newCommit));+ }+ List<TreeNode> result = getRepository().git().listTree(newCommit, filePath);+ if (!result.isEmpty() && result.get(0).getMode() != FileMode.TYPE_TREE) {+ TreeNode blobNode = result.get(0);+ return loadComments(new RevAwareChange(UNCHANGED, filePath, filePath,+ blobNode.getMode(), blobNode.getMode(), oldCommit, newCommit));+ } else {+ return null;+ }+ }++ private Component newCompareResult(boolean changesOnly) {+ Component compareResult;+ if (changesOnly) {+ compareResult = new ChangedFilesPanel(COMPARE_RESULT_ID, repoModel, oldCommit, newCommit) {++ @Override+ protected WebMarkupContainer newBlobLink(String id, Change change) {+ return new BlobLink(id, change);+ }+ };+ } else {+ compareResult = new DiffTreePanel(COMPARE_RESULT_ID, repoModel, oldCommit, newCommit) {@Overrideprotected WebMarkupContainer newBlobLink(String id, final Change change) {@@ -342,8 +460,9 @@ public class RequestComparePage extends RequestDetailPage {return compareResult;}- private RevAwareChange getActiveChange() {- Component panel = getPage().get("blobDiff");+ @Nullable+ private CommentAwareChange getActiveChange() {+ Component panel = getPage().get(BLOB_DIFF_ID);if (panel instanceof BlobDiffPanel)return ((BlobDiffPanel) panel).getChange();else@@ -353,13 +472,12 @@ public class RequestComparePage extends RequestDetailPage {@Overridepublic void onDetach() {commitsModel.detach();- changesModel.detach();commentModel.detach();super.onDetach();}- private ChangeComments loadComments(RevAwareChange change) {+ private CommentAwareChange loadComments(RevAwareChange change) {BlobLoader blobLoader = new BlobLoader() {@Override@@ -389,17 +507,17 @@ public class RequestComparePage extends RequestDetailPage {commits.put(commit.getHash(), commit.getCommitter().getWhen());}- return new ChangeComments(change, commits, commentLoader, blobLoader);+ return new CommentAwareChange(change, commits, commentLoader, blobLoader);}-- public static PageParameters params4(PullRequest request, @Nullable String originalCommit,- @Nullable String revisedCommit, @Nullable String filePath, @Nullable Long commentId) {++ public static PageParameters params4(PullRequest request, @Nullable String oldCommit,+ @Nullable String newCommit, @Nullable String filePath, @Nullable Long commentId) {PageParameters params = RequestDetailPage.params4(request);- if (originalCommit != null)- params.set("original", originalCommit);- if (revisedCommit != null)- params.set("revised", revisedCommit);+ if (oldCommit != null)+ params.set("original", oldCommit);+ if (newCommit != null)+ params.set("revised", newCommit);if (filePath != null)params.set("path", filePath);if (commentId != null)@@ -466,18 +584,31 @@ public class RequestComparePage extends RequestDetailPage {Map.Entry<String, CommitDescription> entry = item.getModelObject();if (forBase) {setResponsePage(RequestComparePage.class,- params4(getPullRequest(), entry.getKey(), revisedCommit, filePath, commentId));+ params4(getPullRequest(), entry.getKey(), newCommit, filePath, commentId));} else {setResponsePage(RequestComparePage.class,- params4(getPullRequest(), originalCommit, entry.getKey(), filePath, commentId));+ params4(getPullRequest(), oldCommit, entry.getKey(), filePath, commentId));}}};Map.Entry<String, CommitDescription> entry = item.getModelObject();String label = GitUtils.abbreviateSHA(entry.getKey());- if (entry.getValue().getName() != null)- label += " - " + entry.getValue().getName();+ String name = entry.getValue().getName();+ if (name != null) {+ label += " - " + name;+ name = name.toLowerCase();+ if (name.contains("base of "))+ item.add(AttributeAppender.append("class", " base special"));+ if (name.contains("concerned"))+ item.add(AttributeAppender.append("class", " concerned special"));+ if (name.contains("head of update"))+ item.add(AttributeAppender.append("class", " update-head special"));+ if (name.contains("integration preview"))+ item.add(AttributeAppender.append("class", " integration-preview special"));+ if (name.contains("head of target"))+ item.add(AttributeAppender.append("class", " target-head special"));+ }link.add(new Label("label", label));if (entry.getValue().getSubject() != null)link.add(new Label("subject", entry.getValue().getSubject()));@@ -527,21 +658,38 @@ public class RequestComparePage extends RequestDetailPage {@Overridepublic void onClick(AjaxRequestTarget target) {filePath = change.getPath();+ RevAwareChange revAwareChange = new RevAwareChange(change, oldCommit, newCommit);++ BlobDiffPanel diffPanel = new BlobDiffPanel(BLOB_DIFF_ID, repoModel,+ loadComments(revAwareChange), -1);+ getPage().replace(diffPanel);+ target.add(diffPanel);- RevAwareChange revAwareChange = new RevAwareChange(change, originalCommit, revisedCommit);- BlobDiffPanel panel = new BlobDiffPanel("blobDiff", repoModel,- revAwareChange, loadComments(revAwareChange), -1);- panel.setOutputMarkupId(true);- RequestComparePage.this.replace(panel);-- Component compareResult = getPage().get("compareResult");- String script = String.format("$('#%s').find('a.active').removeClass('active');", compareResult.getMarkupId());+ Component compareResult = getPage().get(COMPARE_RESULT_ID);+ String script = String.format("$('#%s').find('a.active').removeClass('active');",+ compareResult.getMarkupId());target.prependJavaScript(script);- target.add(panel);target.add(this);- target.add(getPage().get("commentActions"));++ if (commentId != null)+ target.add(getPage().get(HEAD_ID).get(LOCATE_COMMENT_ID));}}++ @Override+ public void onEvent(IEvent<?> event) {+ super.onEvent(event);++ if (event instanceof CommitCommentRemoved) {+ CommitCommentRemoved commitCommentRemoved = (CommitCommentRemoved) event;+ CommitComment comment = commitCommentRemoved.getComment();+ if (comment.getId().equals(commentId)) {+ commentId = null;+ commitCommentRemoved.getTarget().add(get(HEAD_ID));+ }+ }+ }+}