Skip to content

The Unified and Autonomous Development Platform

midwork

robin shinefbeb0d5f2c92
diff --git a/commons.git/src/main/java/com/pmease/commons/git/BlobChange.java b/commons.git/src/main/java/com/pmease/commons/git/BlobChange.java
index 83634657e8..d872a6c45d 100644
--- a/commons.git/src/main/java/com/pmease/commons/git/BlobChange.java
+++ b/commons.git/src/main/java/com/pmease/commons/git/BlobChange.java
@@ -8,7 +8,6 @@ import javax.annotation.Nullable;
import org.eclipse.jgit.diff.DiffEntry;
import org.eclipse.jgit.diff.DiffEntry.ChangeType;
-import org.eclipse.jgit.lib.AnyObjectId;
import com.google.common.base.Preconditions;
import com.pmease.commons.lang.diff.DiffBlock;
@@ -19,30 +18,18 @@ import com.pmease.commons.lang.tokenizers.CmToken;
@SuppressWarnings("serial")
public abstract class BlobChange implements Serializable {
- private final ChangeType type;
+ protected final ChangeType type;
- private final BlobIdent oldBlobIdent;
+ protected final BlobIdent oldBlobIdent;
- private final BlobIdent newBlobIdent;
+ protected final BlobIdent newBlobIdent;
private transient List<DiffBlock<List<CmToken>>> diffBlocks;
public BlobChange(String oldCommitHash, String newCommitHash, DiffEntry diffEntry) {
type = diffEntry.getChangeType();
- if (type != ChangeType.DELETE) {
- newBlobIdent = new BlobIdent(newCommitHash, diffEntry.getNewPath(), diffEntry.getNewMode().getBits());
- AnyObjectId id = diffEntry.getNewId().toObjectId();
- newBlobIdent.id = id!=null?id.name():null;
- } else {
- newBlobIdent = new BlobIdent(newCommitHash, null, null);
- }
- if (type != ChangeType.ADD) {
- oldBlobIdent = new BlobIdent(oldCommitHash, diffEntry.getOldPath(), diffEntry.getOldMode().getBits());
- AnyObjectId id = diffEntry.getOldId().toObjectId();
- oldBlobIdent.id = id!=null?id.name():null;
- } else {
- oldBlobIdent = new BlobIdent(oldCommitHash, null, null);
- }
+ oldBlobIdent = GitUtils.getOldBlobIdent(diffEntry, oldCommitHash);
+ newBlobIdent = GitUtils.getNewBlobIdent(diffEntry, newCommitHash);
}
public ChangeType getType() {
@@ -61,6 +48,10 @@ public abstract class BlobChange implements Serializable {
return newBlobIdent.path!=null? newBlobIdent: oldBlobIdent;
}
+ public String getPath() {
+ return newBlobIdent.path != null? newBlobIdent.path: oldBlobIdent.path;
+ }
+
public List<DiffBlock<List<CmToken>>> getDiffBlocks() {
if (diffBlocks == null) {
try {
@@ -127,10 +118,6 @@ public abstract class BlobChange implements Serializable {
return deletions;
}
- public String getPath() {
- return newBlobIdent.path != null? newBlobIdent.path: oldBlobIdent.path;
- }
-
public Blob getOldBlob() {
Preconditions.checkNotNull(oldBlobIdent.path);
return getBlob(oldBlobIdent);
diff --git a/commons.git/src/main/java/com/pmease/commons/git/Change.java b/commons.git/src/main/java/com/pmease/commons/git/Change.java
deleted file mode 100644
index a7bd5350ec..0000000000
--- a/commons.git/src/main/java/com/pmease/commons/git/Change.java
+++ /dev/null
@@ -1,133 +0,0 @@
-package com.pmease.commons.git;
-
-import static com.pmease.commons.git.Change.Status.RENAMED;
-
-import java.io.Serializable;
-import java.util.StringTokenizer;
-
-import org.eclipse.jgit.lib.FileMode;
-import org.eclipse.jgit.util.QuotedString;
-
-import com.google.common.base.Preconditions;
-import com.pmease.commons.util.StringUtils;
-import com.pmease.commons.util.WordUtils;
-
-@SuppressWarnings("serial")
-public class Change implements Comparable<Change>, Serializable {
-
- public enum Status {ADDED, MODIFIED, DELETED, RENAMED, UNCHANGED}
-
- private final Status status;
-
- private final BlobIdent oldBlobIdent;
-
- private final BlobIdent newBlobIdent;
-
- public Change(Status status, BlobIdent oldBlobIdent, BlobIdent newBlobIdent) {
- this.status = status;
- this.oldBlobIdent = oldBlobIdent;
- this.newBlobIdent = newBlobIdent;
- }
-
- public Status getStatus() {
- return status;
- }
-
- public BlobIdent getOldBlobIdent() {
- return oldBlobIdent;
- }
-
- public BlobIdent getNewBlobIdent() {
- return newBlobIdent;
- }
-
- @Override
- public String toString() {
- if (status == Status.RENAMED)
- return status.name() + "\t" + oldBlobIdent.path + "->" + newBlobIdent.path;
- else if (status == Status.DELETED)
- return status.name() + "\t" + oldBlobIdent.path;
- else
- return status.name() + "\t" + newBlobIdent.path;
- }
-
- public boolean isFolder() {
- return oldBlobIdent.mode == FileMode.TYPE_TREE || newBlobIdent.mode == FileMode.TYPE_TREE;
- }
-
- @Override
- public int compareTo(Change other) {
- if (isFolder()) {
- if (other.isFolder())
- return getPath().compareTo(other.getPath());
- else
- return -1;
- } else if (other.isFolder()) {
- return 1;
- } else {
- return getPath().compareTo(other.getPath());
- }
- }
-
- public String getPath() {
- if (status == Status.DELETED)
- return oldBlobIdent.path;
- else
- return newBlobIdent.path;
- }
-
- private static String dequoteFileName(String quotedFileName) {
- return QuotedString.GIT_PATH.dequote(quotedFileName);
- }
-
- public static Change parseRawLine(String oldRev, String newRev, String rawLine) {
- Preconditions.checkArgument(rawLine.startsWith(":"));
-
- StringTokenizer tokenizer = new StringTokenizer(rawLine.substring(1));
- int oldMode = Integer.parseInt(tokenizer.nextToken(), 8);
- int newMode = Integer.parseInt(tokenizer.nextToken(), 8);
- tokenizer.nextToken();
- tokenizer.nextToken();
- String statusCode = tokenizer.nextToken();
- if (statusCode.startsWith("R")) {
- String oldPath = dequoteFileName(tokenizer.nextToken("\t"));
- String newPath = dequoteFileName(tokenizer.nextToken("\t"));
- BlobIdent oldBlobIdent = new BlobIdent(oldRev, oldPath, oldMode);
- BlobIdent newBlobIdent = new BlobIdent(newRev, newPath, newMode);
- return new Change(Change.Status.RENAMED, oldBlobIdent, newBlobIdent);
- } else if (statusCode.equals("M") || statusCode.equals("T")) {
- String oldPath, newPath;
- oldPath = newPath = dequoteFileName(tokenizer.nextToken("\t"));
- BlobIdent oldBlobIdent = new BlobIdent(oldRev, oldPath, oldMode);
- BlobIdent newBlobIdent = new BlobIdent(newRev, newPath, newMode);
- return new Change(Change.Status.MODIFIED, oldBlobIdent, newBlobIdent);
- } else if (statusCode.equals("D")) {
- String oldPath = dequoteFileName(tokenizer.nextToken("\t"));
- BlobIdent oldBlobIdent = new BlobIdent(oldRev, oldPath, oldMode);
- BlobIdent newBlobIdent = new BlobIdent(newRev, null, newMode);
- return new Change(Change.Status.DELETED, oldBlobIdent, newBlobIdent);
- } else if (statusCode.equals("A")) {
- String newPath = dequoteFileName(tokenizer.nextToken("\t"));
- BlobIdent oldBlobIdent = new BlobIdent(oldRev, null, oldMode);
- BlobIdent newBlobIdent = new BlobIdent(newRev, newPath, newMode);
- return new Change(Change.Status.ADDED, oldBlobIdent, newBlobIdent);
- } else {
- throw new RuntimeException("Unexpected status code: " + statusCode);
- }
- }
-
- public String getHint() {
- if (getStatus() == RENAMED)
- return "Renamed from " + oldBlobIdent.path;
- else
- return WordUtils.capitalize(getStatus().name().toLowerCase());
- }
-
- public String getName() {
- if (getPath().contains("/"))
- return StringUtils.substringAfterLast(getPath(), "/");
- else
- return getPath();
- }
-
-}
diff --git a/commons.git/src/main/java/com/pmease/commons/git/Git.java b/commons.git/src/main/java/com/pmease/commons/git/Git.java
index cf3816aa20..b09fbc9236 100644
--- a/commons.git/src/main/java/com/pmease/commons/git/Git.java
+++ b/commons.git/src/main/java/com/pmease/commons/git/Git.java
@@ -30,7 +30,6 @@ import com.pmease.commons.git.command.IsTreeLinkCommand;
import com.pmease.commons.git.command.ListBranchCommand;
import com.pmease.commons.git.command.ListChangedFilesCommand;
import com.pmease.commons.git.command.ListCherriesCommand;
-import com.pmease.commons.git.command.ListFileChangesCommand;
import com.pmease.commons.git.command.ListHeadCommitCommand;
import com.pmease.commons.git.command.ListSubModulesCommand;
import com.pmease.commons.git.command.ListTagsCommand;
@@ -164,12 +163,6 @@ public class Git implements Serializable {
return new ListChangedFilesCommand(repoDir).fromRev(fromRev).toRev(toRev).path(path).call();
}
- public List<Change> listFileChanges(String fromRev, String toRev, @Nullable String path,
- boolean findRenames) {
- return new ListFileChangesCommand(repoDir).fromRev(fromRev).toRev(toRev).path(path)
- .findRenames(findRenames).call();
- }
-
public Git checkout(String revision, @Nullable String newBranch) {
new CheckoutCommand(repoDir).revision(revision).newBranch(newBranch).call();
return this;
diff --git a/commons.git/src/main/java/com/pmease/commons/git/GitUtils.java b/commons.git/src/main/java/com/pmease/commons/git/GitUtils.java
index 779095a046..9dfaff66c0 100644
--- a/commons.git/src/main/java/com/pmease/commons/git/GitUtils.java
+++ b/commons.git/src/main/java/com/pmease/commons/git/GitUtils.java
@@ -9,6 +9,8 @@ import javax.annotation.Nullable;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.jgit.diff.DiffEntry;
+import org.eclipse.jgit.diff.DiffEntry.ChangeType;
+import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.util.SystemReader;
@@ -179,5 +181,29 @@ public class GitUtils {
public static String branch2ref(String branch) {
return Git.REFS_HEADS + branch;
}
+
+ public static BlobIdent getOldBlobIdent(DiffEntry diffEntry, String oldRev) {
+ BlobIdent blobIdent;
+ if (diffEntry.getChangeType() != ChangeType.ADD) {
+ blobIdent = new BlobIdent(oldRev, diffEntry.getOldPath(), diffEntry.getOldMode().getBits());
+ AnyObjectId id = diffEntry.getOldId().toObjectId();
+ blobIdent.id = id!=null?id.name():null;
+ } else {
+ blobIdent = new BlobIdent(oldRev, null, null);
+ }
+ return blobIdent;
+ }
+
+ public static BlobIdent getNewBlobIdent(DiffEntry diffEntry, String newRev) {
+ BlobIdent blobIdent;
+ if (diffEntry.getChangeType() != ChangeType.DELETE) {
+ blobIdent = new BlobIdent(newRev, diffEntry.getNewPath(), diffEntry.getNewMode().getBits());
+ AnyObjectId id = diffEntry.getNewId().toObjectId();
+ blobIdent.id = id!=null?id.name():null;
+ } else {
+ blobIdent = new BlobIdent(newRev, null, null);
+ }
+ return blobIdent;
+ }
}
diff --git a/commons.git/src/main/java/com/pmease/commons/git/command/ListFileChangesCommand.java b/commons.git/src/main/java/com/pmease/commons/git/command/ListFileChangesCommand.java
deleted file mode 100644
index 76f832d6ce..0000000000
--- a/commons.git/src/main/java/com/pmease/commons/git/command/ListFileChangesCommand.java
+++ /dev/null
@@ -1,90 +0,0 @@
-package com.pmease.commons.git.command;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.base.Preconditions;
-import com.pmease.commons.git.Change;
-import com.pmease.commons.util.execution.Commandline;
-import com.pmease.commons.util.execution.LineConsumer;
-
-public class ListFileChangesCommand extends GitCommand<List<Change>> {
-
- private static final Logger logger = LoggerFactory.getLogger(ListFileChangesCommand.class);
-
- private String fromRev;
-
- private String toRev;
-
- private String path;
-
- private boolean findRenames;
-
- public ListFileChangesCommand(final File repoDir) {
- super(repoDir);
- }
-
- public ListFileChangesCommand fromRev(final String fromRev) {
- this.fromRev = fromRev;
- return this;
- }
-
- public ListFileChangesCommand toRev(final String toRev) {
- this.toRev = toRev;
- return this;
- }
-
- public ListFileChangesCommand path(final String path) {
- this.path = path;
- return this;
- }
-
- public ListFileChangesCommand findRenames(final boolean findRenames) {
- this.findRenames = findRenames;
- return this;
- }
-
- @Override
- public List<Change> call() {
- Preconditions.checkNotNull(toRev, "toRev has to be specified.");
- Preconditions.checkNotNull(fromRev, "fromRev has to be specified.");
-
- final List<Change> fileChanges = new ArrayList<>();
-
- Commandline cmd = cmd();
-
- cmd.addArgs("diff", "--raw");
-
- if (findRenames)
- cmd.addArgs("--find-renames");
-
- cmd.addArgs(fromRev + ".." + toRev);
-
- if (path != null)
- cmd.addArgs("--", path);
-
- cmd.execute(new LineConsumer() {
-
- @Override
- public void consume(String line) {
- if (line.startsWith(":"))
- fileChanges.add(Change.parseRawLine(fromRev, toRev, line));
- }
-
- }, new LineConsumer() {
-
- @Override
- public void consume(String line) {
- logger.error(line);
- }
-
- }).checkReturnCode();
-
- return fileChanges;
- }
-
-}
diff --git a/commons.git/src/test/java/com/pmease/commons/git/command/ListChangedFilesCommandTest.java b/commons.git/src/test/java/com/pmease/commons/git/command/ListChangedFilesCommandTest.java
deleted file mode 100644
index 2759514b6e..0000000000
--- a/commons.git/src/test/java/com/pmease/commons/git/command/ListChangedFilesCommandTest.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package com.pmease.commons.git.command;
-
-import java.util.Collection;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-import com.google.common.collect.Sets;
-import com.pmease.commons.git.AbstractGitTest;
-
-public class ListChangedFilesCommandTest extends AbstractGitTest {
-
- @Test
- public void shouldListChangedFiles() {
- addFileAndCommit("a", "", "commit");
- addFileAndCommit("b", "", "commit");
- addFileAndCommit("c", "", "commit");
- addFileAndCommit("d", "", "commit");
- addFileAndCommit("a", "a", "commit");
-
- Collection<String> changedFiles = git.listChangedFiles("HEAD~4", "HEAD", null);
-
- Assert.assertTrue(changedFiles.containsAll(Sets.newHashSet("a", "b", "c", "d")));
- }
-
-}
diff --git a/commons.git/src/test/java/com/pmease/commons/git/command/ListFileChangesCommandTest.java b/commons.git/src/test/java/com/pmease/commons/git/command/ListFileChangesCommandTest.java
deleted file mode 100644
index a84dfbaaad..0000000000
--- a/commons.git/src/test/java/com/pmease/commons/git/command/ListFileChangesCommandTest.java
+++ /dev/null
@@ -1,46 +0,0 @@
-package com.pmease.commons.git.command;
-
-import static org.junit.Assert.assertEquals;
-
-import java.util.List;
-
-import org.apache.commons.lang3.SystemUtils;
-import org.junit.Test;
-
-import com.pmease.commons.git.AbstractGitTest;
-import com.pmease.commons.git.Change;
-
-public class ListFileChangesCommandTest extends AbstractGitTest {
-
- @Test
- public void test() {
- addFileAndCommit("initial", "", "0");
- addFileAndCommit("file name with space", "hello world", "1");
- removeFileAndCommit("file name with space", "2");
- addFileAndCommit("another file name with space", "hello world", "3");
-
- List<Change> changes = git.listFileChanges("master~3", "master~2", null, true);
- assertEquals(1, changes.size());
- assertEquals("file name with space", changes.get(0).getNewBlobIdent().path);
-
- changes = git.listFileChanges("master~2", "master", null, true);
- assertEquals(1, changes.size());
- assertEquals(Change.Status.RENAMED, changes.get(0).getStatus());
- assertEquals("file name with space", changes.get(0).getOldBlobIdent().path);
- assertEquals("another file name with space", changes.get(0).getNewBlobIdent().path);
-
- if (!SystemUtils.IS_OS_WINDOWS) {
- addFileAndCommit("file name with \"quote\" ", "hello world", "1");
- rm("file name with \"quote\" ");
- addFile(" another file name with \"quote\" ", "hello world");
- commit("2");
-
- changes = git.listFileChanges("master~1", "master", null, true);
- assertEquals(1, changes.size());
- assertEquals(Change.Status.RENAMED, changes.get(0).getStatus());
- assertEquals("file name with \"quote\" ", changes.get(0).getOldBlobIdent().path);
- assertEquals(" another file name with \"quote\" ", changes.get(0).getNewBlobIdent().path);
- }
-
- }
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/PullRequestCommentManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/PullRequestCommentManager.java
index 9ba5614dfa..5e07978a10 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/PullRequestCommentManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/PullRequestCommentManager.java
@@ -10,7 +10,7 @@ public interface PullRequestCommentManager {
* @param comment
* comment to be updated
*/
- void updateInline(PullRequestComment comment);
+ void updateInlineInfo(PullRequestComment comment);
void save(PullRequestComment comment, boolean notify);
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestCommentManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestCommentManager.java
index 0c99e54df8..0b46e591fa 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestCommentManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestCommentManager.java
@@ -8,19 +8,23 @@ import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
+import org.eclipse.jgit.diff.DiffEntry;
+
import com.google.common.base.Preconditions;
import com.pmease.commons.git.Blob;
import com.pmease.commons.git.BlobIdent;
-import com.pmease.commons.git.Change;
+import com.pmease.commons.git.GitUtils;
import com.pmease.commons.hibernate.Transactional;
import com.pmease.commons.hibernate.dao.Dao;
import com.pmease.commons.lang.diff.DiffBlock;
+import com.pmease.commons.lang.diff.DiffMatchPatch.Operation;
import com.pmease.commons.lang.diff.DiffUtils;
import com.pmease.commons.markdown.MarkdownManager;
import com.pmease.gitplex.core.comment.MentionParser;
import com.pmease.gitplex.core.listeners.PullRequestListener;
import com.pmease.gitplex.core.manager.PullRequestCommentManager;
import com.pmease.gitplex.core.model.PullRequestComment;
+import static com.pmease.gitplex.core.model.PullRequestComment.DIFF_CONTEXT_SIZE;
import com.pmease.gitplex.core.model.User;
@Singleton
@@ -42,42 +46,76 @@ public class DefaultPullRequestCommentManager implements PullRequestCommentManag
@Transactional
@Override
- public void updateInline(PullRequestComment comment) {
+ public void updateInlineInfo(PullRequestComment comment) {
Preconditions.checkNotNull(comment.getInlineInfo());
String latestCommitHash = comment.getRequest().getLatestUpdate().getHeadCommitHash();
if (!comment.getNewCommitHash().equals(latestCommitHash)) {
- List<Change> changes = comment.getRepository().getChanges(comment.getNewCommitHash(), latestCommitHash);
+ List<DiffEntry> changes = comment.getRepository().getDiffs(comment.getNewCommitHash(),
+ latestCommitHash, true);
String oldCommitHash = comment.getOldCommitHash();
if (oldCommitHash.equals(comment.getBlobIdent().revision)) {
- BlobIdent newBlobIdent = null;
+ BlobIdent newCompareWith = null;
if (comment.getCompareWith().path != null) {
- for (Change change: changes) {
- if (comment.getCompareWith().path.equals(change.getOldBlobIdent().path)) {
- newBlobIdent = new BlobIdent(latestCommitHash, change.getNewBlobIdent().path, change.getNewBlobIdent().mode);
+ for (DiffEntry change: changes) {
+ if (comment.getCompareWith().path.equals(change.getOldPath())) {
+ newCompareWith = GitUtils.getNewBlobIdent(change, latestCommitHash);
break;
}
}
} else {
- for (Change change: changes) {
- if (comment.getBlobIdent().path.equals(change.getNewBlobIdent().path)) {
- newBlobIdent = new BlobIdent(latestCommitHash, change.getNewBlobIdent().path, change.getNewBlobIdent().mode);
+ for (DiffEntry diff: changes) {
+ if (comment.getBlobIdent().path.equals(diff.getNewPath())) {
+ newCompareWith = GitUtils.getNewBlobIdent(diff, latestCommitHash);
break;
}
}
}
- if (newBlobIdent != null) {
- Blob.Text oldText = comment.getRepository().getBlob(comment.getBlobIdent()).getText();
- Preconditions.checkNotNull(oldText);
- comment.setCompareWith(newBlobIdent);
- } else {
+ if (newCompareWith == null)
+ comment.setCompareWith(newCompareWith);
+ else
comment.getCompareWith().revision = latestCommitHash;
+
+ if (comment.getCompareWith().path != null) {
+ Blob.Text oldText = comment.getRepository().getBlob(comment.getBlobIdent()).getText();
+ Blob.Text newText = comment.getRepository().getBlob(comment.getCompareWith()).getText();
+ if (oldText != null && newText != null) {
+ List<DiffBlock<String>> diffs = DiffUtils.diff(oldText.getLines(), newText.getLines());
+ for (int i=0; i<diffs.size(); i++) {
+ DiffBlock<String> diff = diffs.get(i);
+ int startOffset = comment.getLine() - diff.getOldStart();
+ int endOffset = diff.getOldEnd() - comment.getLine();
+ if (startOffset >= 0 && endOffset > 0) {
+ if (diff.getOperation() == Operation.EQUAL) {
+ int newLine = startOffset + diff.getNewStart();
+ if (diffs.size() == 1) {
+ comment.setBlobIdent(comment.getCompareWith());
+ comment.setLine(newLine);
+ } else if (i == 0) {
+ if (endOffset > DIFF_CONTEXT_SIZE) {
+ comment.setBlobIdent(comment.getCompareWith());
+ comment.setLine(newLine);
+ }
+ } else if (i == diffs.size()-1) {
+ if (startOffset >= DIFF_CONTEXT_SIZE) {
+ comment.setBlobIdent(comment.getCompareWith());
+ comment.setLine(newLine);
+ }
+ } else if (endOffset > DIFF_CONTEXT_SIZE && startOffset >= DIFF_CONTEXT_SIZE){
+ comment.setBlobIdent(comment.getCompareWith());
+ comment.setLine(newLine);
+ }
+ }
+ break;
+ }
+ }
+ }
}
} else {
BlobIdent newBlobIdent = null;
- for (Change change: changes) {
- if (comment.getBlobIdent().path.equals(change.getOldBlobIdent().path)) {
- newBlobIdent = new BlobIdent(latestCommitHash, change.getNewBlobIdent().path, change.getNewBlobIdent().mode);
+ for (DiffEntry diff: changes) {
+ if (comment.getBlobIdent().path.equals(diff.getOldPath())) {
+ newBlobIdent = GitUtils.getNewBlobIdent(diff, latestCommitHash);
break;
}
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestUpdateManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestUpdateManager.java
index 094bd89c65..f9e60d2f09 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestUpdateManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestUpdateManager.java
@@ -79,7 +79,7 @@ public class DefaultPullRequestUpdateManager implements PullRequestUpdateManager
PullRequest request = dao.load(PullRequest.class, requestId);
for (PullRequestComment comment: request.getComments()) {
if (comment.getInlineInfo() != null)
- pullRequestCommentManager.updateInline(comment);
+ pullRequestCommentManager.updateInlineInfo(comment);
}
}
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.java
index 799e10c43f..354b38dab0 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
@@ -767,8 +767,10 @@ public class PullRequest extends AbstractEntity {
public List<String> getCommentables() {
List<String> commentables = new ArrayList<>();
commentables.add(getBaseCommitHash());
- for (PullRequestUpdate update: getSortedUpdates())
- commentables.add(update.getHeadCommitHash());
+ for (PullRequestUpdate update: getSortedUpdates()) {
+ for (Commit commit: update.getCommits())
+ commentables.add(commit.getHash());
+ }
return commentables;
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestComment.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestComment.java
index 33c30e4dd7..d4523b4c97 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestComment.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestComment.java
@@ -35,6 +35,8 @@ import com.pmease.gitplex.core.manager.UserManager;
@Entity
public class PullRequestComment extends AbstractEntity implements InlineComment {
+ public static final int DIFF_CONTEXT_SIZE = 3;
+
@ManyToOne
@JoinColumn(nullable=false)
@Fetch(FetchMode.JOIN)
@@ -56,7 +58,7 @@ public class PullRequestComment extends AbstractEntity implements InlineComment
@Embedded
private InlineInfo inlineInfo;
- private transient Pair<String, String> oldCommitAndNewCommit;
+ private transient Pair<String, String> oldAndNew;
public PullRequest getRequest() {
return request;
@@ -128,18 +130,24 @@ public class PullRequestComment extends AbstractEntity implements InlineComment
return reply;
}
- private Pair<String, String> getOldCommitAndNewCommit() {
- if (oldCommitAndNewCommit == null) {
- List<String> commitHashes = getRequest().getCommentables();
- int index = commitHashes.indexOf(getBlobIdent().revision);
- int compareIndex = commitHashes.indexOf(getCompareWith().revision);
- Preconditions.checkState(index != -1 && compareIndex != -1);
- if (index <= compareIndex)
- oldCommitAndNewCommit = new Pair<>(getBlobIdent().revision, getCompareWith().revision);
- else
- oldCommitAndNewCommit = new Pair<>(getCompareWith().revision, getBlobIdent().revision);
+ private Pair<String, String> getOldAndNew() {
+ String rev = getBlobIdent().revision;
+ if (oldAndNew == null) {
+ if (getCompareWith() != null) {
+ List<String> commitHashes = getRequest().getCommentables();
+ String compareRev = getCompareWith().revision;
+ int index = commitHashes.indexOf(rev);
+ int compareIndex = commitHashes.indexOf(compareRev);
+ Preconditions.checkState(index != -1 && compareIndex != -1);
+ if (index <= compareIndex)
+ oldAndNew = new Pair<>(rev, compareRev);
+ else
+ oldAndNew = new Pair<>(compareRev, rev);
+ } else {
+ oldAndNew = new Pair<>(rev, rev);
+ }
}
- return oldCommitAndNewCommit;
+ return oldAndNew;
}
public InlineInfo getInlineInfo() {
@@ -151,11 +159,11 @@ public class PullRequestComment extends AbstractEntity implements InlineComment
}
public String getOldCommitHash() {
- return getOldCommitAndNewCommit().getFirst();
+ return getOldAndNew().getFirst();
}
public String getNewCommitHash() {
- return getOldCommitAndNewCommit().getSecond();
+ return getOldAndNew().getSecond();
}
@Override
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.java
index adba2cf78e..88b0ebbd56 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
@@ -3,6 +3,7 @@ package com.pmease.gitplex.core.model;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
@@ -28,6 +29,8 @@ import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import org.apache.commons.lang3.SerializationUtils;
+import org.eclipse.jgit.diff.DiffEntry;
+import org.eclipse.jgit.diff.DiffFormatter;
import org.eclipse.jgit.errors.RevisionSyntaxException;
import org.eclipse.jgit.internal.storage.file.FileRepository;
import org.eclipse.jgit.lib.AnyObjectId;
@@ -43,20 +46,24 @@ import org.eclipse.jgit.revwalk.LastCommitsOfChildren.Value;
import org.eclipse.jgit.revwalk.RevTree;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.treewalk.TreeWalk;
+import org.eclipse.jgit.treewalk.filter.OrTreeFilter;
+import org.eclipse.jgit.treewalk.filter.PathFilter;
+import org.eclipse.jgit.treewalk.filter.TreeFilter;
import org.eclipse.jgit.util.FS;
+import org.eclipse.jgit.util.io.NullOutputStream;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;
import org.hibernate.validator.constraints.NotEmpty;
+import com.google.common.base.Objects;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.pmease.commons.editable.annotation.Editable;
import com.pmease.commons.editable.annotation.Markdown;
import com.pmease.commons.git.Blob;
import com.pmease.commons.git.BlobIdent;
-import com.pmease.commons.git.Change;
import com.pmease.commons.git.Commit;
import com.pmease.commons.git.Git;
import com.pmease.commons.git.GitUtils;
@@ -67,7 +74,6 @@ import com.pmease.commons.hibernate.AbstractEntity;
import com.pmease.commons.loader.AppLoader;
import com.pmease.commons.util.FileUtils;
import com.pmease.commons.util.LockUtils;
-import com.pmease.commons.util.Pair;
import com.pmease.commons.util.StringUtils;
import com.pmease.gitplex.core.GitPlex;
import com.pmease.gitplex.core.gatekeeper.AndGateKeeper;
@@ -133,7 +139,7 @@ public class Repository extends AbstractEntity implements UserBelonging {
private transient Map<BlobIdent, Blob> blobCache;
- private transient Map<CommitRange, List<Change>> changesCache;
+ private transient Map<DiffKey, List<DiffEntry>> diffCache;
private transient Map<String, Commit> commitCache;
@@ -538,17 +544,34 @@ public class Repository extends AbstractEntity implements UserBelonging {
objectIdCache.put(revision, Optional.fromNullable(objectId));
}
- public List<Change> getChanges(String fromCommit, String toCommit) {
- if (changesCache == null)
- changesCache = new HashMap<>();
+ public List<DiffEntry> getDiffs(String oldRev, String newRev, boolean detectRenames, String...paths) {
+ if (diffCache == null)
+ diffCache = new HashMap<>();
- 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);
+ DiffKey key = new DiffKey(oldRev, newRev, detectRenames, paths);
+ List<DiffEntry> diffs = diffCache.get(key);
+ if (diffs == null) {
+ try ( FileRepository jgitRepo = openAsJGitRepo();
+ DiffFormatter diffFormatter = new DiffFormatter(NullOutputStream.INSTANCE);) {
+ diffFormatter.setRepository(jgitRepo);
+ diffFormatter.setDetectRenames(detectRenames);
+ AnyObjectId oldCommitId = getObjectId(oldRev);
+ AnyObjectId newCommitId = getObjectId(newRev);
+ if (paths.length >= 2) {
+ List<TreeFilter> pathFilters = new ArrayList<>();
+ for (String path: paths)
+ pathFilters.add(PathFilter.create(path));
+ diffFormatter.setPathFilter(OrTreeFilter.create(pathFilters));
+ } else if (paths.length == 1) {
+ diffFormatter.setPathFilter(PathFilter.create(paths[0]));
+ }
+ diffs = diffFormatter.scan(oldCommitId, newCommitId);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ diffCache.put(key, diffs);
}
- return changes;
+ return diffs;
}
public Commit getCommit(String commitHash) {
@@ -571,10 +594,38 @@ public class Repository extends AbstractEntity implements UserBelonging {
commitCache.put(commit.getHash(), commit);
}
- private static class CommitRange extends Pair<String, String> {
- CommitRange(String fromCommit, String toCommit) {
- super(fromCommit, toCommit);
+ private static class DiffKey implements Serializable {
+ String oldRev;
+
+ String newRev;
+
+ String[] paths;
+
+ boolean detectRenames;
+
+ DiffKey(String oldRev, String newRev, boolean detectRenames, String...paths) {
+ this.oldRev = oldRev;
+ this.newRev = newRev;
+ this.detectRenames = detectRenames;
+ this.paths = paths;
+ }
+
+ public boolean equals(Object other) {
+ if (!(other instanceof DiffKey))
+ return false;
+ if (this == other)
+ return true;
+ DiffKey otherKey = (DiffKey) other;
+ return Objects.equal(oldRev, otherKey.oldRev)
+ && Objects.equal(newRev, otherKey.newRev)
+ && Objects.equal(paths, otherKey.paths)
+ && Objects.equal(detectRenames, otherKey.detectRenames);
+ }
+
+ public int hashCode() {
+ return Objects.hashCode(oldRev, newRev, paths, detectRenames);
}
+
}
public FileRepository openAsJGitRepo() {
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/Constants.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/Constants.java
index 8ac6b18e48..2c1cca37a0 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/Constants.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/Constants.java
@@ -11,8 +11,7 @@ public class Constants {
public static final int DEFAULT_SELECT2_PAGE_SIZE = 25;
/* diff constants */
- public static final int DIFF_DEFAULT_CONTEXT_SIZE = 3;
- public static final int DIFF_EXPAND_CONTEXT_SIZE = 15;
+ public static final int DIFF_EXPAND_SIZE = 15;
public static final int MAX_DIFF_FILES = 500;
public static final int MAX_SINGLE_FILE_DIFF_LINES = 5000;
public static final int MAX_DIFF_LINES = 20000;
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.java
index 3e207bdff1..532ef02ef7 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.java
@@ -51,6 +51,7 @@ import com.pmease.commons.wicket.component.feedback.FeedbackPanel;
import com.pmease.gitplex.core.comment.Comment;
import com.pmease.gitplex.core.comment.InlineComment;
import com.pmease.gitplex.core.comment.InlineCommentSupport;
+import com.pmease.gitplex.core.model.PullRequestComment;
import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.web.Constants;
import com.pmease.gitplex.web.component.avatar.AvatarMode;
@@ -162,8 +163,8 @@ public class TextDiffPanel extends Panel {
int index = params.getParameterValue("index").toInt();
Integer lastContextSize = contextSizes.get(index);
if (lastContextSize == null)
- lastContextSize = Constants.DIFF_DEFAULT_CONTEXT_SIZE;
- int contextSize = lastContextSize + Constants.DIFF_EXPAND_CONTEXT_SIZE;
+ lastContextSize = PullRequestComment.DIFF_CONTEXT_SIZE;
+ int contextSize = lastContextSize + Constants.DIFF_EXPAND_SIZE;
contextSizes.put(index, contextSize);
StringBuilder builder = new StringBuilder();
@@ -339,7 +340,7 @@ public class TextDiffPanel extends Panel {
}
private String renderDiffs() {
- int contextSize = Constants.DIFF_DEFAULT_CONTEXT_SIZE;
+ int contextSize = PullRequestComment.DIFF_CONTEXT_SIZE;
StringBuilder builder = new StringBuilder();
builder.append("<colgroup><col width='40'></col>");
if (diffMode == DiffMode.UNIFIED)
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/RevisionDiffPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/RevisionDiffPanel.java
index 5b848c7003..dc5d3b0439 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/RevisionDiffPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/RevisionDiffPanel.java
@@ -1,6 +1,5 @@
package com.pmease.gitplex.web.component.diff.revision;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
@@ -28,15 +27,10 @@ import org.apache.wicket.request.resource.CssResourceReference;
import org.apache.wicket.util.lang.Objects;
import org.eclipse.jgit.diff.DiffEntry;
import org.eclipse.jgit.diff.DiffEntry.ChangeType;
-import org.eclipse.jgit.diff.DiffFormatter;
-import org.eclipse.jgit.internal.storage.file.FileRepository;
-import org.eclipse.jgit.lib.AnyObjectId;
-import org.eclipse.jgit.treewalk.filter.PathFilter;
-import org.eclipse.jgit.util.io.NullOutputStream;
import com.pmease.commons.git.Blob;
-import com.pmease.commons.git.BlobChange;
import com.pmease.commons.git.BlobIdent;
+import com.pmease.commons.git.BlobChange;
import com.pmease.commons.git.LineProcessor;
import com.pmease.commons.lang.diff.DiffUtils;
import com.pmease.gitplex.core.GitPlex;
@@ -57,6 +51,8 @@ public class RevisionDiffPanel extends Panel {
private final String filterPath;
+ private final String comparePath;
+
private final LineProcessor lineProcessor;
private final DiffMode diffMode;
@@ -68,117 +64,109 @@ public class RevisionDiffPanel extends Panel {
@Override
protected ChangesAndCount load() {
- try ( FileRepository jgitRepo = repoModel.getObject().openAsJGitRepo();
- DiffFormatter diffFormatter = new DiffFormatter(NullOutputStream.INSTANCE);) {
- diffFormatter.setRepository(jgitRepo);
- diffFormatter.setDetectRenames(true);
-
- if (filterPath != null)
- diffFormatter.setPathFilter(PathFilter.create(filterPath));
- AnyObjectId oldCommitId = repoModel.getObject().getObjectId(oldRev);
- AnyObjectId newCommitId = repoModel.getObject().getObjectId(newRev);
- List<DiffEntry> entries = diffFormatter.scan(oldCommitId, newCommitId);
- List<BlobChange> diffableChanges = new ArrayList<>();
- for (DiffEntry entry: diffFormatter.scan(oldCommitId, newCommitId)) {
- if (diffableChanges.size() < Constants.MAX_DIFF_FILES) {
- diffableChanges.add(new BlobChange(oldCommitId.name(), newCommitId.name(), entry) {
-
- @Override
- public Blob getBlob(BlobIdent blobIdent) {
- return repoModel.getObject().getBlob(blobIdent);
- }
-
- @Override
- public LineProcessor getLineProcessor() {
- return lineProcessor;
- }
-
- });
- } else {
- break;
- }
- }
+ String oldCommitHash = repoModel.getObject().getObjectId(oldRev).name();
+ String newCommitHash = repoModel.getObject().getObjectId(newRev).name();
+ List<DiffEntry> diffEntries = repoModel.getObject().getDiffs(oldCommitHash, newCommitHash,
+ true, filterPath, comparePath);
+ List<BlobChange> diffableChanges = new ArrayList<>();
+ for (DiffEntry entry: diffEntries) {
+ if (diffableChanges.size() < Constants.MAX_DIFF_FILES) {
+ diffableChanges.add(new BlobChange(oldCommitHash, newCommitHash, entry) {
- // Diff calculation can be slow, so we pre-load diffs of each change
- // concurrently
- Collection<Callable<Void>> tasks = new ArrayList<>();
- for (final BlobChange change: diffableChanges) {
- tasks.add(new Callable<Void>() {
+ @Override
+ public Blob getBlob(BlobIdent blobIdent) {
+ return repoModel.getObject().getBlob(blobIdent);
+ }
@Override
- public Void call() throws Exception {
- change.getDiffBlocks();
- return null;
+ public LineProcessor getLineProcessor() {
+ return lineProcessor;
}
});
- }
- for (Future<Void> future: GitPlex.getInstance(ForkJoinPool.class).invokeAll(tasks)) {
- try {
- // call get in order to throw exception if there is any during task execution
- future.get();
- } catch (InterruptedException|ExecutionException e) {
- throw new RuntimeException(e);
- }
- }
+ } else {
+ break;
+ }
+ }
- int totalChanges = entries.size();
- if (diffableChanges.size() == totalChanges) {
- // some changes should be removed if content is the same after line processing
- for (Iterator<BlobChange> it = diffableChanges.iterator(); it.hasNext();) {
- BlobChange change = it.next();
- if (change.getType() == ChangeType.MODIFY
- && Objects.equal(change.getOldBlobIdent().mode, change.getNewBlobIdent().mode)
- && change.getAdditions() + change.getDeletions() == 0) {
- Blob.Text oldText = change.getOldText();
- Blob.Text newText = change.getNewText();
- if (oldText != null && newText != null
- && (oldText.getLines().size() + newText.getLines().size()) <= DiffUtils.MAX_DIFF_SIZE) {
- it.remove();
- }
- }
- }
- totalChanges = diffableChanges.size();
- }
+ // Diff calculation can be slow, so we pre-load diffs of each change
+ // concurrently
+ Collection<Callable<Void>> tasks = new ArrayList<>();
+ for (final BlobChange change: diffableChanges) {
+ tasks.add(new Callable<Void>() {
- List<BlobChange> displayableChanges = new ArrayList<>();
- int totalChangedLines = 0;
- for (BlobChange change: diffableChanges) {
- int changedLines = change.getAdditions() + change.getDeletions();
-
- // we do not count large diff in a single file in order to
- // display smaller diffs from different files as many as
- // possible.
- if (changedLines <= Constants.MAX_SINGLE_FILE_DIFF_LINES) {
- totalChangedLines += changedLines;
- if (totalChangedLines <= Constants.MAX_DIFF_LINES)
- displayableChanges.add(change);
- else
- break;
- } else {
- // large diff in a single file will not be displayed, so
- // adding it to change list will do no harm, and can avoid
- // displaying "too many changes" when some big text file
- // is added/removed without touching too many files
- displayableChanges.add(change);
+ @Override
+ public Void call() throws Exception {
+ change.getDiffBlocks();
+ return null;
+ }
+
+ });
+ }
+ for (Future<Void> future: GitPlex.getInstance(ForkJoinPool.class).invokeAll(tasks)) {
+ try {
+ // call get in order to throw exception if there is any during task execution
+ future.get();
+ } catch (InterruptedException|ExecutionException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ int totalChanges = diffEntries.size();
+ if (diffableChanges.size() == totalChanges) {
+ // some changes should be removed if content is the same after line processing
+ for (Iterator<BlobChange> it = diffableChanges.iterator(); it.hasNext();) {
+ BlobChange change = it.next();
+ if (change.getType() == ChangeType.MODIFY
+ && Objects.equal(change.getOldBlobIdent().mode, change.getNewBlobIdent().mode)
+ && change.getAdditions() + change.getDeletions() == 0) {
+ Blob.Text oldText = change.getOldText();
+ Blob.Text newText = change.getNewText();
+ if (oldText != null && newText != null
+ && (oldText.getLines().size() + newText.getLines().size()) <= DiffUtils.MAX_DIFF_SIZE) {
+ it.remove();
+ }
}
}
- return new ChangesAndCount(displayableChanges, totalChanges);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
+ totalChanges = diffableChanges.size();
+ }
+
+ List<BlobChange> displayableChanges = new ArrayList<>();
+ int totalChangedLines = 0;
+ for (BlobChange change: diffableChanges) {
+ int changedLines = change.getAdditions() + change.getDeletions();
+
+ // we do not count large diff in a single file in order to
+ // display smaller diffs from different files as many as
+ // possible.
+ if (changedLines <= Constants.MAX_SINGLE_FILE_DIFF_LINES) {
+ totalChangedLines += changedLines;
+ if (totalChangedLines <= Constants.MAX_DIFF_LINES)
+ displayableChanges.add(change);
+ else
+ break;
+ } else {
+ // large diff in a single file will not be displayed, so
+ // adding it to change list will do no harm, and can avoid
+ // displaying "too many changes" when some big text file
+ // is added/removed without touching too many files
+ displayableChanges.add(change);
+ }
+ }
+ return new ChangesAndCount(displayableChanges, totalChanges);
}
};
public RevisionDiffPanel(String id, IModel<Repository> repoModel, String oldRev, String newRev,
- @Nullable String filterPath, LineProcessor lineProcessor, DiffMode diffMode,
- @Nullable InlineCommentSupport commentSupport) {
+ @Nullable String filterPath, @Nullable String comparePath, LineProcessor lineProcessor,
+ DiffMode diffMode, @Nullable InlineCommentSupport commentSupport) {
super(id);
this.repoModel = repoModel;
this.oldRev = oldRev;
this.newRev = newRev;
this.filterPath = filterPath;
+ this.comparePath = comparePath;
this.lineProcessor = lineProcessor;
this.diffMode = diffMode;
this.commentSupport = commentSupport;
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/newrequest/NewRequestPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/newrequest/NewRequestPage.java
index f1490772a4..8c2416b476 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/newrequest/NewRequestPage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/newrequest/NewRequestPage.java
@@ -387,7 +387,7 @@ public class NewRequestPage extends PullRequestPage {
String oldRev = request.getBaseCommitHash();
String newRev = request.getLatestUpdate().getHeadCommitHash();
RevisionDiffPanel diffPanel = new RevisionDiffPanel("revisionDiff", repoModel,
- oldRev, newRev, filterPath, diffOption.getLineProcessor(),
+ oldRev, newRev, filterPath, null, diffOption.getLineProcessor(),
diffOption.getDiffMode(), null);
diffPanel.setOutputMarkupId(true);
return diffPanel;
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/requestdetail/compare/RequestComparePage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/requestdetail/compare/RequestComparePage.java
index 982c4d6ce9..7fb2ddeef5 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/requestdetail/compare/RequestComparePage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/requestdetail/compare/RequestComparePage.java
@@ -28,6 +28,8 @@ import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.request.resource.CssResourceReference;
+import org.eclipse.jgit.diff.DiffEntry;
+import org.eclipse.jgit.internal.storage.file.FileRepository;
import com.google.common.base.Preconditions;
import com.pmease.commons.git.BlobIdent;
@@ -87,6 +89,8 @@ public class RequestComparePage extends RequestDetailPage {
private String filterPath;
+ private String comparePath;
+
private Long commentId;
private WebMarkupContainer compareOptions;
@@ -287,21 +291,26 @@ public class RequestComparePage extends RequestDetailPage {
PullRequest request = getPullRequest();
if (request.isOpen()) {
final IntegrationPreview preview = request.getIntegrationPreview();
- if (preview != null && preview.getIntegrated() != null
- && !getRepository().getChanges(preview.getRequestHead(), preview.getIntegrated()).isEmpty()) {
- items.add(new ComparisonChoiceItem("Target Branch", "Integration Preview") {
-
- @Override
- protected void onSelect(AjaxRequestTarget target) {
- hide(target);
- oldCommitHash = getPullRequest().getTarget().getHead();
- newCommitHash = preview.getIntegrated();
- getPageParameters().set(PARAM_OLD, oldCommitHash);
- getPageParameters().set(PARAM_NEW, newCommitHash);
- onStateChange(target);
+ if (preview != null && preview.getIntegrated() != null) {
+ try (FileRepository jgitRepo = getRepository().openAsJGitRepo();) {
+ List<DiffEntry> diffs = getRepository().getDiffs(
+ preview.getRequestHead(), preview.getIntegrated(), false);
+ if (!diffs.isEmpty()) {
+ items.add(new ComparisonChoiceItem("Target Branch", "Integration Preview") {
+
+ @Override
+ protected void onSelect(AjaxRequestTarget target) {
+ hide(target);
+ oldCommitHash = getPullRequest().getTarget().getHead();
+ newCommitHash = preview.getIntegrated();
+ getPageParameters().set(PARAM_OLD, oldCommitHash);
+ getPageParameters().set(PARAM_NEW, newCommitHash);
+ onStateChange(target);
+ }
+
+ });
}
-
- });
+ }
}
}
@@ -558,8 +567,10 @@ public class RequestComparePage extends RequestDetailPage {
oldCommitHash = comment.getOldCommitHash();
if (newCommitHash == null)
newCommitHash = comment.getNewCommitHash();
- if (filterPath == null)
+ if (filterPath == null) {
filterPath = comment.getBlobIdent().path;
+ comparePath = comment.getCompareWith().path;
+ }
}
if (oldCommitHash == null)
oldCommitHash = getPullRequest().getBaseCommitHash();
@@ -657,9 +668,9 @@ public class RequestComparePage extends RequestDetailPage {
};
};
- RevisionDiffPanel diffPanel = new RevisionDiffPanel("compareResult", repoModel,
- oldCommitHash, newCommitHash, filterPath, diffOption.getLineProcessor(),
- diffOption.getDiffMode(), commentSupport);
+ RevisionDiffPanel diffPanel = new RevisionDiffPanel("compareResult",
+ repoModel, oldCommitHash, newCommitHash, filterPath, comparePath,
+ diffOption.getLineProcessor(), diffOption.getDiffMode(), commentSupport);
diffPanel.setOutputMarkupId(true);
if (target != null) {
replace(diffPanel);
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.html
index c5f9d1ec6a..e415318076 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.html
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.html
@@ -1,10 +1,3 @@
<wicket:extend>
- <ul>
- <li class="1">1</li>
- <li class="2">2</li>
- <li class="3">3</li>
- </ul>
- <script type="text/javascript">
- console.log($("li.2").next().prev().length);
- </script>
+ <a wicket:id="test">test</a>
</wicket:extend>
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.java
index dd0917ed1d..42ff987bd7 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.java
@@ -1,6 +1,7 @@
package com.pmease.gitplex.web.page.test;
import org.apache.wicket.markup.head.IHeaderResponse;
+import org.apache.wicket.markup.html.link.Link;
import com.pmease.gitplex.web.page.base.BasePage;
@@ -10,7 +11,15 @@ public class TestPage extends BasePage {
@Override
protected void onInitialize() {
super.onInitialize();
- }
+
+ add(new Link<Void>("test") {
+
+ @Override
+ public void onClick() {
+ }
+
+ });
+ }
@Override
public void renderHead(IHeaderResponse response) {