The Unified and Autonomous Development Platform
About to optimize ChangeComments
robin shineb57664c237cc
diff --git a/commons.git/src/main/java/com/pmease/commons/git/BlobInfo.java b/commons.git/src/main/java/com/pmease/commons/git/BlobInfo.javanew file mode 100644index 0000000000..3681ff7ff6--- /dev/null+++ b/commons.git/src/main/java/com/pmease/commons/git/BlobInfo.java@@ -0,0 +1,69 @@+package com.pmease.commons.git;++import java.io.Serializable;++import org.apache.commons.lang3.builder.EqualsBuilder;+import org.apache.commons.lang3.builder.HashCodeBuilder;++import com.google.common.base.Objects;++@SuppressWarnings("serial")+public class BlobInfo implements Serializable {++ private final String path;++ private final String revision;++ private final int mode;++ public BlobInfo(String revision, String path, int mode) {+ this.revision = revision;+ this.path = path;+ this.mode = mode;+ }++ public String getPath() {+ return path;+ }++ public String getRevision() {+ return revision;+ }++ public int getMode() {+ return mode;+ }++ @Override+ public boolean equals(Object other) {+ if (!(other instanceof BlobInfo))+ return false;+ if (this == other)+ return true;+ BlobInfo otherInfo = (BlobInfo) other;+ return new EqualsBuilder()+ .append(revision, otherInfo.getRevision())+ .append(path, otherInfo.getPath())+ .append(mode, otherInfo.mode)+ .isEquals();+ }++ @Override+ public int hashCode() {+ return new HashCodeBuilder(17, 37)+ .append(revision)+ .append(path)+ .append(mode)+ .toHashCode();+ }++ @Override+ public String toString() {+ return Objects.toStringHelper(BlobInfo.class)+ .add("revision", revision)+ .add("path", path)+ .add("mode", mode)+ .toString();+ }++}diff --git a/commons.git/src/main/java/com/pmease/commons/git/BlobText.java b/commons.git/src/main/java/com/pmease/commons/git/BlobText.javanew file mode 100644index 0000000000..5f9634cf61--- /dev/null+++ b/commons.git/src/main/java/com/pmease/commons/git/BlobText.java@@ -0,0 +1,150 @@+package com.pmease.commons.git;++import java.io.Serializable;+import java.nio.charset.Charset;+import java.util.ArrayList;+import java.util.List;+import java.util.regex.Pattern;++import javax.annotation.Nullable;++import org.apache.commons.lang3.StringUtils;+import org.apache.tika.mime.MediaType;+import org.eclipse.jgit.lib.FileMode;++import com.google.common.collect.Lists;+import com.pmease.commons.git.extensionpoint.TextConverter;+import com.pmease.commons.git.extensionpoint.TextConverterProvider;+import com.pmease.commons.loader.AppLoader;+import com.pmease.commons.util.Charsets;+import com.pmease.commons.util.MediaTypes;++@SuppressWarnings("serial")+public class BlobText implements Serializable {++ private static final Pattern WHITESPACE_PATTERN = Pattern.compile("\\s+");++ private final List<String> lines;++ private final boolean hasEolAtEof;++ private final MediaType mediaType;++ private final String charset;++ public BlobText(List<String> lines, boolean hasEolAtEof, String charset, MediaType mediaType) {+ this.lines = lines;+ this.hasEolAtEof = hasEolAtEof;+ this.charset = charset;+ this.mediaType = mediaType;+ }++ public BlobText(List<String> lines, boolean hasEolAtEof, String charset) {+ this(lines, hasEolAtEof, charset, MediaType.TEXT_PLAIN);+ }++ public BlobText(List<String> lines) {+ this(lines, true, Charsets.UTF_8.name());+ }++ public BlobText(String line) {+ this(Lists.newArrayList(line));+ }++ public BlobText() {+ this(new ArrayList<String>());+ }++ public boolean isHasEolAtEof() {+ return hasEolAtEof;+ }++ public List<String> getLines() {+ return lines;+ }++ public String getCharset() {+ return charset;+ }++ public MediaType getMediaType() {+ return mediaType;+ }++ public BlobText ignoreEOL() {+ List<String> processedLines = new ArrayList<>();+ for (String line: lines) {+ if (line.endsWith("\r"))+ line = line.substring(0, line.length()-1);+ processedLines.add(line);+ }+ return new BlobText(processedLines, hasEolAtEof, charset, mediaType);+ }++ public BlobText ignoreEOLSpaces() {+ List<String> processedLines = new ArrayList<>();+ for (String line: lines)+ processedLines.add(StringUtils.stripEnd(line, " \t\r"));+ return new BlobText(processedLines, hasEolAtEof, charset, mediaType);+ }++ public BlobText ignoreChangeSpaces() {+ List<String> processedLines = new ArrayList<>();+ for (String line: lines) {+ line = WHITESPACE_PATTERN.matcher(line.trim()).replaceAll(" ");+ processedLines.add(line);+ }+ return new BlobText(processedLines, hasEolAtEof, charset, mediaType);+ }++ /**+ * Read text from specified bytes. This method only treats "\n" as EOL character,+ * and any occurrences of "\r" will be preserved in read result. This method is+ * intended to read text files for comparison purpose.+ *+ * @param bytes+ * bytes to read lines from+ * @return+ * resulting GitText, <tt>null</tt> if charset can not be detected+ */+ public static @Nullable BlobText from(byte[] blobContent, String blobPath, int blobMode) {+ if (blobMode == FileMode.TYPE_GITLINK || blobMode == FileMode.TYPE_SYMLINK)+ return new BlobText(new String(blobContent));++ MediaType mediaType = MediaTypes.detectFrom(blobContent, blobPath);++ for (TextConverterProvider provider: AppLoader.getExtensions(TextConverterProvider.class)) {+ TextConverter textConverter = provider.getTextConverter(mediaType);+ if (textConverter != null)+ return new BlobText(textConverter.convert(blobContent), true, Charsets.UTF_8.name(), mediaType);+ }++ Charset charset = Charsets.detectFrom(blobContent);+ if (charset != null) {+ List<String> lines = new ArrayList<>();+ StringBuilder builder = new StringBuilder();+ String string = new String(blobContent, charset);+ for (int i=0; i<string.length(); i++) {+ char ch = string.charAt(i);+ if (ch == '\n') {+ lines.add(builder.toString());+ builder = new StringBuilder();+ } else {+ builder.append(ch);+ }+ }+ if (builder.length() != 0) {+ lines.add(builder.toString());+ return new BlobText(lines, false, charset.name());+ } else {+ return new BlobText(lines, true, charset.name());+ }+ } else {+ return null;+ }+ }++ public static @Nullable BlobText from(byte[] blobContent) {+ return from(blobContent, null, FileMode.TYPE_FILE);+ }+}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.javaindex b74480e86e..a2fe1eb54a 100644--- a/commons.git/src/main/java/com/pmease/commons/git/Change.java+++ b/commons.git/src/main/java/com/pmease/commons/git/Change.java@@ -1,12 +1,18 @@package com.pmease.commons.git;+import static com.pmease.commons.git.Change.Status.RENAMED;+import java.io.Serializable;import java.util.StringTokenizer;+import javax.annotation.Nullable;+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 {@@ -23,7 +29,7 @@ public class Change implements Comparable<Change>, Serializable {private final int newMode;- public Change(Status status, String oldPath, String newPath, int oldMode, int newMode) {+ public Change(Status status, @Nullable String oldPath, @Nullable String newPath, int oldMode, int newMode) {this.status = status;this.oldPath = oldPath;this.newPath = newPath;@@ -39,10 +45,12 @@ public class Change implements Comparable<Change>, Serializable {this.newMode = change.newMode;}+ @Nullablepublic String getOldPath() {return oldPath;}+ @Nullablepublic String getNewPath() {return newPath;}@@ -125,4 +133,19 @@ public class Change implements Comparable<Change>, Serializable {throw new RuntimeException("Unexpected status code: " + statusCode);}}++ public String getHint() {+ if (getStatus() == RENAMED)+ return "Renamed from " + getOldPath();+ 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/Commit.java b/commons.git/src/main/java/com/pmease/commons/git/Commit.javaindex 55990196d5..91d572e244 100644--- a/commons.git/src/main/java/com/pmease/commons/git/Commit.java+++ b/commons.git/src/main/java/com/pmease/commons/git/Commit.java@@ -17,8 +17,6 @@ import com.google.common.collect.Lists;@SuppressWarnings("serial")public class Commit extends BriefCommit {- public static final String ZERO_HASH = "0000000000000000000000000000000000000000";-private final String body;private final String note;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.javaindex 35faebd883..0f12ac73bb 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@@ -11,7 +11,6 @@ import java.io.Serializable;import java.util.ArrayList;import java.util.Collection;import java.util.Collections;-import java.util.Date;import java.util.HashMap;import java.util.HashSet;import java.util.List;@@ -21,8 +20,6 @@ import java.util.Set;import javax.annotation.Nullable;import org.eclipse.jgit.lib.FileMode;-import org.eclipse.jgit.lib.PersonIdent;-import org.eclipse.jgit.util.SystemReader;import com.google.common.base.Preconditions;import com.pmease.commons.git.command.AddCommand;@@ -50,6 +47,7 @@ import com.pmease.commons.git.command.ListTreeCommand;import com.pmease.commons.git.command.LogCommand;import com.pmease.commons.git.command.MergeCommand;import com.pmease.commons.git.command.MergeCommand.FastForwardMode;+import com.pmease.commons.git.command.MoveCommand;import com.pmease.commons.git.command.ParseRevisionCommand;import com.pmease.commons.git.command.PullCommand;import com.pmease.commons.git.command.PushCommand;@@ -276,6 +274,11 @@ public class Git implements Serializable {return this;}+ public Git mv(String source, String destination) {+ new MoveCommand(repoDir).source(source).destination(destination).call();+ return this;+ }+public Git clone(String from, boolean bare, boolean shared, boolean noCheckout, @Nullable String branch) {new CloneCommand(repoDir).from(from).bare(bare).shared(shared).noCheckout(noCheckout).branch(branch).call();return this;@@ -490,17 +493,15 @@ public class Git implements Serializable {return new ShowCommand(repoDir).revision(revision).path(path).call();}- public String readSubModule(String revision, String path) {- String subModuleUrl = listSubModules(revision).get(path);- Preconditions.checkNotNull(subModuleUrl);- return subModuleUrl + ":" + listTree(revision, path).iterator().next().getHash();- }-- public byte[] read(String revision, String path, int mode) {- if (mode == FileMode.TYPE_GITLINK)- return readSubModule(revision, path).getBytes();- else- return show(revision, path);+ public byte[] readBlob(BlobInfo blobInfo) {+ if (blobInfo.getMode() == FileMode.TYPE_GITLINK) {+ String subModuleUrl = listSubModules(blobInfo.getRevision()).get(blobInfo.getPath());+ Preconditions.checkNotNull(subModuleUrl);+ List<TreeNode> result = listTree(blobInfo.getRevision(), blobInfo.getPath());+ return (subModuleUrl + ":" + result.iterator().next().getHash()).getBytes();+ } else {+ return show(blobInfo.getRevision(), blobInfo.getPath());+ }}public List<Commit> log(@Nullable String fromRev, @Nullable String toRev,@@ -584,9 +585,4 @@ public class Git implements Serializable {public String toString() {return repoDir.toString();}-- public static PersonIdent newPersonIdent(String name, String email, Date when) {- return new PersonIdent(name, email, when.getTime(),- SystemReader.getInstance().getTimezone(when.getTime()));- }}diff --git a/commons.git/src/main/java/com/pmease/commons/git/GitText.java b/commons.git/src/main/java/com/pmease/commons/git/GitText.javadeleted file mode 100644index db18f9fda8..0000000000--- a/commons.git/src/main/java/com/pmease/commons/git/GitText.java+++ /dev/null@@ -1,106 +0,0 @@-package com.pmease.commons.git;--import java.io.Serializable;-import java.nio.charset.Charset;-import java.util.ArrayList;-import java.util.List;-import java.util.regex.Pattern;--import javax.annotation.Nullable;--import org.apache.commons.lang3.StringUtils;--import com.pmease.commons.util.Charsets;--@SuppressWarnings("serial")-public class GitText implements Serializable {-- private static final Pattern WHITESPACE_PATTERN = Pattern.compile("\\s+");-- private final List<String> lines;-- private final boolean hasEolAtEof;-- private final String charset;-- public GitText(List<String> lines, boolean hasEolAtEof, String charset) {- this.lines = lines;- this.hasEolAtEof = hasEolAtEof;- this.charset = charset;- }-- public boolean isHasEolAtEof() {- return hasEolAtEof;- }-- public List<String> getLines() {- return lines;- }-- public String getCharset() {- return charset;- }-- public GitText ignoreEOL() {- List<String> processedLines = new ArrayList<>();- for (String line: lines) {- if (line.endsWith("\r"))- line = line.substring(0, line.length()-1);- processedLines.add(line);- }- return new GitText(processedLines, hasEolAtEof, charset);- }-- public GitText ignoreEOLSpaces() {- List<String> processedLines = new ArrayList<>();- for (String line: lines)- processedLines.add(StringUtils.stripEnd(line, " \t\r"));- return new GitText(processedLines, hasEolAtEof, charset);- }-- public GitText ignoreChangeSpaces() {- List<String> processedLines = new ArrayList<>();- for (String line: lines) {- line = WHITESPACE_PATTERN.matcher(line.trim()).replaceAll(" ");- processedLines.add(line);- }- return new GitText(processedLines, hasEolAtEof, charset);- }-- /**- * Read text from specified bytes. This method only treats "\n" as EOL character,- * and any occurrences of "\r" will be preserved in read result. This method is- * intended to read text files for comparison purpose.- *- * @param bytes- * bytes to read lines from- * @return- * resulting GitText, <tt>null</tt> if charset can not be detected- */- public static @Nullable GitText from(byte[] bytes) {- Charset charset = Charsets.detectFrom(bytes);- if (charset != null) {- List<String> lines = new ArrayList<>();- StringBuilder builder = new StringBuilder();- String string = new String(bytes, charset);- for (int i=0; i<string.length(); i++) {- char ch = string.charAt(i);- if (ch == '\n') {- lines.add(builder.toString());- builder = new StringBuilder();- } else {- builder.append(ch);- }- }- if (builder.length() != 0) {- lines.add(builder.toString());- return new GitText(lines, false, charset.name());- } else {- return new GitText(lines, true, charset.name());- }- } else {- return null;- }- }--}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.javaindex 3fc7aa3bab..9a8d05bc69 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@@ -1,9 +1,12 @@package com.pmease.commons.git;+import java.util.Date;import java.util.regex.Pattern;import org.apache.commons.lang3.StringUtils;import org.eclipse.jgit.lib.FileMode;+import org.eclipse.jgit.lib.PersonIdent;+import org.eclipse.jgit.util.SystemReader;import com.google.common.base.Objects;import com.google.common.base.Preconditions;@@ -43,5 +46,10 @@ public class GitUtils {elsereturn "Folder";}++ public static PersonIdent newPersonIdent(String name, String email, Date when) {+ return new PersonIdent(name, email, when.getTime(),+ SystemReader.getInstance().getTimezone(when.getTime()));+ }}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.javanew file mode 100644index 0000000000..7ba33ea335--- /dev/null+++ b/commons.git/src/main/java/com/pmease/commons/git/RevAwareChange.java@@ -0,0 +1,43 @@+package com.pmease.commons.git;++import javax.annotation.Nullable;++@SuppressWarnings("serial")+public class RevAwareChange extends Change {++ private final String oldRevision;++ private final String newRevision;++ public RevAwareChange(Change change, @Nullable String oldRevision, @Nullable String newRevision) {+ super(change);+ this.oldRevision = oldRevision;+ this.newRevision = newRevision;+ }++ public RevAwareChange(Status status, @Nullable String oldPath, @Nullable String newPath, int oldMode, int newMode,+ @Nullable String oldRevision, @Nullable String newRevision) {+ super(status, oldPath, newPath, oldMode, newMode);+ this.oldRevision = oldRevision;+ this.newRevision = newRevision;+ }++ @Nullable+ public String getOldRevision() {+ return oldRevision;+ }++ @Nullable+ public String getNewRevision() {+ return newRevision;+ }++ public BlobInfo getOldBlobInfo() {+ return new BlobInfo(oldRevision, getOldPath(), getOldMode());+ }++ public BlobInfo getNewBlobInfo() {+ return new BlobInfo(newRevision, getNewPath(), getNewMode());+ }++}\ No newline at end of filediff --git a/commons.git/src/main/java/com/pmease/commons/git/command/BlameCommand.java b/commons.git/src/main/java/com/pmease/commons/git/command/BlameCommand.javaindex 86b3f924dc..099710cd82 100644--- a/commons.git/src/main/java/com/pmease/commons/git/command/BlameCommand.java+++ b/commons.git/src/main/java/com/pmease/commons/git/command/BlameCommand.java@@ -14,7 +14,7 @@ import org.slf4j.LoggerFactory;import com.google.common.base.Preconditions;import com.pmease.commons.git.Blame;import com.pmease.commons.git.BriefCommit;-import com.pmease.commons.git.Git;+import com.pmease.commons.git.GitUtils;import com.pmease.commons.util.execution.Commandline;import com.pmease.commons.util.execution.ExecuteResult;import com.pmease.commons.util.execution.LineConsumer;@@ -187,8 +187,8 @@ public class BlameCommand extends GitCommand<List<Blame>> {private BriefCommit build() {return new BriefCommit(hash,- Git.newPersonIdent(committer, committerEmail, committerDate),- Git.newPersonIdent(author, authorEmail, authorDate),+ GitUtils.newPersonIdent(committer, committerEmail, committerDate),+ GitUtils.newPersonIdent(author, authorEmail, authorDate),summary.trim());}}diff --git a/commons.git/src/main/java/com/pmease/commons/git/command/LogCommand.java b/commons.git/src/main/java/com/pmease/commons/git/command/LogCommand.javaindex 463057ed6c..114ab29122 100644--- a/commons.git/src/main/java/com/pmease/commons/git/command/LogCommand.java+++ b/commons.git/src/main/java/com/pmease/commons/git/command/LogCommand.java@@ -13,7 +13,7 @@ import org.slf4j.LoggerFactory;import com.pmease.commons.git.Commit;import com.pmease.commons.git.Change;-import com.pmease.commons.git.Git;+import com.pmease.commons.git.GitUtils;import com.pmease.commons.util.execution.Commandline;import com.pmease.commons.util.execution.LineConsumer;@@ -210,12 +210,13 @@ public class LogCommand extends GitCommand<List<Commit>> {private Commit build() {return new Commit(hash,- Git.newPersonIdent(committerName, committerEmail, committerDate),- Git.newPersonIdent(authorName, authorEmail, authorDate),+ GitUtils.newPersonIdent(committerName, committerEmail, committerDate),+ GitUtils.newPersonIdent(authorName, authorEmail, authorDate),summary.trim(),StringUtils.isNotBlank(message)?message.trim():null,StringUtils.isNotBlank(note)?note.trim():null,parentHashes, fileChanges);}}+}diff --git a/commons.git/src/main/java/com/pmease/commons/git/command/MoveCommand.java b/commons.git/src/main/java/com/pmease/commons/git/command/MoveCommand.javanew file mode 100644index 0000000000..169f0b9f9b--- /dev/null+++ b/commons.git/src/main/java/com/pmease/commons/git/command/MoveCommand.java@@ -0,0 +1,60 @@+package com.pmease.commons.git.command;++import java.io.File;++import org.slf4j.Logger;+import org.slf4j.LoggerFactory;++import com.google.common.base.Preconditions;+import com.pmease.commons.util.execution.Commandline;+import com.pmease.commons.util.execution.LineConsumer;++public class MoveCommand extends GitCommand<Void> {++ private static final Logger logger = LoggerFactory.getLogger(MoveCommand.class);++ private String source;++ private String destination;++ public MoveCommand(File repoDir) {+ super(repoDir);+ }++ public MoveCommand source(String source) {+ this.source = source;+ return this;+ }++ public MoveCommand destination(String destination) {+ this.destination = destination;+ return this;+ }++ @Override+ public Void call() {+ Preconditions.checkNotNull(source, "source has to be specified.");+ Preconditions.checkNotNull(destination, "destination has to be specified.");++ Commandline cmd = cmd().addArgs("mv", source, destination);++ cmd.execute(new LineConsumer() {++ @Override+ public void consume(String line) {+ logger.debug(line);+ }++ }, new LineConsumer() {++ @Override+ public void consume(String line) {+ logger.error(line);+ }++ }).checkReturnCode();++ return null;+ }++}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/extensionpoint/TextConverter.java b/commons.git/src/main/java/com/pmease/commons/git/extensionpoint/TextConverter.javasimilarity index 67%rename from gitplex.web/src/main/java/com/pmease/gitplex/web/extensionpoint/TextConverter.javarename to commons.git/src/main/java/com/pmease/commons/git/extensionpoint/TextConverter.javaindex 4d0fe059d9..4807ba9e4e 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/extensionpoint/TextConverter.java+++ b/commons.git/src/main/java/com/pmease/commons/git/extensionpoint/TextConverter.java@@ -1,4 +1,4 @@-package com.pmease.gitplex.web.extensionpoint;+package com.pmease.commons.git.extensionpoint;import java.util.List;diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/extensionpoint/TextConverterProvider.java b/commons.git/src/main/java/com/pmease/commons/git/extensionpoint/TextConverterProvider.javasimilarity index 84%rename from gitplex.web/src/main/java/com/pmease/gitplex/web/extensionpoint/TextConverterProvider.javarename to commons.git/src/main/java/com/pmease/commons/git/extensionpoint/TextConverterProvider.javaindex 0cdb0c64b2..e8fc41aabb 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/extensionpoint/TextConverterProvider.java+++ b/commons.git/src/main/java/com/pmease/commons/git/extensionpoint/TextConverterProvider.java@@ -1,4 +1,4 @@-package com.pmease.gitplex.web.extensionpoint;+package com.pmease.commons.git.extensionpoint;import javax.annotation.Nullable;import org.apache.tika.mime.MediaType;diff --git a/commons.git/src/test/java/com/pmease/commons/git/GitTextTest.java b/commons.git/src/test/java/com/pmease/commons/git/GitTextTest.javaindex d4a52cc031..cf1d525eb4 100644--- a/commons.git/src/test/java/com/pmease/commons/git/GitTextTest.java+++ b/commons.git/src/test/java/com/pmease/commons/git/GitTextTest.java@@ -9,7 +9,7 @@ public class GitTextTest {@Testpublic void test() {- GitText result = GitText.from(" hello \tworld \t \r".getBytes());+ BlobText result = BlobText.from(" hello \tworld \t \r".getBytes());assertNotNull(result);assertEquals(" hello \tworld \t ", result.ignoreEOL().getLines().get(0));assertEquals(" hello \tworld", result.ignoreEOLSpaces().getLines().get(0));diff --git a/commons.git/src/test/java/com/pmease/commons/git/GitUtilsTest.java b/commons.git/src/test/java/com/pmease/commons/git/GitUtilsTest.javaindex 7115a0faeb..8813c69ff9 100644--- a/commons.git/src/test/java/com/pmease/commons/git/GitUtilsTest.java+++ b/commons.git/src/test/java/com/pmease/commons/git/GitUtilsTest.java@@ -6,17 +6,17 @@ import org.junit.Test;import com.google.common.collect.Lists;-public class GitUtilsTest {+public class GitUtilsTest extends AbstractGitTest {@Testpublic void testReadLines() {String content = "中文测试\r\nsecond line";- GitText result = GitText.from(content.getBytes());+ BlobText result = BlobText.from(content.getBytes());assertEquals(Lists.newArrayList("中文测试\r", "second line"), result.getLines());assertEquals(false, result.isHasEolAtEof());- result = GitText.from("\nhello\n\nworld\n".getBytes());+ result = BlobText.from("\nhello\n\nworld\n".getBytes());assertEquals(Lists.newArrayList("", "hello", "", "world"), result.getLines());}-+}diff --git a/commons.git/src/test/java/com/pmease/commons/git/command/ListTreeCommandTest.java b/commons.git/src/test/java/com/pmease/commons/git/command/ListTreeCommandTest.javaindex 24341a3aba..d70a462b58 100644--- a/commons.git/src/test/java/com/pmease/commons/git/command/ListTreeCommandTest.java+++ b/commons.git/src/test/java/com/pmease/commons/git/command/ListTreeCommandTest.java@@ -10,6 +10,7 @@ import org.eclipse.jgit.lib.FileMode;import org.junit.Test;import com.pmease.commons.git.AbstractGitTest;+import com.pmease.commons.git.BlobInfo;import com.pmease.commons.git.Git;import com.pmease.commons.git.TreeNode;import com.pmease.commons.util.FileUtils;@@ -50,7 +51,8 @@ public class ListTreeCommandTest extends AbstractGitTest {assertEquals(FileMode.TYPE_TREE, treeNodes.get(0).getMode());TreeNode node = treeNodes.get(6);- String submoduleInfo = new String(bareGit.read("master", node.getPath(), node.getMode()));+ BlobInfo blobInfo = new BlobInfo("master", node.getPath(), node.getMode());+ String submoduleInfo = new String(bareGit.readBlob(blobInfo));String submodulePath = new File(StringUtils.substringBeforeLast(submoduleInfo, ":")).getCanonicalPath();String submoduleCommit = StringUtils.substringAfterLast(submoduleInfo, ":");assertEquals(moduleGit.repoDir().getAbsolutePath(), submodulePath);@@ -64,7 +66,8 @@ public class ListTreeCommandTest extends AbstractGitTest {assertEquals("file", treeNodes.get(0).getName());TreeNode fileNode = treeNodes.get(0);- assertEquals("hello world", new String(bareGit.read("master", fileNode.getPath(), fileNode.getMode())));+ blobInfo = new BlobInfo("master", fileNode.getPath(), fileNode.getMode());+ assertEquals("hello world", new String(bareGit.readBlob(blobInfo)));}}diff --git a/commons.util/src/main/java/com/pmease/commons/util/diff/DiffUtils.java b/commons.util/src/main/java/com/pmease/commons/util/diff/DiffUtils.javaindex 794e065ba7..d33c009e2f 100644--- a/commons.util/src/main/java/com/pmease/commons/util/diff/DiffUtils.java+++ b/commons.util/src/main/java/com/pmease/commons/util/diff/DiffUtils.java@@ -153,9 +153,9 @@ public class DiffUtils {} else if (diff.getAction() == DiffLine.Action.DELETE) {originalLine++;} else {+ lineMapping.put(originalLine, revisedLine);revisedLine++;originalLine++;- lineMapping.put(originalLine, revisedLine);}}return lineMapping;diff --git a/commons.util/src/test/java/com/pmease/commons/util/diff/DiffUtilsTest.java b/commons.util/src/test/java/com/pmease/commons/util/diff/DiffUtilsTest.javaindex b3e8c01f01..979c213832 100644--- a/commons.util/src/test/java/com/pmease/commons/util/diff/DiffUtilsTest.java+++ b/commons.util/src/test/java/com/pmease/commons/util/diff/DiffUtilsTest.java@@ -224,11 +224,11 @@ public class DiffUtilsTest {"line 6"};Map<Integer, Integer> map = DiffUtils.mapLines(Arrays.asList(original), Arrays.asList(revised));- assertTrue(map.get(1) == 1);- assertTrue(map.get(2) == null);- assertTrue(map.get(3) == 3);+ assertTrue(map.get(0) == 0);+ assertTrue(map.get(1) == null);+ assertTrue(map.get(2) == 2);+ assertTrue(map.get(3) == 4);assertTrue(map.get(4) == 5);assertTrue(map.get(5) == 6);- assertTrue(map.get(6) == 7);}}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/BlobLoader.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/BlobLoader.javanew file mode 100644index 0000000000..19a5632606--- /dev/null+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/BlobLoader.java@@ -0,0 +1,22 @@+package com.pmease.gitplex.core.comment;++import java.util.List;++import javax.annotation.Nullable;++import com.pmease.commons.git.BlobInfo;++public interface BlobLoader {++ /**+ * Load content of specified blob and convert to lines.+ *+ * @param blobInfo+ * blob info to load+ * @return+ * lines of the blob, or null if the blob content can not be+ * converted to text+ */+ @Nullable+ List<String> loadBlob(BlobInfo blobInfo);+}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/ChangeComments.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/ChangeComments.javanew file mode 100644index 0000000000..a92ebfd11d--- /dev/null+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/ChangeComments.java@@ -0,0 +1,208 @@+package com.pmease.gitplex.core.comment;++import java.io.Serializable;+import java.util.ArrayList;+import java.util.Date;+import java.util.HashMap;+import java.util.HashSet;+import java.util.LinkedHashMap;+import java.util.List;+import java.util.Map;+import java.util.Set;++import javax.annotation.Nullable;++import com.pmease.commons.git.BlobInfo;+import com.pmease.commons.git.RevAwareChange;+import com.pmease.commons.util.Pair;+import com.pmease.commons.util.diff.DiffUtils;+import com.pmease.gitplex.core.model.CommentPosition;+import com.pmease.gitplex.core.model.CommitComment;++@SuppressWarnings("serial")+public class ChangeComments implements Serializable {++ private final Map<String, Date> commits;++ private Map<Integer, List<CommitComment>> oldComments;++ private Map<Integer, List<CommitComment>> newComments;++ public ChangeComments(RevAwareChange change, LinkedHashMap<String, Date> commits,+ CommentLoader commentLoader, BlobLoader blobLoader) {++ 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());+ if (end != -1 && getBlob(blobs, change.getNewBlobInfo(), blobLoader).isEmpty())+ end = -1;+ }++ if (begin != -1) {+ oldComments = new HashMap<>();++ 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.getOldPath());+ if (commentsOnFile != null) {+ blobInfo = new BlobInfo(commit, change.getOldPath(), change.getOldMode());+ } else {+ commentsOnFile = commentsOnCommit.get(change.getNewPath());+ if (commentsOnFile != null)+ blobInfo = new BlobInfo(commit, change.getNewPath(), change.getNewMode());+ }++ if (blobInfo != null) {+ List<String> fileContent = blobLoader.loadBlob(blobInfo);+ if (!fileContent.isEmpty()) {+ List<String> oldContent = getBlob(blobs, change.getOldBlobInfo(), blobLoader);+ Map<Integer, Integer> lineMap = DiffUtils.mapLines(fileContent, oldContent);+ for (CommitComment comment: commentsOnFile) {+ Integer lineNo = lineMap.get(comment.getPosition().getLineNo());+ if (lineNo != null)+ addLineComment(oldComments, lineNo, comment);+ }+ }+ }+ }++ List<CommitComment> commentsOnFile = getCommentsOnCommit(comments, change.getOldRevision(), commentLoader).get(change.getOldPath());+ if (commentsOnFile != null) {+ for (CommitComment comment: commentsOnFile)+ addLineComment(oldComments, comment.getPosition().getLineNo(), comment);+ }+ }++ if (end != -1) {+ newComments = new HashMap<>();++ Set<CommentKey> appliedComments = new HashSet<>();+ if (oldComments != null) {+ for (List<CommitComment> list: oldComments.values()) {+ for (CommitComment comment: list)+ appliedComments.add(new CommentKey(comment.getCommit(), comment.getPosition()));+ }+ }+ 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.getNewPath());+ if (commentsOnFile != null) {+ blobInfo = new BlobInfo(commit, change.getNewPath(), change.getNewMode());+ } else {+ commentsOnFile = commentsOnCommit.get(change.getOldPath());+ if (commentsOnFile != null)+ blobInfo = new BlobInfo(commit, change.getOldPath(), change.getOldMode());+ }++ if (blobInfo != null) {+ boolean allApplied = true;+ for (CommitComment comment: commentsOnFile) {+ CommentKey key = new CommentKey(comment.getCommit(), comment.getPosition());+ if (!appliedComments.contains(key)) {+ allApplied = false;+ break;+ }+ }+ if (!allApplied) {+ List<String> fileContent = getBlob(blobs, blobInfo, blobLoader);+ if (!fileContent.isEmpty()) {+ List<String> newContent = getBlob(blobs, change.getNewBlobInfo(), blobLoader);+ Map<Integer, Integer> lineMap = DiffUtils.mapLines(fileContent, newContent);+ 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);+ }+ }+ }+ }+ }++ List<CommitComment> commentsOnFile = getCommentsOnCommit(comments, change.getNewRevision(), commentLoader).get(change.getNewPath());+ if (commentsOnFile != null) {+ for (CommitComment comment: commentsOnFile)+ addLineComment(newComments, comment.getPosition().getLineNo(), comment);+ }+ }++ }++ private void addLineComment(Map<Integer, List<CommitComment>> comments, int lineNo, CommitComment comment) {+ List<CommitComment> commentsOnLine = comments.get(lineNo);+ if (commentsOnLine == null) {+ commentsOnLine = new ArrayList<>();+ comments.put(lineNo, commentsOnLine);+ }+ commentsOnLine.add(comment);+ }++ private Map<String, List<CommitComment>> getCommentsOnCommit(Map<String, Map<String, List<CommitComment>>> comments,+ String commit, CommentLoader commentLoader) {+ Map<String, List<CommitComment>> commentsOnCommit = comments.get(commit);+ if (commentsOnCommit == null) {+ commentsOnCommit = new HashMap<>();+ for (CommitComment each: commentLoader.loadComments(commit)) {+ if (each.getPosition() != null && each.getPosition().getLineNo() != null) {+ List<CommitComment> commentsOnFile = commentsOnCommit.get(each.getPosition().getFilePath());+ if (commentsOnFile == null) {+ commentsOnFile = new ArrayList<>();+ commentsOnCommit.put(each.getPosition().getFilePath(), commentsOnFile);+ }+ commentsOnFile.add(each);+ }+ }+ comments.put(commit, commentsOnCommit);+ }+ return commentsOnCommit;+ }++ @Nullable+ public Map<Integer, List<CommitComment>> getOldComments() {+ return oldComments;+ }++ @Nullable+ public Map<Integer, List<CommitComment>> getNewComments() {+ return newComments;+ }++ public Map<String, Date> getCommits() {+ return commits;+ }++ private List<String> getBlob(Map<BlobInfo, List<String>> blobs, BlobInfo blobInfo, BlobLoader blobLoader) {+ List<String> blob = blobs.get(blobInfo);+ if (blob == null) {+ blob = blobLoader.loadBlob(blobInfo);+ if (blob == null)+ blob = new ArrayList<>();+ blobs.put(blobInfo, blob);+ }+ return blob;+ }++ private static class CommentKey extends Pair<String, CommentPosition> {++ public CommentKey(String commit, CommentPosition position) {+ super(commit, position);+ }++ }+}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/ChangeLoader.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/ChangeLoader.javanew file mode 100644index 0000000000..060599b628--- /dev/null+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/ChangeLoader.java@@ -0,0 +1,9 @@+package com.pmease.gitplex.core.comment;++import java.util.List;++import com.pmease.commons.git.Change;++public interface ChangeLoader {+ List<Change> loadChanges(String fromRev, String toRev);+}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/CommentLoader.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/CommentLoader.javanew file mode 100644index 0000000000..b82edabbfb--- /dev/null+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/CommentLoader.java@@ -0,0 +1,20 @@+package com.pmease.gitplex.core.comment;++import java.util.List;++import com.pmease.gitplex.core.model.CommitComment;++public interface CommentLoader {+ /**+ * Load list of comments on specified commit, ordered by comment id.+ *+ * @param commit+ * commit to load comments for+ * @return+ * list of commit comments on specified commit ordered by comment id,+ * including comments on commit itself, comments on files in the commit,+ * and comments on file lines in the commit. Empty list should be+ * returned if there are no any comments on specified commit+ */+ List<CommitComment> loadComments(String commit);+}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/CommentThread.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/CommentThread.javanew file mode 100644index 0000000000..beb453a143--- /dev/null+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/CommentThread.java@@ -0,0 +1,64 @@+package com.pmease.gitplex.core.comment;++import java.util.ArrayList;+import java.util.Collections;+import java.util.HashMap;+import java.util.List;+import java.util.Map;++import javax.annotation.Nullable;++import com.pmease.gitplex.core.model.CommentPosition;+import com.pmease.gitplex.core.model.CommitComment;++public class CommentThread implements Comparable<CommentThread> {++ private final CommentPosition position;++ private final List<CommitComment> comments;++ public CommentThread(@Nullable CommentPosition position, List<CommitComment> comments) {+ this.position = position;+ this.comments = comments;+ }++ public CommentPosition getPosition() {+ return position;+ }++ public List<CommitComment> getComments() {+ return comments;+ }++ public CommitComment getFirstComment() {+ return comments.get(0);+ }++ public CommitComment getLastComment() {+ return comments.get(comments.size()-1);+ }++ @Override+ public int compareTo(CommentThread o) {+ return getLastComment().getId().compareTo(o.getLastComment().getId());+ }++ public static List<CommentThread> asThreads(List<CommitComment> comments) {+ Map<CommentPosition, List<CommitComment>> threadMap = new HashMap<>();+ for (CommitComment comment: comments) {+ List<CommitComment> threadComments = threadMap.get(comment.getPosition());+ if (threadComments == null) {+ threadComments = new ArrayList<>();+ threadMap.put(comment.getPosition(), threadComments);+ }+ threadComments.add(comment);+ }++ List<CommentThread> threads = new ArrayList<>();+ for (Map.Entry<CommentPosition, List<CommitComment>> entry: threadMap.entrySet())+ threads.add(new CommentThread(entry.getKey(), entry.getValue()));++ Collections.sort(threads);+ return threads;+ }+}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/hookcallback/GitPostReceiveCallback.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/hookcallback/GitPostReceiveCallback.javaindex ac20e277eb..7f51e28439 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/hookcallback/GitPostReceiveCallback.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/hookcallback/GitPostReceiveCallback.java@@ -18,7 +18,7 @@ import org.slf4j.Logger;import org.slf4j.LoggerFactory;import com.google.common.base.Preconditions;-import com.pmease.commons.git.Commit;+import com.pmease.commons.git.GitUtils;import com.pmease.commons.hibernate.dao.Dao;import com.pmease.commons.util.StringUtils;import com.pmease.gitplex.core.manager.BranchManager;@@ -101,7 +101,7 @@ public class GitPostReceiveCallback extends HttpServlet {private void onRefUpdated(Repository repository, String refName, String oldCommitHash, final String newCommitHash) {String branchName = Branch.parseName(refName);if (branchName != null) {- if (oldCommitHash.equals(Commit.ZERO_HASH)) {+ if (oldCommitHash.equals(GitUtils.NULL_SHA1)) {Branch branch = new Branch();branch.setRepository(repository);branch.setName(branchName);@@ -111,7 +111,7 @@ public class GitPostReceiveCallback extends HttpServlet {dao.persist(branch);if (repository.getBranches().size() == 1)repository.git().updateDefaultBranch(branchName);- } else if (newCommitHash.equals(Commit.ZERO_HASH)) {+ } else if (newCommitHash.equals(GitUtils.NULL_SHA1)) {Branch branch = branchManager.findBy(repository, branchName);Preconditions.checkNotNull(branch);diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/hookcallback/GitUpdateCallback.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/hookcallback/GitUpdateCallback.javaindex d319dc7f49..b27adbe09d 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/hookcallback/GitUpdateCallback.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/hookcallback/GitUpdateCallback.java@@ -19,7 +19,7 @@ import org.slf4j.Logger;import org.slf4j.LoggerFactory;import com.google.common.base.Preconditions;-import com.pmease.commons.git.Commit;+import com.pmease.commons.git.GitUtils;import com.pmease.commons.hibernate.dao.Dao;import com.pmease.commons.util.StringUtils;import com.pmease.gitplex.core.gatekeeper.GateKeeper;@@ -117,13 +117,13 @@ public class GitUpdateCallback extends HttpServlet {} else {String branchName = Branch.parseName(refName);if (branchName != null) { // push branch ref- if (oldCommitHash.equals(Commit.ZERO_HASH)) { // create new branch+ if (oldCommitHash.equals(GitUtils.NULL_SHA1)) { // create new branchcheckRef(user, repository, refName, output);} else {Branch branch = branchManager.findBy(repository, branchName);Preconditions.checkNotNull(branch);- if (newCommitHash.equals(Commit.ZERO_HASH)) { // deleting a branch ref+ if (newCommitHash.equals(GitUtils.NULL_SHA1)) { // deleting a branch refGateKeeper gateKeeper = repository.getGateKeeper();CheckResult checkResult = gateKeeper.checkBranch(user, branch);@@ -141,7 +141,7 @@ public class GitUpdateCallback extends HttpServlet {List<String> messages = new ArrayList<>();for (String each: checkResult.getReasons())messages.add(each);- if (!newCommitHash.equals(Commit.ZERO_HASH) && !(checkResult instanceof Disapproved)) {+ if (!newCommitHash.equals(GitUtils.NULL_SHA1) && !(checkResult instanceof Disapproved)) {messages.add("");messages.add("----------------------------------------------------");messages.add("You may submit a pull request instead.");diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CommentVisitManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CommentVisitManager.javanew file mode 100644index 0000000000..fd0b7462f2--- /dev/null+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CommentVisitManager.java@@ -0,0 +1,33 @@+package com.pmease.gitplex.core.manager;++import java.util.Date;+import java.util.List;++import javax.annotation.Nullable;++import com.google.inject.ImplementedBy;+import com.pmease.gitplex.core.manager.impl.DefaultCommentVisitManager;+import com.pmease.gitplex.core.model.Repository;+import com.pmease.gitplex.core.model.CommentVisit;++@ImplementedBy(DefaultCommentVisitManager.class)+public interface CommentVisitManager {++ /**+ * Find comment visits by specified commit date range.+ *+ * @param repository+ * repository to find comment inside+ * @param fromDate+ * from date of associated commit+ * @param toDate+ * to date of associated commit+ * @return+ * list of found comment visits+ */+ List<CommentVisit> findByCommitDates(Repository repository, @Nullable Date fromDate, @Nullable Date toDate);++ List<CommentVisit> findByCommitOrDates(Repository repository, String commit,+ @Nullable Date fromDate, @Nullable Date toDate);++}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CommitCommentManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CommitCommentManager.javaindex 396f663346..2fefddc6ca 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CommitCommentManager.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CommitCommentManager.java@@ -1,7 +1,10 @@package com.pmease.gitplex.core.manager;+import java.util.Date;import java.util.List;+import javax.annotation.Nullable;+import com.google.inject.ImplementedBy;import com.pmease.gitplex.core.manager.impl.DefaultCommitCommentManager;import com.pmease.gitplex.core.model.CommitComment;@@ -47,4 +50,22 @@ public interface CommitCommentManager {* list of comments ordered by id*/List<CommitComment> findByCommitAndFile(Repository repository, String commit, String file);++ /**+ * Find comments by specified commit date range.+ *+ * @param repository+ * repository to find comment inside+ * @param fromDate+ * from date of associated commit+ * @param toDate+ * to date of associated commit+ * @return+ * list of found comments ordered by id+ */+ List<CommitComment> findByCommitDates(Repository repository, @Nullable Date fromDate, @Nullable Date toDate);++ List<CommitComment> findByCommitOrDates(Repository repository, String commit,+ @Nullable Date fromDate, @Nullable Date toDate);+}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/ThreadVisitManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/ThreadVisitManager.javadeleted file mode 100644index d0402b7d3f..0000000000--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/ThreadVisitManager.java+++ /dev/null@@ -1,25 +0,0 @@-package com.pmease.gitplex.core.manager;--import java.util.Date;-import java.util.Map;--import com.google.inject.ImplementedBy;-import com.pmease.gitplex.core.manager.impl.DefaultThreadVisitManager;-import com.pmease.gitplex.core.model.CommentPosition;-import com.pmease.gitplex.core.model.Repository;--@ImplementedBy(DefaultThreadVisitManager.class)-public interface ThreadVisitManager {-- /**- * Calculate map of visited comment position to date.- *- * @param repository- * repository to calculate visit map inside- * @param commit- * commit to calculate visit map for- * @return- * map of comment position to last visit date- */- Map<CommentPosition, Date> calcVisitMap(Repository repository, String commit);-}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCommentVisitManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCommentVisitManager.javanew file mode 100644index 0000000000..a902ea5bf2--- /dev/null+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCommentVisitManager.java@@ -0,0 +1,56 @@+package com.pmease.gitplex.core.manager.impl;++import java.util.Date;+import java.util.List;++import javax.inject.Inject;+import javax.inject.Singleton;++import org.hibernate.criterion.Conjunction;+import org.hibernate.criterion.Order;+import org.hibernate.criterion.Restrictions;++import com.pmease.commons.hibernate.dao.Dao;+import com.pmease.commons.hibernate.dao.EntityCriteria;+import com.pmease.gitplex.core.manager.CommentVisitManager;+import com.pmease.gitplex.core.model.Repository;+import com.pmease.gitplex.core.model.CommentVisit;++@Singleton+public class DefaultCommentVisitManager implements CommentVisitManager {++ private final Dao dao;++ @Inject+ public DefaultCommentVisitManager(Dao dao) {+ this.dao = dao;+ }++ @Override+ public List<CommentVisit> findByCommitDates(Repository repository, Date fromDate, Date toDate) {+ EntityCriteria<CommentVisit> criteria = EntityCriteria.of(CommentVisit.class);+ criteria.add(Restrictions.eq("repository", repository));+ if (fromDate != null)+ criteria.add(Restrictions.ge("commitDate", fromDate));+ if (toDate != null)+ criteria.add(Restrictions.le("commitDate", toDate));+ criteria.addOrder(Order.asc("id"));+ return dao.query(criteria, 0, 0);+ }++ @Override+ public List<CommentVisit> findByCommitOrDates(Repository repository,+ String commit, Date fromDate, Date toDate) {+ EntityCriteria<CommentVisit> criteria = EntityCriteria.of(CommentVisit.class);+ criteria.add(Restrictions.eq("repository", repository));+ Conjunction conjunction = Restrictions.conjunction();+ if (fromDate != null)+ conjunction.add(Restrictions.ge("commitDate", fromDate));+ if (toDate != null)+ conjunction.add(Restrictions.le("commitDate", toDate));+ criteria.add(Restrictions.or(Restrictions.eq("commit", commit), conjunction));+ criteria.addOrder(Order.asc("id"));+ return dao.query(criteria, 0, 0);+ }++}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCommitCommentManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCommitCommentManager.javaindex ccf88ca4ab..6954f87731 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCommitCommentManager.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCommitCommentManager.java@@ -1,10 +1,12 @@package com.pmease.gitplex.core.manager.impl;+import java.util.Date;import java.util.List;import javax.inject.Inject;import javax.inject.Singleton;+import org.hibernate.criterion.Conjunction;import org.hibernate.criterion.Order;import org.hibernate.criterion.Restrictions;@@ -52,4 +54,31 @@ public class DefaultCommitCommentManager implements CommitCommentManager {.addOrder(Order.asc("id")), 0, 0);}+ @Override+ public List<CommitComment> findByCommitDates(Repository repository, Date fromDate, Date toDate) {+ EntityCriteria<CommitComment> criteria = EntityCriteria.of(CommitComment.class);+ criteria.add(Restrictions.eq("repository", repository));+ if (fromDate != null)+ criteria.add(Restrictions.ge("commitDate", fromDate));+ if (toDate != null)+ criteria.add(Restrictions.le("commitDate", toDate));+ criteria.addOrder(Order.asc("id"));+ return dao.query(criteria, 0, 0);+ }++ @Override+ public List<CommitComment> findByCommitOrDates(Repository repository,+ String commit, Date fromDate, Date toDate) {+ EntityCriteria<CommitComment> criteria = EntityCriteria.of(CommitComment.class);+ criteria.add(Restrictions.eq("repository", repository));+ Conjunction conjunction = Restrictions.conjunction();+ if (fromDate != null)+ conjunction.add(Restrictions.ge("commitDate", fromDate));+ if (toDate != null)+ conjunction.add(Restrictions.le("commitDate", toDate));+ criteria.add(Restrictions.or(Restrictions.eq("commit", commit), conjunction));+ criteria.addOrder(Order.asc("id"));+ return dao.query(criteria, 0, 0);+ }+}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultThreadVisitManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultThreadVisitManager.javadeleted file mode 100644index 78667e913a..0000000000--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultThreadVisitManager.java+++ /dev/null@@ -1,44 +0,0 @@-package com.pmease.gitplex.core.manager.impl;--import java.util.Date;-import java.util.HashMap;-import java.util.List;-import java.util.Map;--import javax.inject.Inject;-import javax.inject.Singleton;--import org.hibernate.criterion.Restrictions;--import com.pmease.commons.hibernate.Sessional;-import com.pmease.commons.hibernate.dao.Dao;-import com.pmease.commons.hibernate.dao.EntityCriteria;-import com.pmease.gitplex.core.manager.ThreadVisitManager;-import com.pmease.gitplex.core.model.CommentPosition;-import com.pmease.gitplex.core.model.Repository;-import com.pmease.gitplex.core.model.ThreadVisit;--@Singleton-public class DefaultThreadVisitManager implements ThreadVisitManager {-- private final Dao dao;-- @Inject- public DefaultThreadVisitManager(Dao dao) {- this.dao = dao;- }-- @Sessional- @Override- public Map<CommentPosition, Date> calcVisitMap(Repository repository, String commit) {- Map<CommentPosition, Date> visitMap = new HashMap<>();- List<ThreadVisit> visits = dao.query(EntityCriteria.of(ThreadVisit.class)- .add(Restrictions.eq("repository", repository))- .add(Restrictions.eq("commit", commit)), 0, 0);- for (ThreadVisit visit: visits)- visitMap.put(visit.getPosition(), visit.getDate());-- return visitMap;- }--}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/CommentPosition.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/CommentPosition.javaindex 1f87494214..9a64e48fc2 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/CommentPosition.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/CommentPosition.java@@ -8,6 +8,8 @@ import javax.persistence.Embeddable;import org.apache.commons.lang3.builder.EqualsBuilder;import org.apache.commons.lang3.builder.HashCodeBuilder;+import com.google.common.base.Objects;+@SuppressWarnings("serial")@Embeddablepublic class CommentPosition implements Serializable {@@ -16,7 +18,15 @@ public class CommentPosition implements Serializable {private Integer lineNo;- @Nullable+ public CommentPosition() {++ }++ public CommentPosition(String filePath, Integer lineNo) {+ this.filePath = filePath;+ this.lineNo = lineNo;+ }+public String getFilePath() {return filePath;}@@ -55,4 +65,11 @@ public class CommentPosition implements Serializable {.toHashCode();}+ @Override+ public String toString() {+ return Objects.toStringHelper(CommentPosition.class)+ .add("filePath", filePath)+ .add("lineNo", lineNo)+ .toString();+ }}\ No newline at end of filediff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/ThreadVisit.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/CommentVisit.javasimilarity index 66%rename from gitplex.core/src/main/java/com/pmease/gitplex/core/model/ThreadVisit.javarename to gitplex.core/src/main/java/com/pmease/gitplex/core/model/CommentVisit.javaindex ab0ec387c9..2bc82b9700 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/ThreadVisit.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/CommentVisit.java@@ -8,12 +8,17 @@ import javax.persistence.Embedded;import javax.persistence.Entity;import javax.persistence.JoinColumn;import javax.persistence.ManyToOne;+import javax.persistence.Table;+import javax.persistence.UniqueConstraint;import com.pmease.commons.hibernate.AbstractEntity;@SuppressWarnings("serial")@Entity-public class ThreadVisit extends AbstractEntity {+@Table(uniqueConstraints={+ @UniqueConstraint(columnNames={"repository", "commit", "position.filePath", "position.lineNo"})+})+public class CommentVisit extends AbstractEntity {@ManyToOne@JoinColumn(nullable=false)@@ -22,12 +27,15 @@ public class ThreadVisit extends AbstractEntity {@Column(nullable=false)private String commit;+ @Column(nullable=false)+ private Date commitDate;+@ManyToOne@JoinColumn(nullable=false)private User user;@Column(nullable=false)- private Date date = new Date();+ private Date visitDate = new Date();@Embeddedprivate CommentPosition position;@@ -48,12 +56,12 @@ public class ThreadVisit extends AbstractEntity {this.user = user;}- public Date getDate() {- return date;+ public Date getVisitDate() {+ return visitDate;}- public void setDate(Date date) {- this.date = date;+ public void setVisitDate(Date date) {+ this.visitDate = date;}public String getCommit() {@@ -64,6 +72,14 @@ public class ThreadVisit extends AbstractEntity {this.commit = commit;}+ public Date getCommitDate() {+ return commitDate;+ }++ public void setCommitDate(Date commitDate) {+ this.commitDate = commitDate;+ }+@Nullablepublic CommentPosition getPosition() {return position;diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/CommitComment.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/CommitComment.javaindex 0b7a35034a..43a8e23ead 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/CommitComment.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/CommitComment.java@@ -9,6 +9,7 @@ import javax.persistence.Entity;import javax.persistence.JoinColumn;import javax.persistence.ManyToOne;+import com.google.common.base.Objects;import com.pmease.commons.hibernate.AbstractEntity;@SuppressWarnings("serial")@@ -22,12 +23,15 @@ public class CommitComment extends AbstractEntity {@Column(nullable=false)private String commit;+ @Column(nullable=false)+ private Date commitDate;+@ManyToOne@JoinColumn(nullable=false)private User user;@Column(nullable=false)- private Date date = new Date();+ private Date commentDate = new Date();@Column(nullable=false)private String content;@@ -59,12 +63,20 @@ public class CommitComment extends AbstractEntity {this.content = content;}- public Date getDate() {- return date;+ public Date getCommitDate() {+ return commitDate;+ }++ public void setCommitDate(Date commitDate) {+ this.commitDate = commitDate;}- public void setDate(Date date) {- this.date = date;+ public Date getCommentDate() {+ return commentDate;+ }++ public void setCommentDate(Date commentDate) {+ this.commentDate = commentDate;}public String getCommit() {@@ -84,4 +96,12 @@ public class CommitComment extends AbstractEntity {this.position = position;}+ @Override+ public String toString() {+ return Objects.toStringHelper(CommitComment.class)+ .add("commit", commit)+ .add("position", position)+ .add("content", content)+ .toString();+ }}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 4a4ee3cf64..0473998eee 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@@ -5,8 +5,10 @@ import java.util.Collection;import java.util.Collections;import java.util.Comparator;import java.util.Date;+import java.util.HashMap;import java.util.HashSet;import java.util.List;+import java.util.Map;import java.util.Set;import java.util.concurrent.Callable;@@ -29,12 +31,15 @@ import com.pmease.commons.git.Commit;import com.pmease.commons.git.Git;import com.pmease.commons.hibernate.AbstractEntity;import com.pmease.commons.util.LockUtils;+import com.pmease.gitplex.core.GitPlex;import com.pmease.gitplex.core.gatekeeper.checkresult.Approved;import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;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;@SuppressWarnings("serial")@Entity@@ -106,7 +111,7 @@ public class PullRequest extends AbstractEntity {private Collection<Verification> verifications = new ArrayList<Verification>();@OneToMany(mappedBy = "request", cascade = CascadeType.REMOVE)- private Collection<PullRequestComment> comments = new ArrayList<PullRequestComment>();+ private Collection<PullRequestComment> requestComments = new ArrayList<PullRequestComment>();private transient List<PullRequestUpdate> sortedUpdates;@@ -116,6 +121,10 @@ public class PullRequest extends AbstractEntity {private transient Set<String> pendingCommits;+ private transient Map<String, List<CommitComment>> commitComments;++ private transient Map<String, Map<CommentPosition, Date>> commentVisits;+/*** Get title of this merge request.*@@ -241,12 +250,12 @@ public class PullRequest extends AbstractEntity {this.verifications = verifications;}- public Collection<PullRequestComment> getComments() {- return comments;+ public Collection<PullRequestComment> getRequestComments() {+ return requestComments;}- public void setComments(Collection<PullRequestComment> comments) {- this.comments = comments;+ public void setRequestComments(Collection<PullRequestComment> requestComments) {+ this.requestComments = requestComments;}public Status getStatus() {@@ -513,4 +522,52 @@ public class PullRequest extends AbstractEntity {&& getIntegrationInfo().getIntegrationHead() != null;}+ public Map<String, List<CommitComment>> getCommitComments() {+ if (commitComments == null) {+ commitComments = new HashMap<>();+ Map<String, Date> commits = new HashMap<>();+ for (PullRequestUpdate update: updates) {+ for (Commit commit: update.getCommits())+ commits.put(commit.getHash(), commit.getCommitter().getWhen());+ }+ CommitCommentManager manager = GitPlex.getInstance(CommitCommentManager.class);+ for (CommitComment comment: manager.findByCommitOrDates(getTarget().getRepository(),+ getBaseCommit(), Collections.min(commits.values()), Collections.max(commits.values()))) {+ if (comment.getCommit().equals(getBaseCommit()) || commits.containsKey(comment.getCommit())) {+ List<CommitComment> comments = commitComments.get(comment.getCommit());+ if (comments == null) {+ comments = new ArrayList<>();+ commitComments.put(comment.getCommit(), comments);+ }+ comments.add(comment);+ }+ }+ }+ return commitComments;+ }++ public Map<String, Map<CommentPosition, Date>> getCommentVisits() {+ if (commentVisits == null) {+ commentVisits = new HashMap<>();+ Map<String, Date> commits = new HashMap<>();+ for (PullRequestUpdate update: updates) {+ for (Commit commit: update.getCommits())+ commits.put(commit.getHash(), commit.getCommitter().getWhen());+ }+ CommentVisitManager manager = GitPlex.getInstance(CommentVisitManager.class);+ for (CommentVisit visit: manager.findByCommitOrDates(getTarget().getRepository(),+ getBaseCommit(), Collections.min(commits.values()), Collections.max(commits.values()))) {+ if (visit.getCommit().equals(getBaseCommit()) || commits.containsKey(visit.getCommit())) {+ Map<CommentPosition, Date> visits = commentVisits.get(visit.getCommit());+ if (visits == null) {+ visits = new HashMap<>();+ commentVisits.put(visit.getCommit(), visits);+ }+ visits.put(visit.getPosition(), visit.getVisitDate());+ }+ }+ }+ 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 ccceb4da6b..e416359365 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@@ -5,7 +5,9 @@ import java.io.IOException;import java.util.ArrayList;import java.util.Collection;import java.util.Date;+import java.util.HashMap;import java.util.List;+import java.util.Map;import javax.annotation.Nullable;import javax.persistence.CascadeType;@@ -20,21 +22,24 @@ import javax.persistence.UniqueConstraint;import javax.validation.Valid;import javax.validation.constraints.NotNull;-import com.pmease.gitplex.core.GitPlex;-import com.pmease.gitplex.core.gatekeeper.AndGateKeeper;-import com.pmease.gitplex.core.gatekeeper.GateKeeper;-import com.pmease.gitplex.core.manager.StorageManager;-import com.pmease.gitplex.core.permission.object.ProtectedObject;-import com.pmease.gitplex.core.permission.object.UserBelonging;-import com.pmease.gitplex.core.validation.RepositoryName;-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.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.gitplex.core.GitPlex;+import com.pmease.gitplex.core.gatekeeper.AndGateKeeper;+import com.pmease.gitplex.core.gatekeeper.GateKeeper;+import com.pmease.gitplex.core.manager.BranchManager;+import com.pmease.gitplex.core.manager.StorageManager;+import com.pmease.gitplex.core.permission.object.ProtectedObject;+import com.pmease.gitplex.core.permission.object.UserBelonging;+import com.pmease.gitplex.core.validation.RepositoryName;@Entity@Table(uniqueConstraints={@@ -82,7 +87,7 @@ public class Repository extends AbstractEntity implements UserBelonging {private Collection<CommitComment> commitComments = new ArrayList<>();@OneToMany(mappedBy="repository", cascade=CascadeType.REMOVE)- private Collection<ThreadVisit> threadVisits = new ArrayList<>();+ private Collection<CommentVisit> threadVisits = new ArrayList<>();@OneToMany(mappedBy="repository", cascade=CascadeType.REMOVE)private Collection<Branch> branches = new ArrayList<>();@@ -90,6 +95,10 @@ 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, Optional<BlobText>> blobTexts = new HashMap<>();+public User getOwner() {return owner;}@@ -177,11 +186,11 @@ public class Repository extends AbstractEntity implements UserBelonging {this.commitComments = commitComments;}- public Collection<ThreadVisit> getThreadVisits() {+ public Collection<CommentVisit> getThreadVisits() {return threadVisits;}- public void setThreadVisits(Collection<ThreadVisit> threadVisits) {+ public void setThreadVisits(Collection<CommentVisit> threadVisits) {this.threadVisits = threadVisits;}@@ -342,4 +351,47 @@ public class Repository extends AbstractEntity implements UserBelonging {return getDefaultBranch();}+ /**+ * Read blob content and cache result in repository in case the same blob+ * content is requested again.+ *+ * @param blobInfo+ * info of the blob+ * @return+ * content of the blob+ */+ public byte[] getBlobContent(BlobInfo blobInfo) {+ byte[] blobContent = blobContents.get(blobInfo);+ if (blobContent == null) {+ blobContent = git().readBlob(blobInfo);+ blobContents.put(blobInfo, blobContent);+ }+ return blobContent;+ }++ /**+ * Read blob content as text and cache result in repository in case the same+ * blob text is requested again.+ *+ * @param commit+ * commit of the blob+ * @param blobPath+ * path of the blob+ * @param blobMode+ * mode of the blob+ * @return+ * text of the blob, or <tt>null</tt> if the blob content can not be+ * converted to text+ */+ @Nullable+ public BlobText getBlobText(BlobInfo blobInfo) {+ Optional<BlobText> optional = blobTexts.get(blobInfo);+ if (optional == null) {+ byte[] blobContent = getBlobContent(blobInfo);+ optional = Optional.fromNullable(BlobText.from(blobContent, blobInfo.getPath(), blobInfo.getMode()));+ blobTexts.put(blobInfo, optional);+ }+ return optional.orNull();+ }+}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/User.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/User.javaindex 7f9af46518..c6435143ba 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/User.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/User.java@@ -43,7 +43,7 @@ public class User extends AbstractUser implements ProtectedObject {private Collection<CommitComment> commitComments = new ArrayList<>();@OneToMany(mappedBy="user", cascade=CascadeType.REMOVE)- private Collection<ThreadVisit> threadVisits = new ArrayList<>();+ private Collection<CommentVisit> threadVisits = new ArrayList<>();@OneToMany(mappedBy="user", cascade=CascadeType.REMOVE)private Collection<Membership> memberships = new ArrayList<>();@@ -129,11 +129,11 @@ public class User extends AbstractUser implements ProtectedObject {this.commitComments = commitComments;}- public Collection<ThreadVisit> getThreadVisits() {+ public Collection<CommentVisit> getThreadVisits() {return threadVisits;}- public void setThreadVisits(Collection<ThreadVisit> threadVisits) {+ public void setThreadVisits(Collection<CommentVisit> threadVisits) {this.threadVisits = threadVisits;}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/ChangeCommentsTest.javanew file mode 100644index 0000000000..00425a01a9--- /dev/null+++ b/gitplex.core/src/test/java/com/pmease/gitplex/core/comment/ChangeCommentsTest.java@@ -0,0 +1,193 @@+package com.pmease.gitplex.core.comment;++import java.io.ByteArrayInputStream;+import java.io.IOException;+import java.util.ArrayList;+import java.util.Date;+import java.util.LinkedHashMap;+import java.util.List;++import org.apache.commons.io.IOUtils;++import static org.junit.Assert.*;++import org.junit.Test;++import com.pmease.commons.git.AbstractGitTest;+import com.pmease.commons.git.BlobInfo;+import com.pmease.commons.git.Change;+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 {++ @Test+ public void test() {+ final List<String> fileRevs = new ArrayList<>();+ fileRevs.add(""+ + "11\n" //comment1+ + "22\n"+ + "33\n"+ + "44\n" //comment5+ + "55\n" //comment3, comment6+ + "66\n"+ + "77\n"+ + "88\n" //comment4+ + "99\n");+ fileRevs.add(""+ + "111\n"+ + "222\n"+ + "33\n"+ + "44\n"+ + "55\n"+ + "66\n"+ + "77\n"+ + "88\n"+ + "99\n");+ fileRevs.add(""+ + "111\n"+ + "222\n"+ + "33\n"+ + "44\n"+ + "55\n"+ + "66\n"+ + "77\n"+ + "888\n"+ + "999\n");+ fileRevs.add(""+ + "111\n"+ + "222\n" //comment2+ + "33\n"+ + "44\n"+ + "555\n"+ + "66\n"+ + "77\n"+ + "8888\n"+ + "999\n"); //comment8, comment9++ addFileAndCommit("file1", fileRevs.get(0), "add file1");++ addFileAndCommit("file1", fileRevs.get(1), "modify file1");++ addFileAndCommit("file1", fileRevs.get(2), "modify file1");++ addFileAndCommit("file1", fileRevs.get(3), "modify file1");++ final LinkedHashMap<String, Date> commits = new LinkedHashMap<>();+ commits.put(git.parseRevision("master~3", true), new Date());+ commits.put(git.parseRevision("master~2", true), new Date());+ commits.put(git.parseRevision("master~1", true), new Date());+ commits.put(git.parseRevision("master", true), new Date());++ CommentLoader commentLoader = new CommentLoader() {++ @Override+ public List<CommitComment> loadComments(String commit) {+ List<CommitComment> comments = new ArrayList<>();+ List<String> commitHashes = new ArrayList<>(commits.keySet());++ int index = commitHashes.indexOf(commit);+ if (index == 0) {+ CommitComment comment = new CommitComment();+ comment.setId(1L);+ comment.setCommit(commit);+ comment.setContent("comment1");+ comment.setPosition(new CommentPosition("file1", 0));+ comments.add(comment);+ } else if (index == 1) {+ CommitComment comment = new CommitComment();+ comment.setId(2L);+ comment.setCommit(commit);+ comment.setContent("comment2");+ comment.setPosition(new CommentPosition("file1", 1));+ comments.add(comment);++ comment = new CommitComment();+ comment.setId(3L);+ comment.setCommit(commit);+ comment.setContent("comment3");+ comment.setPosition(new CommentPosition("file1", 4));+ comments.add(comment);++ comment = new CommitComment();+ comment.setId(4L);+ comment.setCommit(commit);+ comment.setContent("comment4");+ comment.setPosition(new CommentPosition("file1", 7));+ comments.add(comment);+ } else if (index == 2) {+ CommitComment comment = new CommitComment();+ comment.setId(5L);+ comment.setCommit(commit);+ comment.setContent("comment5");+ comment.setPosition(new CommentPosition("file1", 3));+ comments.add(comment);++ comment = new CommitComment();+ comment.setId(6L);+ comment.setCommit(commit);+ comment.setContent("comment6");+ comment.setPosition(new CommentPosition("file1", 4));+ comments.add(comment);++ comment = new CommitComment();+ comment.setId(7L);+ comment.setCommit(commit);+ comment.setContent("comment7");+ comment.setPosition(new CommentPosition("file1", 7));+ comments.add(comment);++ comment = new CommitComment();+ comment.setId(8L);+ comment.setCommit(commit);+ comment.setContent("comment8");+ comment.setPosition(new CommentPosition("file1", 8));+ comments.add(comment);+ } else if (index == 3) {+ CommitComment comment = new CommitComment();+ comment.setId(9L);+ comment.setCommit(commit);+ comment.setContent("comment9");+ comment.setPosition(new CommentPosition("file1", 8));+ comments.add(comment);+ }+ return comments;+ }++ };++ BlobLoader fileLoader = new BlobLoader() {++ @Override+ public List<String> loadBlob(BlobInfo blobInfo) {+ List<String> commitHashes = new ArrayList<>(commits.keySet());++ int index = commitHashes.indexOf(blobInfo.getRevision());+ String content = fileRevs.get(index);+ try {+ return IOUtils.readLines(new ByteArrayInputStream(content.getBytes()));+ } catch (IOException e) {+ throw new RuntimeException(e);+ }+ }++ };++ List<String> commitHashes = new ArrayList<>(commits.keySet());+ 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);++ 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());+ }++}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/WebModule.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/WebModule.javaindex c373406f32..8574170e15 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/WebModule.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/WebModule.java@@ -3,6 +3,8 @@ package com.pmease.gitplex.web;import org.apache.tika.mime.MediaType;import org.glassfish.jersey.server.ResourceConfig;+import com.pmease.commons.git.extensionpoint.TextConverter;+import com.pmease.commons.git.extensionpoint.TextConverterProvider;import com.pmease.commons.jersey.JerseyConfigurator;import com.pmease.commons.jetty.ServletConfigurator;import com.pmease.commons.loader.AbstractPluginModule;@@ -14,8 +16,6 @@ import com.pmease.gitplex.web.extensionpoint.DiffRenderer;import com.pmease.gitplex.web.extensionpoint.DiffRendererProvider;import com.pmease.gitplex.web.extensionpoint.MediaRenderer;import com.pmease.gitplex.web.extensionpoint.MediaRendererProvider;-import com.pmease.gitplex.web.extensionpoint.TextConverter;-import com.pmease.gitplex.web.extensionpoint.TextConverterProvider;import com.pmease.gitplex.web.page.repository.info.code.blob.renderer.BlobRendererFactory;import com.pmease.gitplex.web.resource.ResourceLocator;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 fc80923953..1d76d53e21 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@@ -814,15 +814,15 @@ ul.diff-alerts {padding-left: 12px;}.blob-diff>.head {border-bottom: 1px solid #BBB; padding: 4px 8px; font-size: 16px;border-radius: 4px 4px 0 0; background: #F2F2F2;}.blob-diff>.body {padding: 8px;}-.blob-diff.original {margin-bottom: 16px;}-.blob-diff.original, .blob-diff.original>.head {border-color: #FC9494;}-.blob-diff.revised, .blob-diff.revised>.head {border-color: #07C707;}-.blob-diff.original>.head {color: #FA5A5A; background: #FDBFBF;}-.blob-diff.revised>.head {color: #059505; background: #B6F8A2;}+.blob-diff.old {margin-bottom: 16px;}+.blob-diff.old, .blob-diff.old>.head {border-color: #FC9494;}+.blob-diff.new, .blob-diff.new>.head {border-color: #07C707;}+.blob-diff.old>.head {color: #FA5A5A; background: #FDBFBF;}+.blob-diff.new>.head {color: #059505; background: #B6F8A2;}.blob-diff .line {padding: 4px 8px;}.blob-diff .line>.fa {width: 16px;}-.blob-diff .original.line {background: #FCA6A6; color: #8f0000;}-.blob-diff .revised.line {background: #B6F8A2; color: #007f00;}+.blob-diff .old.line {background: #FCA6A6; color: #8f0000;}+.blob-diff .new.line {background: #B6F8A2; color: #007f00;}/* DIFF STAT */.diff-stat {font-family: 'PontIcons'; color: #ddd; }@@ -838,7 +838,7 @@ ul.diff-alerts {padding-left: 12px;}ul.threads li {border-left: 4px solid #F0F0F0; padding-left: 8px;}ul.threads li.unread {border-color: #70AEFA;}ul.threads li a {color: #444; cursor: pointer;}-ul.threads li .markdown {color: #444; margin-top: 4px;}+ul.threads li .markdown {color: #888; margin-top: 4px;}/* BRANCH CHOICE */.affinal-branch-choice .connector {margin: 4px 0 0 0; color: #BBB; font-weight: bold;@@ -924,21 +924,21 @@ 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 .comparison-base {margin-right: 32px;}-.request-detail .comparison-choices {border-bottom: 1px dashed #BBB; padding-bottom: 16px;}+.request-detail .compare>.head .original {margin-right: 32px;}+.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: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-result {margin-top: 16px;}-.request-detail .compare-result>tbody>tr>td.nav {width: 1%;}-.request-detail .compare-result>tbody>tr>td.nav .panel-heading {white-space: nowrap;}-.request-detail .compare-result>tbody>tr>td.nav .panel-heading>span {margin-right: 16px;}-.request-detail .compare-result>tbody>tr>td.content {padding-left: 16px;}-.request-detail .compare-result>tbody>tr>td.nav a {padding: 2px;}-.request-detail .compare-result>tbody>tr>td.nav a.active {background: #0F89E7; color: white; border-radius: 2px;}+.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;}+.request-detail .compare>.body>tbody>tr>td.nav .panel-heading>span {margin-right: 16px;}+.request-detail .compare>.body>tbody>tr>td.content {padding-left: 16px;}+.request-detail .compare>.body>tbody>tr>td.nav a {padding: 2px;}+.request-detail .compare>.body>tbody>tr>td.nav a.active {background: #0F89E7; color: white; border-radius: 2px;}.update-commits {margin: 0 0 0 -14px;}.update-commits tbody>tr>td.handle {diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/BlobDiffInfo.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/BlobDiffInfo.javadeleted file mode 100644index aeb7e8336c..0000000000--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/BlobDiffInfo.java+++ /dev/null@@ -1,33 +0,0 @@-package com.pmease.gitplex.web.component.diff;--import com.pmease.commons.git.Change;--@SuppressWarnings("serial")-public class BlobDiffInfo extends Change {-- private final String oldRevision;-- private final String newRevision;-- public BlobDiffInfo(Change change, String oldRevision, String newRevision) {- super(change);- this.oldRevision = oldRevision;- this.newRevision = newRevision;- }-- public BlobDiffInfo(Status status, String oldPath, String newPath, int oldMode, int newMode,- String oldRevision, String newRevision) {- super(status, oldPath, newPath, oldMode, newMode);- this.oldRevision = oldRevision;- this.newRevision = newRevision;- }-- public String getOldRevision() {- return oldRevision;- }-- public String getNewRevision() {- return newRevision;- }--}\ No newline at end of filediff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/BlobDiffPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/BlobDiffPanel.htmlindex de16765de7..8070adb88a 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/BlobDiffPanel.html+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/BlobDiffPanel.html@@ -1,18 +1,18 @@<wicket:panel>- <wicket:enclosure child="originalContent">- <div class="blob-diff original">+ <wicket:enclosure child="oldContent">+ <div class="blob-diff old"><div class="head">- <i class="fa fa-minus"></i> <span wicket:id="originalTitle"></span>+ <i class="fa fa-minus"></i> <span wicket:id="oldTitle"></span></div>- <div wicket:id="originalContent" class="body"></div>+ <div wicket:id="oldContent" class="body"></div></div></wicket:enclosure>- <wicket:enclosure child="revisedContent">- <div class="blob-diff revised">+ <wicket:enclosure child="newContent">+ <div class="blob-diff new"><div class="head">- <i class="fa fa-plus"></i> <span wicket:id="revisedTitle"></span>+ <i class="fa fa-plus"></i> <span wicket:id="newTitle"></span></div>- <div wicket:id="revisedContent" class="body"></div>+ <div wicket:id="newContent" class="body"></div></div></wicket:enclosure><div wicket:id="blobContent"></div>@@ -50,11 +50,11 @@<span wicket:id="title"></span></div><div class="body">- <div class="original line">+ <div class="old line"><i class="fa fa-minus"></i><span wicket:id="oldContent"></span></div>- <div class="revised line">+ <div class="new line"><i class="fa fa-plus"></i><span wicket:id="newContent"></span></div>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 84f9134a9b..16bdea16cc 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/BlobDiffPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/BlobDiffPanel.java@@ -1,130 +1,104 @@package com.pmease.gitplex.web.component.diff;-import java.util.ArrayList;+import static com.pmease.commons.git.Change.Status.UNCHANGED;++import javax.annotation.Nullable;import org.apache.tika.mime.MediaType;-import org.apache.wicket.Component;import org.apache.wicket.markup.html.WebMarkupContainer;import org.apache.wicket.markup.html.basic.Label;import org.apache.wicket.markup.html.panel.Fragment;import org.apache.wicket.markup.html.panel.Panel;import org.apache.wicket.model.IModel;-import org.apache.wicket.model.LoadableDetachableModel;import org.eclipse.jgit.lib.FileMode;-import com.pmease.commons.git.Git;-import com.pmease.commons.git.GitText;-import com.pmease.commons.util.Charsets;+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.model.Repository;import com.pmease.gitplex.web.component.gitlink.GitLink;import com.pmease.gitplex.web.component.symbollink.SymbolLink;-import com.pmease.gitplex.web.component.view.BlobRenderInfo;import com.pmease.gitplex.web.component.view.BlobViewPanel;import com.pmease.gitplex.web.extensionpoint.DiffRenderer;import com.pmease.gitplex.web.extensionpoint.DiffRendererProvider;-import com.pmease.gitplex.web.extensionpoint.TextConverter;-import com.pmease.gitplex.web.extensionpoint.TextConverterProvider;@SuppressWarnings("serial")public class BlobDiffPanel extends Panel {private final IModel<Repository> repoModel;- private final BlobDiffInfo diffInfo;-- private final IModel<byte[]> oldContentModel;+ private final RevAwareChange change;- private final IModel<byte[]> newContentModel;+ private final ChangeComments comments;- public BlobDiffPanel(String id, IModel<Repository> repoModel, final BlobDiffInfo diffInfo) {+ public BlobDiffPanel(String id, IModel<Repository> repoModel, RevAwareChange change,+ @Nullable ChangeComments comments, int lineNo) {super(id);this.repoModel = repoModel;- this.diffInfo = diffInfo;-- oldContentModel = new LoadableDetachableModel<byte[]>() {-- @Override- protected byte[] load() {- Git git = BlobDiffPanel.this.repoModel.getObject().git();- if (diffInfo.getStatus() == BlobDiffInfo.Status.ADDED)- return null;- else- return git.read(diffInfo.getOldRevision(), diffInfo.getOldPath(), diffInfo.getOldMode());-- }-- };- newContentModel = new LoadableDetachableModel<byte[]>() {-- @Override- protected byte[] load() {- Git git = BlobDiffPanel.this.repoModel.getObject().git();- if (diffInfo.getStatus() == BlobDiffInfo.Status.DELETED)- return null;- else if (diffInfo.getStatus() != BlobDiffInfo.Status.UNCHANGED)- return git.read(diffInfo.getNewRevision(), diffInfo.getNewPath(), diffInfo.getNewMode());- else- return oldContentModel.getObject();- }-- };+ this.change = change;+ this.comments = comments;}- public BlobDiffInfo getBlobDiffInfo() {- return diffInfo;+ public RevAwareChange getChange() {+ return change;}@Overrideprotected void onInitialize() {super.onInitialize();- int oldBlobType = diffInfo.getOldMode() & FileMode.TYPE_MASK;- int newBlobType = diffInfo.getNewMode() & FileMode.TYPE_MASK;+ int oldBlobType = change.getOldMode() & FileMode.TYPE_MASK;+ int newBlobType = change.getNewMode() & FileMode.TYPE_MASK;- if (diffInfo.getStatus() == BlobDiffInfo.Status.UNCHANGED) {- add(new WebMarkupContainer("originalContent").setVisible(false));- add(new WebMarkupContainer("revisedContent").setVisible(false));+ if (change.getStatus() == UNCHANGED) {+ add(new WebMarkupContainer("oldContent").setVisible(false));+ add(new WebMarkupContainer("newContent").setVisible(false));Fragment fragment = new Fragment("blobContent", "notChangedFrag", this);- fragment.add(new Label("title", diffInfo.getOldPath()));- BlobRenderInfo renderInfo = new BlobRenderInfo(diffInfo.getNewPath(),- diffInfo.getNewRevision(), diffInfo.getNewMode());- fragment.add(new BlobViewPanel("content", repoModel, renderInfo, newContentModel));+ fragment.add(new Label("title", change.getOldPath()));+ BlobInfo renderInfo = new BlobInfo(change.getNewRevision(),+ change.getNewPath(), change.getNewMode());+ fragment.add(new BlobViewPanel("content", repoModel, renderInfo));add(fragment);} else if (oldBlobType == FileMode.TYPE_GITLINK && newBlobType == FileMode.TYPE_GITLINK) {- add(new WebMarkupContainer("originalContent").setVisible(false));- add(new WebMarkupContainer("revisedContent").setVisible(false));+ add(new WebMarkupContainer("oldContent").setVisible(false));+ add(new WebMarkupContainer("newContent").setVisible(false));Fragment fragment = new Fragment("blobContent", "nonFileDiffFrag", this);- fragment.add(new Label("renamedTitle", diffInfo.getOldPath())- .setVisible(!diffInfo.getOldPath().equals(diffInfo.getNewPath())));- fragment.add(new Label("title", diffInfo.getNewPath()));- fragment.add(new GitLink("oldContent", new String(oldContentModel.getObject())));- fragment.add(new GitLink("newContent", new String(newContentModel.getObject())));+ fragment.add(new Label("renamedTitle", change.getOldPath())+ .setVisible(!change.getOldPath().equals(change.getNewPath())));+ fragment.add(new Label("title", change.getNewPath()));+ BlobText oldText = repoModel.getObject().getBlobText(change.getOldBlobInfo());+ BlobText newText = repoModel.getObject().getBlobText(change.getNewBlobInfo());+ fragment.add(new GitLink("oldContent", oldText.getLines().get(0)));+ fragment.add(new GitLink("newContent", newText.getLines().get(0)));add(fragment);} else if (oldBlobType == FileMode.TYPE_SYMLINK && newBlobType == FileMode.TYPE_SYMLINK) {- add(new WebMarkupContainer("originalContent").setVisible(false));- add(new WebMarkupContainer("revisedContent").setVisible(false));+ add(new WebMarkupContainer("oldContent").setVisible(false));+ add(new WebMarkupContainer("newContent").setVisible(false));Fragment fragment = new Fragment("blobContent", "nonFileDiffFrag", this);- fragment.add(new Label("renamedTitle", diffInfo.getOldPath())- .setVisible(!diffInfo.getOldPath().equals(diffInfo.getNewPath())));- fragment.add(new Label("title", diffInfo.getNewPath()));- fragment.add(new SymbolLink("oldContent", repoModel, diffInfo.getOldRevision(),- diffInfo.getOldPath(), new String(oldContentModel.getObject())));- fragment.add(new SymbolLink("newContent", repoModel, diffInfo.getNewRevision(),- diffInfo.getNewPath(), new String(newContentModel.getObject())));+ fragment.add(new Label("renamedTitle", change.getOldPath())+ .setVisible(!change.getOldPath().equals(change.getNewPath())));+ fragment.add(new Label("title", change.getNewPath()));+ BlobText oldText = repoModel.getObject().getBlobText(change.getOldBlobInfo());+ BlobText newText = repoModel.getObject().getBlobText(change.getNewBlobInfo());+ fragment.add(new SymbolLink("oldContent", repoModel, change.getOldRevision(),+ change.getOldPath(), oldText.getLines().get(0)));+ fragment.add(new SymbolLink("newContent", repoModel, change.getNewRevision(),+ change.getNewPath(), newText.getLines().get(0)));add(fragment);} else if (oldBlobType == FileMode.TYPE_FILE && newBlobType == FileMode.TYPE_FILE) {- add(new WebMarkupContainer("originalContent").setVisible(false));- add(new WebMarkupContainer("revisedContent").setVisible(false));+ add(new WebMarkupContainer("oldContent").setVisible(false));+ add(new WebMarkupContainer("newContent").setVisible(false));- byte[] oldContent = oldContentModel.getObject();- byte[] newContent = newContentModel.getObject();- MediaType oldMediaType = MediaTypes.detectFrom(oldContent, diffInfo.getOldPath());- MediaType newMediaType = MediaTypes.detectFrom(newContent, diffInfo.getNewPath());+ byte[] oldContent = repoModel.getObject().getBlobContent(change.getOldBlobInfo());+ byte[] newContent = repoModel.getObject().getBlobContent(change.getNewBlobInfo());+ MediaType oldMediaType = MediaTypes.detectFrom(oldContent, change.getOldPath());+ MediaType newMediaType = MediaTypes.detectFrom(newContent, change.getNewPath());DiffRenderer renderer = null;for (DiffRendererProvider provider: GitPlex.getExtensions(DiffRendererProvider.class)) {@@ -133,95 +107,66 @@ public class BlobDiffPanel extends Panel {break;}if (renderer != null) {- add(renderer.render("blobContent", diffInfo, oldContentModel, newContentModel));+ add(renderer.render("blobContent", repoModel, change));} else {- Component diffPanel = null;- if (oldMediaType == newMediaType) {- TextConverter textConverter = null;- for (TextConverterProvider provider: GitPlex.getExtensions(TextConverterProvider.class)) {- textConverter = provider.getTextConverter(oldMediaType);- if (textConverter != null)- break;- }- if (textConverter != null) {- GitText oldText = new GitText(textConverter.convert(oldContent),- true, Charsets.UTF_8.name());- GitText newText = new GitText(textConverter.convert(newContent),- true, Charsets.UTF_8.name());- diffPanel = new TextDiffPanel("blobContent", repoModel, diffInfo, oldText, newText);+ BlobText oldText = repoModel.getObject().getBlobText(change.getOldBlobInfo());+ BlobText newText = repoModel.getObject().getBlobText(change.getNewBlobInfo());+ if (oldText != null) {+ if (newText != null) {+ add(new TextDiffPanel("blobContent", repoModel, change, oldText, newText, comments));+ } else if (newContent.length == 0) {+ add(new TextDiffPanel("blobContent", repoModel, change, oldText, new BlobText(), comments));+ } else {+ Fragment fragment = new Fragment("blobContent", "binaryFileFrag", this);+ fragment.add(new FileDiffTitle("summary", change));+ add(fragment);}- }- if (diffPanel == null) {+ } else if (newText != null) {if (oldContent.length == 0) {- if (newContent.length == 0) {- Fragment fragment = new Fragment("blobContent", "emptyFileFrag", this);- fragment.add(new FileDiffTitle("summary", diffInfo));- diffPanel = fragment;- } else {- GitText newText = GitText.from(newContent);- if (newText != null) {- GitText oldText = new GitText(new ArrayList<String>(), true, newText.getCharset());- diffPanel = new TextDiffPanel("blobContent", repoModel, diffInfo, oldText, newText);- } else {- Fragment fragment = new Fragment("blobContent", "binaryFileFrag", this);- fragment.add(new FileDiffTitle("summary", diffInfo));- diffPanel = fragment;- }- }+ add(new TextDiffPanel("blobContent", repoModel, change, new BlobText(), newText, comments));} else {- if (newContent.length == 0) {- GitText oldText = GitText.from(oldContent);- if (oldText != null) {- GitText newText = new GitText(new ArrayList<String>(), true, oldText.getCharset());- diffPanel = new TextDiffPanel("blobContent", repoModel, diffInfo, oldText, newText);- } else {- Fragment fragment = new Fragment("blobContent", "binaryFileFrag", this);- fragment.add(new FileDiffTitle("summary", diffInfo));- diffPanel = fragment;- }- } else {- GitText oldText = GitText.from(oldContent);- GitText newText = GitText.from(newContent);- if (oldText != null && newText != null) {- diffPanel = new TextDiffPanel("blobContent", repoModel, diffInfo, oldText, newText);- } else {- Fragment fragment = new Fragment("blobContent", "binaryFileFrag", this);- fragment.add(new FileDiffTitle("summary", diffInfo));- diffPanel = fragment;- }- }+ Fragment fragment = new Fragment("blobContent", "binaryFileFrag", this);+ fragment.add(new FileDiffTitle("summary", change));+ add(fragment);}+ } else if (oldContent.length == 0 && newContent.length == 0) {+ Fragment fragment = new Fragment("blobContent", "emptyFileFrag", this);+ fragment.add(new FileDiffTitle("summary", change));+ add(fragment);+ } else {+ Fragment fragment = new Fragment("blobContent", "binaryFileFrag", this);+ fragment.add(new FileDiffTitle("summary", change));+ add(fragment);}- add(diffPanel);}} else {if (oldBlobType == FileMode.TYPE_SYMLINK) {- add(new SymbolLink("originalContent", repoModel, diffInfo.getOldRevision(),- diffInfo.getOldPath(), new String(oldContentModel.getObject())));+ BlobText oldText = repoModel.getObject().getBlobText(change.getOldBlobInfo());+ add(new SymbolLink("oldContent", repoModel, change.getOldRevision(),+ change.getOldPath(), oldText.getLines().get(0)));} else if (oldBlobType == FileMode.TYPE_GITLINK) {- add(new GitLink("originalContent", new String(oldContentModel.getObject())));+ BlobText oldText = repoModel.getObject().getBlobText(change.getOldBlobInfo());+ add(new GitLink("oldContent", oldText.getLines().get(0)));} else if (oldBlobType == FileMode.TYPE_FILE) {- BlobRenderInfo renderInfo = new BlobRenderInfo(diffInfo.getOldPath(),- diffInfo.getOldRevision(), diffInfo.getOldMode());- add(new BlobViewPanel("originalContent", repoModel, renderInfo, oldContentModel));+ add(new BlobViewPanel("oldContent", repoModel, change.getOldBlobInfo()));} else {- add(new WebMarkupContainer("originalContent").setVisible(false));+ add(new WebMarkupContainer("oldContent").setVisible(false));}- add(new Label("originalTitle", diffInfo.getOldPath()));+ add(new Label("oldTitle", change.getOldPath()));if (newBlobType == FileMode.TYPE_SYMLINK) {- add(new SymbolLink("revisedContent", repoModel, diffInfo.getNewRevision(),- diffInfo.getNewPath(), new String(newContentModel.getObject())));+ BlobText newText = repoModel.getObject().getBlobText(change.getNewBlobInfo());+ add(new SymbolLink("newContent", repoModel, change.getNewRevision(),+ change.getNewPath(), newText.getLines().get(0)));} else if (newBlobType == FileMode.TYPE_GITLINK) {- add(new GitLink("revisedContent", new String(newContentModel.getObject())));+ BlobText newText = repoModel.getObject().getBlobText(change.getNewBlobInfo());+ add(new GitLink("newContent", newText.getLines().get(0)));} else if (newBlobType == FileMode.TYPE_FILE) {- BlobRenderInfo renderInfo = new BlobRenderInfo(diffInfo.getNewPath(),- diffInfo.getNewRevision(), diffInfo.getNewMode());- add(new BlobViewPanel("revisedContent", repoModel, renderInfo, newContentModel));+ add(new BlobViewPanel("newContent", repoModel, change.getNewBlobInfo()));} else {- add(new WebMarkupContainer("revisedContent").setVisible(false));+ add(new WebMarkupContainer("newContent").setVisible(false));}- add(new Label("revisedTitle", diffInfo.getNewPath()));+ add(new Label("newTitle", change.getNewPath()));add(new WebMarkupContainer("blobContent").setVisible(false));}@@ -230,8 +175,6 @@ public class BlobDiffPanel extends Panel {protected void onDetach() {repoModel.detach();- oldContentModel.detach();- newContentModel.detach();super.onDetach();}diff --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 75d25ab206..3428bff713 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@@ -33,19 +33,8 @@ public abstract class ChangedFilesPanel extends Panel {protected void populateItem(ListItem<Change> item) {Change change = item.getModelObject();WebMarkupContainer link = newBlobLink("link", change);- if (change.getStatus() == Change.Status.ADDED) {- link.add(new Label("label", change.getNewPath()));- link.add(AttributeAppender.append("title", "Added"));- } else if (change.getStatus() == Change.Status.DELETED) {- link.add(new Label("label", change.getOldPath()));- link.add(AttributeAppender.append("title", "Deleted"));- } else if (change.getStatus() == Change.Status.MODIFIED) {- link.add(new Label("label", change.getNewPath()));- link.add(AttributeAppender.append("title", "Modified"));- } else {- link.add(new Label("label", change.getNewPath()));- link.add(AttributeAppender.append("title", "Renamed from " + change.getOldPath()));- }+ 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()));}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 a90e50b7c5..e240c0eeb0 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@@ -6,7 +6,6 @@ import java.util.List;import jersey.repackaged.com.google.common.base.Splitter;-import org.apache.commons.lang3.StringUtils;import org.apache.wicket.Component;import org.apache.wicket.ajax.AjaxRequestTarget;import org.apache.wicket.ajax.markup.html.AjaxLink;@@ -22,7 +21,6 @@ import org.apache.wicket.model.IModel;import org.apache.wicket.model.Model;import com.pmease.commons.git.Change;-import com.pmease.commons.util.WordUtils;import com.pmease.gitplex.core.model.Repository;@SuppressWarnings("serial")@@ -130,22 +128,12 @@ public abstract class DiffTreePanel extends Panel {link = newBlobLink("link", node.getChange());fragment.add(AttributeAppender.append("class", " file "));}- if (node.getChange().getStatus() == Change.Status.RENAMED) {- link.add(AttributeAppender.append("title", "Renamed from " + node.getChange().getOldPath()));- } else {- link.add(AttributeAppender.append("title",- WordUtils.capitalize(node.getChange().getStatus().name().toLowerCase())));- }+ link.add(AttributeAppender.append("title", node.getChange().getHint()));+fragment.add(link);fragment.add(AttributeAppender.append("class", node.getChange().getStatus().name().toLowerCase()));- String name;- if (node.getChange().getPath().contains("/"))- name = StringUtils.substringAfterLast(node.getChange().getPath(), "/");- else- name = node.getChange().getPath();-- link.add(new Label("label", name));+ link.add(new Label("label", node.getChange().getName()));return fragment;}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/FileDiffTitle.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/FileDiffTitle.javaindex ad178e2ee7..1981f00188 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/FileDiffTitle.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/FileDiffTitle.java@@ -11,6 +11,7 @@ import org.apache.wicket.model.Model;import org.eclipse.jgit.lib.FileMode;import com.google.common.base.Preconditions;+import com.pmease.commons.git.RevAwareChange;import com.pmease.commons.wicket.behavior.TooltipBehavior;import de.agilecoders.wicket.core.markup.html.bootstrap.components.TooltipConfig;@@ -19,30 +20,30 @@ import de.agilecoders.wicket.core.markup.html.bootstrap.components.TooltipConfig@SuppressWarnings("serial")public class FileDiffTitle extends Panel {- private final BlobDiffInfo diffInfo;+ private final RevAwareChange change;private final List<String> alerts;- public FileDiffTitle(String id, BlobDiffInfo diffInfo, List<String> alerts) {+ public FileDiffTitle(String id, RevAwareChange change, List<String> alerts) {super(id);- int oldBlobType = diffInfo.getOldMode() & FileMode.TYPE_MASK;- int newBlobType = diffInfo.getNewMode() & FileMode.TYPE_MASK;+ int oldBlobType = change.getOldMode() & FileMode.TYPE_MASK;+ int newBlobType = change.getNewMode() & FileMode.TYPE_MASK;Preconditions.checkArgument(oldBlobType == FileMode.TYPE_FILE && newBlobType == FileMode.TYPE_FILE);- this.diffInfo = diffInfo;+ this.change = change;this.alerts = new ArrayList<>();- if (diffInfo.getOldMode() != diffInfo.getNewMode()) {- this.alerts.add("File mode is changed from " + Integer.toString(diffInfo.getOldMode(), 8)- + " to " + Integer.toString(diffInfo.getNewMode(), 8));+ if (change.getOldMode() != change.getNewMode()) {+ this.alerts.add("File mode is changed from " + Integer.toString(change.getOldMode(), 8)+ + " to " + Integer.toString(change.getNewMode(), 8));}if (alerts != null)this.alerts.addAll(alerts);}- public FileDiffTitle(String id, BlobDiffInfo diffInfo) {+ public FileDiffTitle(String id, RevAwareChange diffInfo) {this(id, diffInfo, null);}@@ -50,9 +51,9 @@ public class FileDiffTitle extends Panel {protected void onInitialize() {super.onInitialize();- add(new Label("renamedTitle", diffInfo.getOldPath())- .setVisible(!diffInfo.getOldPath().equals(diffInfo.getNewPath())));- add(new Label("title", diffInfo.getNewPath()));+ add(new Label("renamedTitle", change.getOldPath())+ .setVisible(!change.getOldPath().equals(change.getNewPath())));+ add(new Label("title", change.getNewPath()));if (alerts.size() == 0) {add(new WebMarkupContainer("alerts").setVisible(false));diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.javaindex cc9b863efa..f0c3f160e3 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.java@@ -1,12 +1,17 @@package com.pmease.gitplex.web.component.diff;+import static com.pmease.commons.util.diff.DiffLine.Action.ADD;+import static com.pmease.commons.util.diff.DiffLine.Action.DELETE;+import static com.pmease.commons.util.diff.DiffLine.Action.EQUAL;+import java.util.ArrayList;import java.util.Collections;import java.util.Date;-import java.util.HashMap;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;@@ -24,8 +29,9 @@ import org.apache.wicket.model.IModel;import org.apache.wicket.model.LoadableDetachableModel;import org.apache.wicket.model.Model;-import com.pmease.commons.git.GitText;+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;@@ -39,8 +45,8 @@ 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.manager.AuthorizationManager;-import com.pmease.gitplex.core.manager.CommitCommentManager;import com.pmease.gitplex.core.manager.UserManager;import com.pmease.gitplex.core.model.CommentPosition;import com.pmease.gitplex.core.model.CommitComment;@@ -73,21 +79,19 @@ public class TextDiffPanel extends Panel {private final IModel<Repository> repoModel;- private final BlobDiffInfo diffInfo;-- private final GitText oldText;+ private final RevAwareChange change;- private final GitText newText;+ private final BlobText oldText;- private final IModel<Map<Integer, List<CommitComment>>> oldCommentsModel;+ private final BlobText newText;- private final IModel<Map<Integer, List<CommitComment>>> newCommentsModel;+ private final ChangeComments comments;private final IModel<Boolean> allowToAddCommentModel;- private GitText effectiveOldText;+ private BlobText effectiveOldText;- private GitText effectiveNewText;+ private BlobText effectiveNewText;private DiffOption diffOption = DiffOption.IGNORE_NOTHING;@@ -95,51 +99,26 @@ public class TextDiffPanel extends Panel {private List<DiffLine> diffs;- public TextDiffPanel(String id, final IModel<Repository> repoModel,- BlobDiffInfo diffInfo, GitText oldText, GitText newText) {+ public TextDiffPanel(String id, final IModel<Repository> repoModel, RevAwareChange change,+ BlobText oldText, BlobText newText, @Nullable ChangeComments comments) {super(id);this.repoModel = repoModel;+ this.comments = comments;- String oldCommitHash = diffInfo.getOldRevision();+ String oldCommitHash = change.getOldRevision();if (!GitUtils.isHash(oldCommitHash))oldCommitHash = repoModel.getObject().git().parseRevision(oldCommitHash, true);- String newCommitHash = diffInfo.getNewRevision();+ String newCommitHash = change.getNewRevision();if (!GitUtils.isHash(newCommitHash))newCommitHash = repoModel.getObject().git().parseRevision(newCommitHash, true);- this.diffInfo = new BlobDiffInfo(diffInfo.getStatus(), diffInfo.getOldPath(), diffInfo.getNewPath(),- diffInfo.getOldMode(), diffInfo.getNewMode(), oldCommitHash, newCommitHash);+ this.change = new RevAwareChange(change.getStatus(), change.getOldPath(), change.getNewPath(),+ change.getOldMode(), change.getNewMode(), oldCommitHash, newCommitHash);this.oldText = oldText;this.newText = newText;- oldCommentsModel = new LoadableDetachableModel<Map<Integer, List<CommitComment>>>() {-- @Override- protected Map<Integer, List<CommitComment>> load() {- List<CommitComment> comments = GitPlex.getInstance(CommitCommentManager.class).findByCommitAndFile(- TextDiffPanel.this.repoModel.getObject(),- TextDiffPanel.this.diffInfo.getOldRevision(),- TextDiffPanel.this.diffInfo.getOldPath());- return mapCommentsToLines(comments);- }-- };-- newCommentsModel = new LoadableDetachableModel<Map<Integer, List<CommitComment>>>() {-- @Override- protected Map<Integer, List<CommitComment>> load() {- List<CommitComment> comments = GitPlex.getInstance(CommitCommentManager.class).findByCommitAndFile(- TextDiffPanel.this.repoModel.getObject(),- TextDiffPanel.this.diffInfo.getNewRevision(),- TextDiffPanel.this.diffInfo.getNewPath());- return mapCommentsToLines(comments);- }-- };-// cache add comment permission check in model to avoid recalculation for every lineallowToAddCommentModel = new LoadableDetachableModel<Boolean>() {@@ -155,22 +134,6 @@ public class TextDiffPanel extends Panel {onDiffOptionChanged();}- private Map<Integer, List<CommitComment>> mapCommentsToLines(List<CommitComment> comments) {- Map<Integer, List<CommitComment>> map = new HashMap<>();- for (CommitComment comment: comments) {- Integer lineNo = comment.getPosition().getLineNo();- if (lineNo != null) {- List<CommitComment> lineComments = map.get(lineNo);- if (lineComments == null) {- lineComments = new ArrayList<>();- map.put(lineNo, lineComments);- }- lineComments.add(comment);- }- }- return map;- }-private void onDiffOptionChanged() {if (diffOption == DiffOption.IGNORE_EOL) {effectiveOldText = oldText.ignoreEOL();@@ -191,7 +154,7 @@ public class TextDiffPanel extends Panel {private boolean isIdentical() {for (DiffLine diffLine: diffs) {- if (diffLine.getAction() != DiffLine.Action.EQUAL)+ if (diffLine.getAction() != EQUAL)return false;}return true;@@ -233,7 +196,7 @@ public class TextDiffPanel extends Panel {if (!newText.isHasEolAtEof())alerts.add("Revised text does not have EOL character at EOF");- head.add(new FileDiffTitle("title", diffInfo, alerts));+ head.add(new FileDiffTitle("title", change, alerts));head.add(new WebMarkupContainer("identical") {@@ -277,7 +240,7 @@ public class TextDiffPanel extends Panel {@Overrideprotected void onConfigure() {super.onConfigure();- setVisible(showComments);+ setVisible((getOldComments() != null || getNewComments() != null) && showComments);}}.add(new ScrollBehavior(head, ".comments.line", 50, false)));@@ -287,7 +250,7 @@ public class TextDiffPanel extends Panel {@Overrideprotected void onConfigure() {super.onConfigure();- setVisible(showComments);+ setVisible((getOldComments() != null || getNewComments() != null) && showComments);}}.add(new ScrollBehavior(head, ".comments.line", 50, true)));@@ -302,7 +265,7 @@ public class TextDiffPanel extends Panel {@Overrideprotected void onConfigure() {super.onConfigure();- setVisible(!showComments);+ setVisible((getOldComments() != null || getNewComments() != null) && !showComments);}});@@ -316,7 +279,7 @@ public class TextDiffPanel extends Panel {@Overrideprotected void onConfigure() {super.onConfigure();- setVisible(showComments);+ setVisible((getOldComments() != null || getNewComments() != null) && showComments);}});@@ -471,16 +434,23 @@ public class TextDiffPanel extends Panel {@Overrideprotected List<CommitComment> load() {- List<CommitComment> oldLineComments = oldCommentsModel.getObject().get(diffLine.getOldLineNo());+ List<CommitComment> oldLineComments = null;+ if (getOldComments() != null)+ oldLineComments = getOldComments().get(diffLine.getOldLineNo());+if (oldLineComments == null)oldLineComments = new ArrayList<>();- List<CommitComment> newLineComments = newCommentsModel.getObject().get(diffLine.getNewLineNo());++ List<CommitComment> newLineComments = null;+ if (getNewComments() != null)+ newLineComments = getNewComments().get(diffLine.getNewLineNo());+if (newLineComments == null)newLineComments = new ArrayList<>();- if (diffLine.getAction() == DiffLine.Action.DELETE) {+ if (diffLine.getAction() == DELETE) {return oldLineComments;- } else if (diffLine.getAction() == DiffLine.Action.ADD) {+ } else if (diffLine.getAction() == ADD) {return newLineComments;} else {List<CommitComment> comments = new ArrayList<>();@@ -524,7 +494,7 @@ public class TextDiffPanel extends Panel {@Overrideprotected void populateItem(final ListItem<CommitComment> commentItem) {- CommitComment comment = commentItem.getModelObject();+ final CommitComment comment = commentItem.getModelObject();Fragment fragment = new Fragment("comment", "viewCommentFrag", TextDiffPanel.this);fragment.setOutputMarkupId(true);@@ -534,7 +504,7 @@ public class TextDiffPanel extends Panel {@Overridepublic Date getObject() {- return commentItem.getModelObject().getDate();+ return commentItem.getModelObject().getCommentDate();}}));@@ -571,7 +541,7 @@ public class TextDiffPanel extends Panel {super.onSubmit(target, form);CommitComment comment = commentItem.getModelObject();- comment.setDate(new Date());+ comment.setCommentDate(new Date());comment.setContent(input.getModelObject());GitPlex.getInstance(Dao.class).persist(comment);@@ -589,17 +559,32 @@ public class TextDiffPanel extends Panel {protected void onConfigure() {super.onConfigure();- setVisible(GitPlex.getInstance(AuthorizationManager.class).canModify(commentItem.getModelObject()));+ AuthorizationManager manager = GitPlex.getInstance(AuthorizationManager.class);+ setVisible(manager.canModify(commentItem.getModelObject()));}});- final Long commentId = commentItem.getModelObject().getId();fragment.add(new AjaxLink<Void>("delete") {@Overridepublic void onClick(AjaxRequestTarget target) {- Dao dao = GitPlex.getInstance(Dao.class);- dao.remove(dao.load(CommitComment.class, commentId));+ GitPlex.getInstance(Dao.class).remove(comment);+ if (comments.getOldComments() != null) {+ List<CommitComment> lineComments = comments.getOldComments().get(diffLine.getOldLineNo());+ if (lineComments != null) {+ lineComments.remove(comment);+ if (lineComments.isEmpty())+ comments.getOldComments().remove(diffLine.getOldLineNo());+ }+ }+ if (comments.getNewComments() != null) {+ List<CommitComment> lineComments = comments.getNewComments().get(diffLine.getNewLineNo());+ if (lineComments != null) {+ lineComments.remove(comment);+ if (lineComments.isEmpty())+ comments.getOldComments().remove(diffLine.getNewLineNo());+ }+ }target.add(commentsRow);}@@ -637,15 +622,15 @@ public class TextDiffPanel extends Panel {contentRow.add(new AddCommentLink("addComment", lineItem));- if (diffLine.getAction() == DiffLine.Action.ADD) {- if (lineItem.getIndex() == 0 || diffs.get(lineItem.getIndex()-1).getAction() == DiffLine.Action.EQUAL)+ if (diffLine.getAction() == ADD) {+ if (lineItem.getIndex() == 0 || diffs.get(lineItem.getIndex()-1).getAction() == EQUAL)contentRow.add(AttributeAppender.append("class", " new diff-block"));elsecontentRow.add(AttributeAppender.append("class", " new"));contentRow.add(new Label("oldLineNo"));contentRow.add(new Label("newLineNo", "+ " + (diffLine.getNewLineNo()+1)));- } else if (diffLine.getAction() == DiffLine.Action.DELETE) {- if (lineItem.getIndex() == 0 || diffs.get(lineItem.getIndex()-1).getAction() == DiffLine.Action.EQUAL)+ } else if (diffLine.getAction() == DELETE) {+ if (lineItem.getIndex() == 0 || diffs.get(lineItem.getIndex()-1).getAction() == EQUAL)contentRow.add(AttributeAppender.append("class", " old diff-block"));elsecontentRow.add(AttributeAppender.append("class", " old"));@@ -700,7 +685,7 @@ public class TextDiffPanel extends Panel {private class AddCommentLink extends AjaxLink<Void> {- private ListItem<DiffLine> item;+ private final ListItem<DiffLine> item;public AddCommentLink(String id, ListItem<DiffLine> item) {super(id);@@ -746,24 +731,37 @@ public class TextDiffPanel extends Panel {CommitComment comment = new CommitComment();comment.setRepository(repoModel.getObject());comment.setUser(GitPlex.getInstance(UserManager.class).getCurrent());- comment.setPosition(new CommentPosition());String commit;- if (diffLine.getAction() == DiffLine.Action.ADD- || diffLine.getAction() == DiffLine.Action.EQUAL) {- commit = diffInfo.getNewRevision();- comment.getPosition().setFilePath(diffInfo.getNewPath());- comment.getPosition().setLineNo(diffLine.getNewLineNo());+ CommentPosition position;+ if (diffLine.getAction() == DELETE) {+ commit = change.getOldRevision();+ position = new CommentPosition(change.getOldPath(), diffLine.getOldLineNo());+ } else if (diffLine.getAction() == ADD) {+ commit = change.getNewRevision();+ position = new CommentPosition(change.getNewPath(), diffLine.getNewLineNo());+ } else if (getNewComments() != null) {+ commit = change.getNewRevision();+ position = new CommentPosition(change.getNewPath(), diffLine.getNewLineNo());} else {- commit = diffInfo.getOldRevision();- comment.getPosition().setFilePath(diffInfo.getOldPath());- comment.getPosition().setLineNo(diffLine.getOldLineNo());+ commit = change.getOldRevision();+ position = new CommentPosition(change.getOldPath(), diffLine.getOldLineNo());}comment.setCommit(commit);+ comment.setPosition(position);comment.setContent(input.getModelObject());- comment.setDate(new Date());-+ comment.setCommentDate(new Date());+ comment.setCommitDate(comments.getCommits().get(commit));GitPlex.getInstance(Dao.class).persist(comment);+ if (diffLine.getAction() == DELETE)+ addToComments(getOldComments(), diffLine.getOldLineNo(), comment);+ else if (diffLine.getAction() == ADD)+ addToComments(getNewComments(), diffLine.getNewLineNo(), comment);+ else if (getNewComments() != null)+ addToComments(getNewComments(), diffLine.getNewLineNo(), comment);+ else+ addToComments(getOldComments(), diffLine.getOldLineNo(), comment);+commentsRow.replace(new WebMarkupContainer(NEW_COMMENT_ID));target.add(commentsRow);}@@ -779,20 +777,54 @@ public class TextDiffPanel extends Panel {}target.add(commentsRow);}++ private void addToComments(Map<Integer, List<CommitComment>> comments, int lineNo, CommitComment comment) {+ List<CommitComment> lineComments = comments.get(lineNo);+ if (lineComments == null) {+ lineComments = new ArrayList<>();+ comments.put(lineNo, lineComments);+ }+ lineComments.add(comment);+ }@Overrideprotected void onConfigure() {super.onConfigure();- setVisible(allowToAddCommentModel.getObject());+ if (!allowToAddCommentModel.getObject()) {+ setVisible(false);+ } else {+ DiffLine.Action action = item.getModelObject().getAction();+ if (action == DELETE)+ setVisible(getOldComments() != null);+ else if (action == ADD)+ setVisible(getNewComments() != null);+ else+ setVisible(getOldComments() != null || 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() {- oldCommentsModel.detach();- newCommentsModel.detach();+ repoModel.detach();+ allowToAddCommentModel.detach();+super.onDetach();}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/view/BlobRenderInfo.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/view/BlobRenderInfo.javadeleted file mode 100644index 19f9158cae..0000000000--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/view/BlobRenderInfo.java+++ /dev/null@@ -1,32 +0,0 @@-package com.pmease.gitplex.web.component.view;--import java.io.Serializable;--@SuppressWarnings("serial")-public class BlobRenderInfo implements Serializable {-- private final String path;-- private final String revision;-- private final int mode;-- public BlobRenderInfo(String path, String revision, int mode) {- this.path = path;- this.revision = revision;- this.mode = mode;- }-- public String getPath() {- return path;- }-- public String getRevision() {- return revision;- }-- public int getMode() {- return mode;- }--}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/view/BlobViewPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/view/BlobViewPanel.javaindex b1b639c8c5..3b93eedbe9 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/view/BlobViewPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/view/BlobViewPanel.java@@ -6,7 +6,8 @@ import org.apache.wicket.markup.html.panel.Panel;import org.apache.wicket.model.IModel;import org.eclipse.jgit.lib.FileMode;-import com.pmease.commons.git.GitText;+import com.pmease.commons.git.BlobInfo;+import com.pmease.commons.git.BlobText;import com.pmease.commons.util.MediaTypes;import com.pmease.gitplex.core.GitPlex;import com.pmease.gitplex.core.model.Repository;@@ -20,30 +21,26 @@ public class BlobViewPanel extends Panel {private final IModel<Repository> repoModel;- private final BlobRenderInfo blobInfo;+ private final BlobInfo blobInfo;- private final IModel<byte[]> blobContentModel;-- public BlobViewPanel(String id, IModel<Repository> repoModel, BlobRenderInfo blobInfo,- IModel<byte[]> blobContentModel) {+ public BlobViewPanel(String id, IModel<Repository> repoModel, BlobInfo blobInfo) {super(id);this.repoModel = repoModel;this.blobInfo = blobInfo;- this.blobContentModel = blobContentModel;}@Overrideprotected void onInitialize() {super.onInitialize();- byte[] content = blobContentModel.getObject();+ byte[] content = repoModel.getObject().getBlobContent(blobInfo);if (blobInfo.getMode() == FileMode.TYPE_GITLINK) {add(new GitLink("blob", new String(content)));} else if (blobInfo.getMode() == FileMode.TYPE_SYMLINK) {add(new SymbolLink("blob", repoModel, blobInfo.getRevision(),blobInfo.getPath(), new String(content)));- } else if (blobContentModel.getObject().length == 0) {+ } else if (content.length == 0) {add(new Label("blob", "<i class='fa fa-info-circle'></i> <em>File is empty</em>").setEscapeModelStrings(false));} else {final MediaType mediaType = MediaTypes.detectFrom(content, blobInfo.getPath());@@ -54,9 +51,9 @@ public class BlobViewPanel extends Panel {break;}if (renderer != null) {- add(renderer.render("blob", blobInfo, blobContentModel));+ add(renderer.render("blob", repoModel, blobInfo));} else {- GitText text = GitText.from(content);+ BlobText text = repoModel.getObject().getBlobText(blobInfo);if (text != null) {add(new TextViewPanel("blob", blobInfo, text));} else {@@ -70,7 +67,6 @@ public class BlobViewPanel extends Panel {@Overrideprotected void onDetach() {repoModel.detach();- blobContentModel.detach();super.onDetach();}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/view/TextViewPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/view/TextViewPanel.javaindex 117b70eec5..6a8c043167 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/view/TextViewPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/view/TextViewPanel.java@@ -2,18 +2,19 @@ package com.pmease.gitplex.web.component.view;import org.apache.wicket.markup.html.panel.Panel;-import com.pmease.commons.git.GitText;+import com.pmease.commons.git.BlobInfo;+import com.pmease.commons.git.BlobText;@SuppressWarnings("serial")public class TextViewPanel extends Panel {@SuppressWarnings("unused")- private final BlobRenderInfo blobInfo;+ private final BlobInfo blobInfo;@SuppressWarnings("unused")- private final GitText blobText;+ private final BlobText blobText;- public TextViewPanel(String id, BlobRenderInfo blobInfo, GitText blobText) {+ public TextViewPanel(String id, BlobInfo blobInfo, BlobText blobText) {super(id);this.blobInfo = blobInfo;diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/extensionpoint/DiffRenderer.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/extensionpoint/DiffRenderer.javaindex 9a275825da..f0693f1f3c 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/extensionpoint/DiffRenderer.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/extensionpoint/DiffRenderer.java@@ -3,9 +3,9 @@ package com.pmease.gitplex.web.extensionpoint;import org.apache.wicket.markup.html.panel.Panel;import org.apache.wicket.model.IModel;-import com.pmease.gitplex.web.component.diff.BlobDiffInfo;+import com.pmease.commons.git.RevAwareChange;+import com.pmease.gitplex.core.model.Repository;public interface DiffRenderer {- Panel render(String panelId, BlobDiffInfo diffInfo,- IModel<byte[]> originalBlobContentModel, IModel<byte[]> revisedBlobContentModel);+ Panel render(String panelId, IModel<Repository> repoModel, RevAwareChange diffInfo);}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/extensionpoint/MediaRenderer.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/extensionpoint/MediaRenderer.javaindex a6827e8354..a4cede5d74 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/extensionpoint/MediaRenderer.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/extensionpoint/MediaRenderer.java@@ -3,8 +3,9 @@ package com.pmease.gitplex.web.extensionpoint;import org.apache.wicket.markup.html.panel.Panel;import org.apache.wicket.model.IModel;-import com.pmease.gitplex.web.component.view.BlobRenderInfo;+import com.pmease.commons.git.BlobInfo;+import com.pmease.gitplex.core.model.Repository;public interface MediaRenderer {- Panel render(String panelId, BlobRenderInfo blobInfo, IModel<byte[]> blobContentModel);+ Panel render(String panelId, IModel<Repository> repoModel, BlobInfo blobInfo);}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/git/GitUtils.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/git/GitUtils.javaindex d8649acbb2..32a1e0a35e 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/git/GitUtils.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/git/GitUtils.java@@ -110,7 +110,7 @@ public class GitUtils {String email = raw.substring(pos1 + 1, pos2 - 1);- return Git.newPersonIdent(name, email, when);+ return com.pmease.commons.git.GitUtils.newPersonIdent(name, email, when);}}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/git/command/BlameCommand.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/git/command/BlameCommand.javaindex f5bcb28a58..07251f5992 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/git/command/BlameCommand.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/git/command/BlameCommand.java@@ -19,7 +19,6 @@ import com.google.common.base.Strings;import com.google.common.collect.Lists;import com.google.common.io.LineProcessor;import com.google.common.io.Resources;-import com.pmease.commons.git.Git;import com.pmease.commons.git.command.GitCommand;import com.pmease.commons.util.execution.Commandline;import com.pmease.commons.util.execution.LineConsumer;@@ -147,8 +146,8 @@ public class BlameCommand extends GitCommand<List<BlameEntry>> {.summary(previous.getCommit().getSubject());} else {builder- .committer(Git.newPersonIdent(committerName, committerEmail, committerDate))- .author(Git.newPersonIdent(authorName, authorEmail, authorDate))+ .committer(com.pmease.commons.git.GitUtils.newPersonIdent(committerName, committerEmail, committerDate))+ .author(com.pmease.commons.git.GitUtils.newPersonIdent(authorName, authorEmail, authorDate)).summary(summary);}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/git/command/BranchForEachRefCommand.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/git/command/BranchForEachRefCommand.javaindex c5e887d7b7..e7725f8975 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/git/command/BranchForEachRefCommand.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/git/command/BranchForEachRefCommand.java@@ -10,7 +10,6 @@ import com.google.common.base.Strings;import com.google.common.collect.Iterables;import com.google.common.collect.Maps;import com.pmease.commons.git.BriefCommit;-import com.pmease.commons.git.Git;import com.pmease.commons.util.execution.Commandline;import com.pmease.gitplex.web.git.GitUtils;@@ -72,10 +71,10 @@ public class BranchForEachRefCommand extends ForEachRefCommand<Map<String, BriefString refname = pieces[i++];String sha = pieces[i++];- PersonIdent committer = Git.newPersonIdent(pieces[i++],+ PersonIdent committer = com.pmease.commons.git.GitUtils.newPersonIdent(pieces[i++],GitUtils.parseEmail(pieces[i++]),GitUtils.parseRawDate(pieces[i++]));- PersonIdent author = Git.newPersonIdent(pieces[i++],+ PersonIdent author = com.pmease.commons.git.GitUtils.newPersonIdent(pieces[i++],GitUtils.parseEmail(pieces[i++]),GitUtils.parseRawDate(pieces[i++]));diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/git/command/ListTagCommand.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/git/command/ListTagCommand.javaindex a4176535c7..caf82039fa 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/git/command/ListTagCommand.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/git/command/ListTagCommand.java@@ -17,7 +17,6 @@ import com.google.common.collect.Lists;import com.google.common.collect.Maps;import com.google.common.io.LineProcessor;import com.pmease.commons.git.Commit;-import com.pmease.commons.git.Git;import com.pmease.commons.git.command.GitCommand;import com.pmease.commons.util.execution.Commandline;import com.pmease.commons.util.execution.LineConsumer;@@ -81,9 +80,9 @@ public class ListTagCommand extends GitCommand<Map<String, Commit>> {int i = 0;currentNames = parseTagNames(pieces[i++]);currentBuilder.hash(pieces[i++]);- currentBuilder.author(Git.newPersonIdent(+ currentBuilder.author(com.pmease.commons.git.GitUtils.newPersonIdent(pieces[i++], GitUtils.parseEmail(pieces[i++]), GitUtils.parseRawDate(pieces[i++])));- currentBuilder.committer(Git.newPersonIdent(+ currentBuilder.committer(com.pmease.commons.git.GitUtils.newPersonIdent(pieces[i++], GitUtils.parseEmail(pieces[i++]), GitUtils.parseRawDate(pieces[i++])));}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/TestPage.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/TestPage.htmlindex d5157aa7ee..2c4e3cb253 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/TestPage.html+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/TestPage.html@@ -1,6 +1,5 @@<wicket:extend><div class="padder" style="background: white; padding: 50px;">- <p wicket:id="test">test</p>- <div wicket:id="diff">hello</div>+ <i class="fa fa-pin" style="transform: rotate(90deg)"></i></div></wicket:extend>diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/RepositoryPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/RepositoryPage.javaindex b236f2efed..46e4905e8d 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/RepositoryPage.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/RepositoryPage.java@@ -45,7 +45,7 @@ public abstract class RepositoryPage extends AccountPage {public static final String PARAM_PATH = "path";- protected IModel<Repository> repositoryModel;+ protected IModel<Repository> repoModel;protected final String currentRevision;@@ -86,7 +86,7 @@ public abstract class RepositoryPage extends AccountPage {+ getAccount() + "/" + repositoryName);}- repositoryModel = new RepositoryModel(repository);+ repoModel = new RepositoryModel(repository);currentRevision = PathUtils.normalize(params.get(PARAM_REVISION).toString());currentPath = PathUtils.normalize(params.get(PARAM_PATH).toString());}@@ -199,17 +199,17 @@ public abstract class RepositoryPage extends AccountPage {@Overrideprotected boolean isPermitted() {return SecurityUtils.getSubject().isPermitted(- ObjectPermission.ofRepositoryRead(repositoryModel.getObject()));+ ObjectPermission.ofRepositoryRead(repoModel.getObject()));}public Repository getRepository() {- return repositoryModel.getObject();+ return repoModel.getObject();}@Overrideprotected void onDetach() {- if (repositoryModel != null)- repositoryModel.detach();+ if (repoModel != null)+ repoModel.detach();super.onDetach();}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/admin/RepoOptionsPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/admin/RepoOptionsPage.javaindex 8b53cf87ad..65d3d041d7 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/admin/RepoOptionsPage.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/admin/RepoOptionsPage.java@@ -97,12 +97,12 @@ public class RepoOptionsPage extends RepoAdminPage {}}));form.add(new TextFieldElement<String>("description", "Description",- new PropertyModel<String>(repositoryModel, "description"))+ new PropertyModel<String>(repoModel, "description")).add(new PropertyValidator<String>()).setRequired(false));form.add(new CheckBoxElement("forkable", "Allow Forks",- new PropertyModel<Boolean>(repositoryModel, "forkable"),+ new PropertyModel<Boolean>(repoModel, "forkable"),Model.of("Enable/Disable whether this repository can be forked by others")));// Default branch is recorded in HEAD ref of the repository, since no any branches exist indiff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/code/blame/BlobBlamePage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/code/blame/BlobBlamePage.javaindex fee58644f0..48e9d9a854 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/code/blame/BlobBlamePage.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/code/blame/BlobBlamePage.java@@ -81,7 +81,7 @@ public class BlobBlamePage extends RepositoryInfoPage {protected void onInitialize() {super.onInitialize();- add(new PathsBreadcrumb("paths", repositoryModel, currentRevision, currentPath));+ add(new PathsBreadcrumb("paths", repoModel, currentRevision, currentPath));FileBlob blob = getBlob();if (blob.isText()) {diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/code/blob/RepoBlobPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/code/blob/RepoBlobPage.javaindex 3628ac1eef..9fb2c7b68f 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/code/blob/RepoBlobPage.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/code/blob/RepoBlobPage.java@@ -78,7 +78,7 @@ public class RepoBlobPage extends RepositoryInfoPage {public void onInitialize() {super.onInitialize();- add(new SourceBreadcrumbPanel("breadcrumb", repositoryModel, currentRevision, currentPath));+ add(new SourceBreadcrumbPanel("breadcrumb", repoModel, currentRevision, currentPath));add(new Label("shortMessage", new AbstractReadOnlyModel<String>() {diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/code/commit/RepoCommitPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/code/commit/RepoCommitPage.javaindex 075e2982c2..0f5f2fe8af 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/code/commit/RepoCommitPage.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/code/commit/RepoCommitPage.java@@ -148,9 +148,9 @@ public class RepoCommitPage extends RepositoryInfoPage implements CommitCommentsadd(createInRefListView("branches", RefType.BRANCH));add(createInRefListView("tags", RefType.TAG));- add(new DiffViewPanel("diffs", repositoryModel, getSince(), getUntil()));+ add(new DiffViewPanel("diffs", repoModel, getSince(), getUntil()));- add(new CommentListPanel("comments", repositoryModel, new AbstractReadOnlyModel<String>() {+ add(new CommentListPanel("comments", repoModel, new AbstractReadOnlyModel<String>() {@Overridepublic String getObject() {diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/code/commits/RepoCommitsPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/code/commits/RepoCommitsPage.javaindex 34896c3081..d2d79118c4 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/code/commits/RepoCommitsPage.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/code/commits/RepoCommitsPage.java@@ -68,7 +68,7 @@ public class RepoCommitsPage extends RepositoryInfoPage {protected void onInitialize() {super.onInitialize();- add(new RevisionSelector("revselector", repositoryModel, currentRevision, currentPath));+ add(new RevisionSelector("revselector", repoModel, currentRevision, currentPath));// BookmarkablePageLink<Void> homeLink = new BookmarkablePageLink<Void>("home",// SourceTreePage.class,// PageSpec.forRepository(getRepository()).add(PageSpec.OBJECT_ID, getRevision()));@@ -90,7 +90,7 @@ public class RepoCommitsPage extends RepositoryInfoPage {}});- add(new RepoCommitsPanel("commits", commitsModel, repositoryModel));+ add(new RepoCommitsPanel("commits", commitsModel, repoModel));add(new BookmarkablePageLink<Void>("newer", RepoCommitsPage.class,paramsOf(getRepository(), getCurrentRevision(), getCurrentPath(), page - 1)).setEnabled(page > 1));add(new BookmarkablePageLink<Void>("older", RepoCommitsPage.class,diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/code/tree/RepoTreePage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/code/tree/RepoTreePage.javaindex 0dc7864c9a..3840440f60 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/code/tree/RepoTreePage.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/code/tree/RepoTreePage.java@@ -62,10 +62,10 @@ public class RepoTreePage extends RepositoryInfoPage {}};- add(new RepoDescribePanel("description", repositoryModel).setVisible(getCurrentPath() != null));- add(new SourceBreadcrumbPanel("breadcrumb", repositoryModel, currentRevision, currentPath));- add(new RepoTreePanel("tree", repositoryModel, currentRevision, currentPath, nodesModel));- add(new ReadmePanel("readme", repositoryModel, currentRevision, nodesModel));+ add(new RepoDescribePanel("description", repoModel).setVisible(getCurrentPath() != null));+ add(new SourceBreadcrumbPanel("breadcrumb", repoModel, currentRevision, currentPath));+ add(new RepoTreePanel("tree", repoModel, currentRevision, currentPath, nodesModel));+ add(new ReadmePanel("readme", repoModel, currentRevision, nodesModel));}@Overridediff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/CommentThread.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/CommentThread.javadeleted file mode 100644index 1ea4c2aff6..0000000000--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/CommentThread.java+++ /dev/null@@ -1,43 +0,0 @@-package com.pmease.gitplex.web.page.repository.info.pullrequest;--import java.io.Serializable;-import java.util.List;--import javax.annotation.Nullable;--import com.pmease.gitplex.core.model.CommentPosition;-import com.pmease.gitplex.core.model.CommitComment;--@SuppressWarnings("serial")-public class CommentThread implements Comparable<CommentThread>, Serializable {-- private final CommentPosition position;-- private final List<CommitComment> comments;-- public CommentThread(@Nullable CommentPosition position, List<CommitComment> comments) {- this.position = position;- this.comments = comments;- }-- public CommentPosition getPosition() {- return position;- }-- public List<CommitComment> getComments() {- return comments;- }-- public CommitComment getFirstComment() {- return comments.get(0);- }-- public CommitComment getLastComment() {- return comments.get(comments.size()-1);- }-- @Override- public int compareTo(CommentThread o) {- return o.getLastComment().getId().compareTo(getLastComment().getId());- }-}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/CommentThreadPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/CommentThreadPanel.javaindex a95feeb268..b89a520a5c 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/CommentThreadPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/CommentThreadPanel.java@@ -1,9 +1,6 @@package com.pmease.gitplex.web.page.repository.info.pullrequest;-import java.util.ArrayList;-import java.util.Collections;import java.util.Date;-import java.util.HashMap;import java.util.List;import java.util.Map;@@ -14,13 +11,13 @@ import org.apache.wicket.markup.html.list.ListItem;import org.apache.wicket.markup.html.list.ListView;import org.apache.wicket.markup.html.panel.Panel;import org.apache.wicket.model.IModel;-import org.apache.wicket.model.LoadableDetachableModel;import org.apache.wicket.model.Model;+import org.apache.wicket.request.mapper.parameter.PageParameters;-import com.pmease.gitplex.core.GitPlex;-import com.pmease.gitplex.core.manager.ThreadVisitManager;+import com.pmease.gitplex.core.comment.CommentThread;import com.pmease.gitplex.core.model.CommentPosition;import com.pmease.gitplex.core.model.CommitComment;+import com.pmease.gitplex.core.model.PullRequest;import com.pmease.gitplex.web.component.label.AgeLabel;import com.pmease.gitplex.web.component.markdown.MarkdownPanel;import com.pmease.gitplex.web.component.user.AvatarByUser;@@ -29,51 +26,20 @@ import com.pmease.gitplex.web.model.UserModel;@SuppressWarnings("serial")public class CommentThreadPanel extends Panel {- private final IModel<List<CommitComment>> commentsModel;+ private final IModel<PullRequest> requestModel;private final IModel<List<CommentThread>> threadsModel;private final IModel<Map<CommentPosition, Date>> visitsModel;- public CommentThreadPanel(String id, final IModel<List<CommitComment>> commentsModel) {+ public CommentThreadPanel(String id, final IModel<PullRequest> requestModel,+ final IModel<List<CommentThread>> threadsModel,+ final IModel<Map<CommentPosition, Date>> visitsModel) {super(id);- this.commentsModel = commentsModel;-- threadsModel = new LoadableDetachableModel<List<CommentThread>>() {-- @Override- protected List<CommentThread> load() {- Map<CommentPosition, List<CommitComment>> threadMap = new HashMap<>();- for (CommitComment comment: commentsModel.getObject()) {- List<CommitComment> threadComments = threadMap.get(comment.getPosition());- if (threadComments == null) {- threadComments = new ArrayList<>();- threadMap.put(comment.getPosition(), threadComments);- }- threadComments.add(comment);- }-- List<CommentThread> threads = new ArrayList<>();- for (Map.Entry<CommentPosition, List<CommitComment>> entry: threadMap.entrySet())- threads.add(new CommentThread(entry.getKey(), entry.getValue()));-- Collections.sort(threads);- return threads;- }-- };-- visitsModel = new LoadableDetachableModel<Map<CommentPosition, Date>>() {-- @Override- protected Map<CommentPosition, Date> load() {- CommitComment aComment = commentsModel.getObject().get(0);- return GitPlex.getInstance(ThreadVisitManager.class).calcVisitMap(- aComment.getRepository(), aComment.getCommit());- }-- };+ this.requestModel = requestModel;+ this.visitsModel = visitsModel;+ this.threadsModel = threadsModel;}@Override@@ -96,7 +62,10 @@ public class CommentThreadPanel extends Panel {} else if (thread.getPosition().getLineNo() == null) {// TODO: navigate to commit file comments page} else {-+ PageParameters params = RequestComparePage.params4(+ requestModel.getObject(),+ null, null, null, thread.getLastComment().getId());+ setResponsePage(RequestComparePage.class, params);}}@@ -113,12 +82,12 @@ public class CommentThreadPanel extends Panel {link.add(new Label("position", "line " + thread.getPosition().getLineNo() + " of file " + thread.getPosition().getFilePath()));}- link.add(new AgeLabel("age", Model.of(thread.getLastComment().getDate())));+ link.add(new AgeLabel("age", Model.of(thread.getLastComment().getCommentDate())));int unread = 0;for (CommitComment comment: thread.getComments()) {Date lastVisit = visitsModel.getObject().get(thread.getPosition());- if (lastVisit == null || comment.getDate().after(lastVisit))+ if (lastVisit == null || comment.getCommentDate().after(lastVisit))unread++;}link.add(new Label("unread", unread));@@ -143,7 +112,7 @@ public class CommentThreadPanel extends Panel {@Overrideprotected void onDetach() {- commentsModel.detach();+ requestModel.detach();threadsModel.detach();visitsModel.detach();diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestActivitiesPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestActivitiesPage.javaindex 06798d077d..14e30f0320 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestActivitiesPage.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestActivitiesPage.java@@ -60,7 +60,7 @@ public class RequestActivitiesPage extends RequestDetailPage {activities.add(new OpenPullRequest(request));- for (PullRequestComment comment: request.getComments()) {+ for (PullRequestComment comment: request.getRequestComments()) {activities.add(new CommentPullRequest(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 bc09108fd1..1e9b9ce986 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,22 +1,33 @@<wicket:extend><div class="compare">- <div class="comparison-choices clearfix">- <div class="comparison-base pull-left">- <label>Comparision Base:</label>- <span class="btn btn-default" wicket:id="baseSelector">+ <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">+ <label>Original:</label>+ <span class="btn btn-default" wicket:id="originalSelector"><i class="fa fa-commit"></i> <span wicket:id="label"></span> <i class="caret"></i></span>- <div wicket:id="baseChoices"></div>+ <div wicket:id="originalChoices"></div></div>- <div class="comparison-head pull-left">- <label>Comparision Head:</label>- <span class="btn btn-default" wicket:id="headSelector">+ <div class="revised pull-left">+ <label>Revised:</label>+ <span class="btn btn-default" wicket:id="revisedSelector"><i class="fa fa-commit"></i> <span wicket:id="label"></span> <i class="caret"></i></span>- <div wicket:id="headChoices"></div>+ <div wicket:id="revisedChoices"></div></div></div>- <table class="compare-result">+ <table class="body"><tr><td class="nav"><div class="panel panel-default">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 8b0dc4220a..1f445ae814 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@@ -1,7 +1,10 @@package com.pmease.gitplex.web.page.repository.info.pullrequest;+import static com.pmease.commons.git.Change.Status.UNCHANGED;+import java.io.Serializable;import java.util.ArrayList;+import java.util.Date;import java.util.LinkedHashMap;import java.util.List;import java.util.Map;@@ -31,17 +34,25 @@ import org.apache.wicket.request.mapper.parameter.PageParameters;import org.eclipse.jgit.lib.FileMode;import com.google.common.base.Preconditions;+import com.pmease.commons.git.BlobInfo;+import com.pmease.commons.git.BlobText;import com.pmease.commons.git.Change;import com.pmease.commons.git.Commit;import com.pmease.commons.git.GitUtils;+import com.pmease.commons.git.RevAwareChange;import com.pmease.commons.git.TreeNode;+import com.pmease.commons.hibernate.dao.Dao;import com.pmease.commons.wicket.behavior.TooltipBehavior;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.CommentLoader;+import com.pmease.gitplex.core.model.CommitComment;import com.pmease.gitplex.core.model.IntegrationInfo;import com.pmease.gitplex.core.model.PullRequest;import com.pmease.gitplex.core.model.PullRequestUpdate;-import com.pmease.gitplex.web.component.diff.BlobDiffInfo;import com.pmease.gitplex.web.component.diff.BlobDiffPanel;import com.pmease.gitplex.web.component.diff.ChangedFilesPanel;import com.pmease.gitplex.web.component.diff.DiffTreePanel;@@ -49,16 +60,26 @@ import com.pmease.gitplex.web.component.diff.DiffTreePanel;@SuppressWarnings("serial")public class RequestComparePage extends RequestDetailPage {- // base commit represents comparison base- private String baseCommit;+ private String originalCommit;- // head commit represents comparison head- private String headCommit;+ private String revisedCommit;private String filePath;+ private Long commentId;+private boolean changedOnly = true;+ private IModel<CommitComment> commentModel = new LoadableDetachableModel<CommitComment>() {++ @Override+ protected CommitComment load() {+ Preconditions.checkNotNull(commentId);+ return GitPlex.getInstance(Dao.class).load(CommitComment.class, commentId);+ }++ };+// map commit name to comit hashprivate IModel<Map<String, CommitDescription>> commitsModel =new LoadableDetachableModel<Map<String, CommitDescription>>() {@@ -111,53 +132,61 @@ public class RequestComparePage extends RequestDetailPage {@Overrideprotected List<Change> load() {- return getRepository().git().listFileChanges(baseCommit, headCommit, null, true);+ return getRepository().git().listFileChanges(originalCommit, revisedCommit, null, true);}};public RequestComparePage(PageParameters params) {super(params);++ filePath = params.get("path").toString();+ commentId = params.get("comment").toLongObject();- baseCommit = params.get("base").toString();- headCommit = params.get("head").toString();-- if (baseCommit != null) {- if (!commitsModel.getObject().containsKey(baseCommit))- throw new IllegalArgumentException("Commit '" + baseCommit + "' is not relevant to current pull request.");- } else {- baseCommit = getPullRequest().getBaseCommit();+ originalCommit = params.get("original").toString();+ revisedCommit = params.get("revised").toString();++ if (!(originalCommit == null && revisedCommit == null || originalCommit != null && revisedCommit != 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 (headCommit != null) {- if (!commitsModel.getObject().containsKey(headCommit))- throw new IllegalArgumentException("Commit '" + headCommit + "' is not relevant to current pull request.");- } else {- headCommit = getPullRequest().getLatestUpdate().getHeadCommit();++ if (revisedCommit != null) {+ if (!commitsModel.getObject().containsKey(revisedCommit))+ throw new IllegalArgumentException("Commit '" + revisedCommit + "' is not relevant to current pull request.");}- filePath = params.get("path").toString();+ if (filePath != null && originalCommit == null)+ throw new IllegalArgumentException("Param 'path' can only be used together with param 'original' and 'revised'.");}-+@Overrideprotected void onInitialize() {super.onInitialize();- WebMarkupContainer baseSelector = new WebMarkupContainer("baseSelector");+ 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>() {@Overrideprotected String load() {- CommitDescription description = commitsModel.getObject().get(baseCommit);+ CommitDescription description = commitsModel.getObject().get(originalCommit);Preconditions.checkNotNull(description);if (description.getName() != null)- return GitUtils.abbreviateSHA(baseCommit) + " - " + description.getName();+ return GitUtils.abbreviateSHA(originalCommit) + " - " + description.getName();else- return GitUtils.abbreviateSHA(baseCommit);+ return GitUtils.abbreviateSHA(originalCommit);}}));- DropdownPanel baseChoicesDropdown = new DropdownPanel("baseChoices", false) {+ DropdownPanel baseChoicesDropdown = new DropdownPanel("originalChoices", false) {@Overrideprotected Component newContent(String id) {@@ -172,29 +201,29 @@ public class RequestComparePage extends RequestDetailPage {@Overrideprotected String load() {- CommitDescription description = commitsModel.getObject().get(baseCommit);+ CommitDescription description = commitsModel.getObject().get(originalCommit);Preconditions.checkNotNull(description);return description.getSubject();}}));- WebMarkupContainer headSelector = new WebMarkupContainer("headSelector");+ WebMarkupContainer headSelector = new WebMarkupContainer("revisedSelector");add(headSelector);headSelector.add(new Label("label", new LoadableDetachableModel<String>() {@Overrideprotected String load() {- CommitDescription description = commitsModel.getObject().get(headCommit);+ CommitDescription description = commitsModel.getObject().get(revisedCommit);Preconditions.checkNotNull(description);if (description.getName() != null)- return GitUtils.abbreviateSHA(headCommit) + " - " + description.getName();+ return GitUtils.abbreviateSHA(revisedCommit) + " - " + description.getName();else- return GitUtils.abbreviateSHA(headCommit);+ return GitUtils.abbreviateSHA(revisedCommit);}}));- DropdownPanel headChoicesDropdown = new DropdownPanel("headChoices", false) {+ DropdownPanel headChoicesDropdown = new DropdownPanel("revisedChoices", false) {@Overrideprotected Component newContent(String id) {@@ -209,7 +238,7 @@ public class RequestComparePage extends RequestDetailPage {@Overrideprotected String load() {- CommitDescription description = commitsModel.getObject().get(headCommit);+ CommitDescription description = commitsModel.getObject().get(revisedCommit);Preconditions.checkNotNull(description);return description.getSubject();}@@ -228,31 +257,49 @@ public class RequestComparePage extends RequestDetailPage {}));- BlobDiffInfo blobDiffInfo = null;- List<Change> changes = changesModel.getObject();- if (filePath != null) {- for (Change change: changes) {- if (filePath.equals(change.getOldPath()) || filePath.equals(change.getNewPath())) {- blobDiffInfo = new BlobDiffInfo(change, baseCommit, headCommit);- break;+ 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 (blobDiffInfo == null) {- List<TreeNode> result = getRepository().git().listTree(headCommit, filePath);- if (!result.isEmpty() && result.get(0).getMode() != FileMode.TYPE_TREE) {- TreeNode blobNode = result.get(0);- blobDiffInfo = new BlobDiffInfo(BlobDiffInfo.Status.UNCHANGED, filePath, filePath,- blobNode.getMode(), blobNode.getMode(), baseCommit, headCommit);+ 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);}+ } else if (commentId == null) {+ originalCommit = getPullRequest().getBaseCommit();+ revisedCommit = getPullRequest().getLatestUpdate().getHeadCommit();} else {- if (!changes.isEmpty())- blobDiffInfo = new BlobDiffInfo(changes.get(0), baseCommit, headCommit);+}- if (blobDiffInfo != null)- add(new BlobDiffPanel("blobDiff", repositoryModel, blobDiffInfo).setOutputMarkupId(true));- else++ if (change != null) {+ BlobDiffPanel blobDiffPanel = new BlobDiffPanel("blobDiff", repoModel,+ change, loadComments(change), lineNo);+ blobDiffPanel.setOutputMarkupId(true);+ add(blobDiffPanel);+ } else {add(new WebMarkupContainer("blobDiff").setOutputMarkupId(true));+ }add(newCompareResultComponent());}@@ -273,7 +320,7 @@ public class RequestComparePage extends RequestDetailPage {compareResult.setEscapeModelStrings(false);}} else {- compareResult = new DiffTreePanel("compareResult", repositoryModel, changesModel, baseCommit, headCommit) {+ compareResult = new DiffTreePanel("compareResult", repoModel, changesModel, originalCommit, revisedCommit) {@Overrideprotected WebMarkupContainer newBlobLink(String id, final Change change) {@@ -284,9 +331,9 @@ public class RequestComparePage extends RequestDetailPage {protected void onInitialize() {super.onInitialize();- BlobDiffInfo blobDiffInfo = getBlobDiffInfo();- if (blobDiffInfo != null)- reveal(blobDiffInfo);+ RevAwareChange activeChange = getActiveChange();+ if (activeChange != null)+ reveal(activeChange);}};@@ -295,10 +342,10 @@ public class RequestComparePage extends RequestDetailPage {return compareResult;}- private BlobDiffInfo getBlobDiffInfo() {+ private RevAwareChange getActiveChange() {Component panel = getPage().get("blobDiff");if (panel instanceof BlobDiffPanel)- return ((BlobDiffPanel) panel).getBlobDiffInfo();+ return ((BlobDiffPanel) panel).getChange();elsereturn null;}@@ -307,17 +354,56 @@ public class RequestComparePage extends RequestDetailPage {public void onDetach() {commitsModel.detach();changesModel.detach();+ commentModel.detach();super.onDetach();}++ private ChangeComments loadComments(RevAwareChange change) {+ BlobLoader blobLoader = new BlobLoader() {- public static PageParameters params4(PullRequest request, String baseCommit, String headCommit, @Nullable String filePath) {+ @Override+ public List<String> loadBlob(BlobInfo blobInfo) {+ BlobText blobText = repoModel.getObject().getBlobText(blobInfo);+ return blobText!=null?blobText.getLines():null;+ }++ };+ CommentLoader commentLoader = new CommentLoader() {++ @Override+ public List<CommitComment> loadComments(String commit) {+ List<CommitComment> comments = getPullRequest().getCommitComments().get(commit);+ if (comments == null)+ return new ArrayList<>();+ else+ return comments;+ }++ };+ LinkedHashMap<String, Date> commits = new LinkedHashMap<>();+ String baseCommit = getPullRequest().getBaseCommit();+ commits.put(baseCommit, getRepository().git().showRevision(baseCommit).getCommitter().getWhen());+ for (int i=getPullRequest().getSortedUpdates().size()-1; i>=0; i--) {+ for (Commit commit: getPullRequest().getSortedUpdates().get(i).getCommits())+ commits.put(commit.getHash(), commit.getCommitter().getWhen());+ }++ return new ChangeComments(change, commits, commentLoader, blobLoader);+ }++ public static PageParameters params4(PullRequest request, @Nullable String originalCommit,+ @Nullable String revisedCommit, @Nullable String filePath, @Nullable Long commentId) {PageParameters params = RequestDetailPage.params4(request);- params.set("base", baseCommit);- params.set("head", headCommit);+ if (originalCommit != null)+ params.set("original", originalCommit);+ if (revisedCommit != null)+ params.set("revised", revisedCommit);if (filePath != null)params.set("path", filePath);+ if (commentId != null)+ params.set("comment", commentId);return params;}@@ -380,10 +466,10 @@ public class RequestComparePage extends RequestDetailPage {Map.Entry<String, CommitDescription> entry = item.getModelObject();if (forBase) {setResponsePage(RequestComparePage.class,- params4(getPullRequest(), entry.getKey(), headCommit, null));+ params4(getPullRequest(), entry.getKey(), revisedCommit, filePath, commentId));} else {setResponsePage(RequestComparePage.class,- params4(getPullRequest(), baseCommit, entry.getKey(), null));+ params4(getPullRequest(), originalCommit, entry.getKey(), filePath, commentId));}}@@ -430,18 +516,21 @@ public class RequestComparePage extends RequestDetailPage {protected void onComponentTag(ComponentTag tag) {super.onComponentTag(tag);- BlobDiffInfo blobDiffInfo = getBlobDiffInfo();- if (blobDiffInfo != null- && Objects.equals(change.getOldPath(), blobDiffInfo.getOldPath())- && Objects.equals(change.getNewPath(), blobDiffInfo.getNewPath())) {+ Change activeChange = getActiveChange();+ if (activeChange != null+ && Objects.equals(change.getOldPath(), activeChange.getOldPath())+ && Objects.equals(change.getNewPath(), activeChange.getNewPath())) {tag.put("class", "active");}}@Overridepublic void onClick(AjaxRequestTarget target) {- BlobDiffPanel panel = new BlobDiffPanel("blobDiff", repositoryModel,- new BlobDiffInfo(change, baseCommit, headCommit));+ filePath = change.getPath();++ RevAwareChange revAwareChange = new RevAwareChange(change, originalCommit, revisedCommit);+ BlobDiffPanel panel = new BlobDiffPanel("blobDiff", repoModel,+ revAwareChange, loadComments(revAwareChange), -1);panel.setOutputMarkupId(true);RequestComparePage.this.replace(panel);@@ -451,6 +540,7 @@ public class RequestComparePage extends RequestDetailPage {target.add(panel);target.add(this);+ target.add(getPage().get("commentActions"));}}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestDetailPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestDetailPage.javaindex f7752da167..0589f202fc 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestDetailPage.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestDetailPage.java@@ -535,7 +535,7 @@ public abstract class RequestDetailPage extends RepositoryInfoPage implements Corequest,request.getLatestUpdate().getHeadCommit(),request.getIntegrationInfo().getIntegrationHead(),- null);+ null, null);Link<Void> link = new BookmarkablePageLink<Void>("preview", RequestComparePage.class, params);link.setVisible(!integrationInfo.getIntegrationHead().equals(integrationInfo.getRequestHead()));diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestUpdatesPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestUpdatesPage.javaindex eceab82e7f..34e4628ecb 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestUpdatesPage.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestUpdatesPage.java@@ -61,7 +61,7 @@ public class RequestUpdatesPage extends RequestDetailPage {PullRequestUpdate update = item.getModelObject();PageParameters params = RequestComparePage.params4(- update.getRequest(), update.getBaseCommit(), update.getHeadCommit(), null);+ update.getRequest(), update.getBaseCommit(), update.getHeadCommit(), null, null);Link<Void> updateLink = new BookmarkablePageLink<Void>("updateLink", RequestComparePage.class, params);List<PullRequestUpdate> updates = update.getRequest().getSortedUpdates();updateLink.add(new Label("updateNo", updates.size() - updates.indexOf(update)));diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/UpdateCommitsPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/UpdateCommitsPanel.javaindex 974f7f7268..2d61389576 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/UpdateCommitsPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/UpdateCommitsPanel.java@@ -1,8 +1,11 @@package com.pmease.gitplex.web.page.repository.info.pullrequest;import java.util.ArrayList;+import java.util.Date;+import java.util.HashMap;import java.util.HashSet;import java.util.List;+import java.util.Map;import java.util.Set;import org.apache.wicket.Component;@@ -22,9 +25,10 @@ import org.apache.wicket.model.Model;import com.pmease.commons.git.Commit;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.manager.CommitCommentManager;+import com.pmease.gitplex.core.comment.CommentThread;+import com.pmease.gitplex.core.model.CommentPosition;import com.pmease.gitplex.core.model.CommitComment;+import com.pmease.gitplex.core.model.PullRequest;import com.pmease.gitplex.core.model.PullRequestUpdate;import com.pmease.gitplex.core.model.Verification;import com.pmease.gitplex.web.component.user.AvatarMode;@@ -91,13 +95,35 @@ public class UpdateCommitsPanel extends Panel {item.add(link);- item.add(new CommentThreadPanel("threads", new LoadableDetachableModel<List<CommitComment>>() {+ item.add(new CommentThreadPanel("threads", new AbstractReadOnlyModel<PullRequest>() {@Override- protected List<CommitComment> load() {- CommitCommentManager manager = GitPlex.getInstance(CommitCommentManager.class);- return manager.findByCommit(getUpdate().getRequest().getTarget().getRepository(),- item.getModelObject().getHash());+ public PullRequest getObject() {+ return getUpdate().getRequest();+ }++ }, new LoadableDetachableModel<List<CommentThread>>() {++ @Override+ protected List<CommentThread> load() {+ List<CommitComment> comments = getUpdate().getRequest().getCommitComments()+ .get(item.getModelObject().getHash());+ if (comments == null)+ return new ArrayList<>();+ else+ return CommentThread.asThreads(comments);+ }++ }, new LoadableDetachableModel<Map<CommentPosition, Date>>() {++ @Override+ protected Map<CommentPosition, Date> load() {+ Map<CommentPosition, Date> visits = getUpdate().getRequest().getCommentVisits()+ .get(item.getModelObject().getHash());+ if (visits == null)+ return new HashMap<>();+ else+ return visits;}}));diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/activity/OpenActivityPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/activity/OpenActivityPanel.javaindex b2fa471fd5..b766e68914 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/activity/OpenActivityPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/activity/OpenActivityPanel.java@@ -1,6 +1,10 @@package com.pmease.gitplex.web.page.repository.info.pullrequest.activity;+import java.util.ArrayList;+import java.util.Date;+import java.util.HashMap;import java.util.List;+import java.util.Map;import org.apache.commons.lang3.StringUtils;import org.apache.wicket.ajax.AjaxRequestTarget;@@ -16,8 +20,9 @@ import org.apache.wicket.model.LoadableDetachableModel;import com.pmease.commons.hibernate.dao.Dao;import com.pmease.gitplex.core.GitPlex;+import com.pmease.gitplex.core.comment.CommentThread;import com.pmease.gitplex.core.manager.AuthorizationManager;-import com.pmease.gitplex.core.manager.CommitCommentManager;+import com.pmease.gitplex.core.model.CommentPosition;import com.pmease.gitplex.core.model.CommitComment;import com.pmease.gitplex.core.model.PullRequest;import com.pmease.gitplex.web.page.repository.info.pullrequest.CommentThreadPanel;@@ -25,16 +30,19 @@ import com.pmease.gitplex.web.page.repository.info.pullrequest.CommentThreadPane@SuppressWarnings("serial")public class OpenActivityPanel extends Panel {+ private IModel<PullRequest> requestModel;+private String description;- public OpenActivityPanel(String id, IModel<PullRequest> model) {- super(id, model);+ public OpenActivityPanel(String id, IModel<PullRequest> requestModel) {+ super(id);+ this.requestModel = requestModel;}private Fragment renderForView() {Fragment fragment = new Fragment("description", "viewFrag", this);- description = getPullRequest().getDescription();+ description = requestModel.getObject().getDescription();if (StringUtils.isNotBlank(description))fragment.add(new MultiLineLabel("content", description));else@@ -44,7 +52,7 @@ public class OpenActivityPanel extends Panel {@Overridepublic void onClick(AjaxRequestTarget target) {- description = getPullRequest().getDescription();+ description = requestModel.getObject().getDescription();Fragment fragment = new Fragment("description", "editFrag", OpenActivityPanel.this);@@ -81,7 +89,7 @@ public class OpenActivityPanel extends Panel {@Overridepublic void onClick(AjaxRequestTarget target) {- PullRequest request = getPullRequest();+ PullRequest request = requestModel.getObject();request.setDescription(description);GitPlex.getInstance(Dao.class).persist(request);@@ -113,7 +121,7 @@ public class OpenActivityPanel extends Panel {super.onConfigure();setVisible(GitPlex.getInstance(AuthorizationManager.class)- .canModify(getPullRequest()));+ .canModify(requestModel.getObject()));}});@@ -128,21 +136,39 @@ public class OpenActivityPanel extends Panel {super.onInitialize();add(renderForView());- add(new CommentThreadPanel("baseThreads", new LoadableDetachableModel<List<CommitComment>>() {+ add(new CommentThreadPanel("baseThreads", requestModel, new LoadableDetachableModel<List<CommentThread>>() {@Override- protected List<CommitComment> load() {- CommitCommentManager manager = GitPlex.getInstance(CommitCommentManager.class);- return manager.findByCommit(getPullRequest().getTarget().getRepository(),- getPullRequest().getBaseCommit());+ protected List<CommentThread> load() {+ PullRequest request = requestModel.getObject();+ List<CommitComment> comments = request.getCommitComments().get(request.getBaseCommit());+ if (comments == null)+ return new ArrayList<>();+ else+ return CommentThread.asThreads(comments);+ }++ }, new LoadableDetachableModel<Map<CommentPosition, Date>>() {++ @Override+ protected Map<CommentPosition, Date> load() {+ PullRequest request = requestModel.getObject();+ Map<CommentPosition, Date> visits = request.getCommentVisits().get(request.getBaseCommit());+ if (visits == null)+ return new HashMap<>();+ else+ return visits;}}));}- private PullRequest getPullRequest() {- return (PullRequest) getDefaultModelObject();+ @Override+ protected void onDetach() {+ requestModel.detach();++ super.onDetach();}}