Skip to content

The Unified and Autonomous Development Platform

midwork

robin shine12f779fa07fc
diff --git a/commons.git/src/main/java/com/pmease/commons/git/BlobChange.java b/commons.git/src/main/java/com/pmease/commons/git/BlobChange.java
index 6c04df447f..83634657e8 100644
--- a/commons.git/src/main/java/com/pmease/commons/git/BlobChange.java
+++ b/commons.git/src/main/java/com/pmease/commons/git/BlobChange.java
@@ -14,6 +14,7 @@ import com.google.common.base.Preconditions;
import com.pmease.commons.lang.diff.DiffBlock;
import com.pmease.commons.lang.diff.DiffMatchPatch.Operation;
import com.pmease.commons.lang.diff.DiffUtils;
+import com.pmease.commons.lang.tokenizers.CmToken;
@SuppressWarnings("serial")
public abstract class BlobChange implements Serializable {
@@ -24,7 +25,7 @@ public abstract class BlobChange implements Serializable {
private final BlobIdent newBlobIdent;
- private transient List<DiffBlock> diffBlocks;
+ private transient List<DiffBlock<List<CmToken>>> diffBlocks;
public BlobChange(String oldCommitHash, String newCommitHash, DiffEntry diffEntry) {
type = diffEntry.getChangeType();
@@ -60,7 +61,7 @@ public abstract class BlobChange implements Serializable {
return newBlobIdent.path!=null? newBlobIdent: oldBlobIdent;
}
- public List<DiffBlock> getDiffBlocks() {
+ public List<DiffBlock<List<CmToken>>> getDiffBlocks() {
if (diffBlocks == null) {
try {
if (type == ChangeType.ADD) {
@@ -110,18 +111,18 @@ public abstract class BlobChange implements Serializable {
public int getAdditions() {
int additions = 0;
- for (DiffBlock diff: getDiffBlocks()) {
+ for (DiffBlock<List<CmToken>> diff: getDiffBlocks()) {
if (diff.getOperation() == Operation.INSERT)
- additions += diff.getLines().size();
+ additions += diff.getUnits().size();
}
return additions;
}
public int getDeletions() {
int deletions = 0;
- for (DiffBlock diff: getDiffBlocks()) {
+ for (DiffBlock<List<CmToken>> diff: getDiffBlocks()) {
if (diff.getOperation() == Operation.DELETE)
- deletions += diff.getLines().size();
+ deletions += diff.getUnits().size();
}
return deletions;
}
diff --git a/commons.lang/src/main/java/com/pmease/commons/lang/diff/AroundContext.java b/commons.lang/src/main/java/com/pmease/commons/lang/diff/AroundContext.java
deleted file mode 100644
index bd0206c8c9..0000000000
--- a/commons.lang/src/main/java/com/pmease/commons/lang/diff/AroundContext.java
+++ /dev/null
@@ -1,52 +0,0 @@
-package com.pmease.commons.lang.diff;
-
-import java.io.Serializable;
-import java.util.List;
-
-@SuppressWarnings("serial")
-public class AroundContext implements Serializable {
-
- private List<DiffLine> diffLines;
-
- private final int line;
-
- private final boolean aboveOmitted;
-
- private final boolean belowOmitted;
-
- public AroundContext(List<DiffLine> diffLines, int line, boolean aboveOmitted, boolean belowOmitted) {
- this.diffLines = diffLines;
- this.line = line;
- this.aboveOmitted = aboveOmitted;
- this.belowOmitted = belowOmitted;
- }
-
- public List<DiffLine> getDiffLines() {
- return diffLines;
- }
-
- public void setDiffLines(List<DiffLine> diffLines) {
- this.diffLines = diffLines;
- }
-
- public int getLine() {
- return line;
- }
-
- public boolean isAboveOmitted() {
- return aboveOmitted;
- }
-
- public boolean isBelowOmitted() {
- return belowOmitted;
- }
-
- @Override
- public String toString() {
- StringBuffer buffer = new StringBuffer();
- for (DiffLine diffLine: diffLines)
- buffer.append(diffLine).append("\n");
- return buffer.toString();
- }
-
-}
diff --git a/commons.lang/src/main/java/com/pmease/commons/lang/diff/DiffBlock.java b/commons.lang/src/main/java/com/pmease/commons/lang/diff/DiffBlock.java
index bac54843a5..e8267ce1db 100644
--- a/commons.lang/src/main/java/com/pmease/commons/lang/diff/DiffBlock.java
+++ b/commons.lang/src/main/java/com/pmease/commons/lang/diff/DiffBlock.java
@@ -1,26 +1,24 @@
package com.pmease.commons.lang.diff;
import java.io.Serializable;
-import java.util.ArrayList;
import java.util.List;
import com.pmease.commons.lang.diff.DiffMatchPatch.Operation;
-import com.pmease.commons.lang.tokenizers.CmToken;
-public class DiffBlock implements Serializable {
+public class DiffBlock<T> implements Serializable {
private static final long serialVersionUID = 1L;
private final DiffMatchPatch.Operation operation;
- private final List<List<CmToken>> lines;
+ private final List<T> units;
private final int oldStart, newStart;
- public DiffBlock(DiffMatchPatch.Operation operation, List<List<CmToken>> lines,
+ public DiffBlock(DiffMatchPatch.Operation operation, List<T> units,
int oldStart, int newStart) {
this.operation = operation;
- this.lines = lines;
+ this.units = units;
this.oldStart = oldStart;
this.newStart = newStart;
}
@@ -29,8 +27,8 @@ public class DiffBlock implements Serializable {
return operation;
}
- public List<List<CmToken>> getLines() {
- return lines;
+ public List<T> getUnits() {
+ return units;
}
public int getOldStart() {
@@ -45,46 +43,27 @@ public class DiffBlock implements Serializable {
if (operation == Operation.INSERT)
return oldStart;
else
- return oldStart + lines.size();
+ return oldStart + units.size();
}
public int getNewEnd() {
if (operation == Operation.DELETE)
return newStart;
else
- return newStart + lines.size();
+ return newStart + units.size();
}
- public List<DiffLine> asDiffLines() {
- List<DiffLine> diffLines = new ArrayList<>();
- int oldLineNo = oldStart;
- int newLineNo = newStart;
- for (List<CmToken> line: lines) {
- diffLines.add(new DiffLine(operation, line, oldLineNo, newLineNo));
- if (operation == Operation.EQUAL) {
- oldLineNo++;
- newLineNo++;
- } else if (operation == Operation.DELETE) {
- oldLineNo++;
- } else {
- newLineNo++;
- }
- }
- return diffLines;
- }
-
@Override
public String toString() {
StringBuffer buffer = new StringBuffer();
- for (List<CmToken> line: lines) {
+ for (T unit: units) {
if (operation == Operation.INSERT)
buffer.append("+");
else if (operation == Operation.DELETE)
buffer.append("-");
else
buffer.append(" ");
- for (CmToken token: line)
- buffer.append(token);
+ buffer.append(unit);
buffer.append("\n");
}
return buffer.toString();
diff --git a/commons.lang/src/main/java/com/pmease/commons/lang/diff/DiffLine.java b/commons.lang/src/main/java/com/pmease/commons/lang/diff/DiffLine.java
deleted file mode 100644
index 8771308940..0000000000
--- a/commons.lang/src/main/java/com/pmease/commons/lang/diff/DiffLine.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package com.pmease.commons.lang.diff;
-
-import java.io.Serializable;
-import java.util.List;
-
-import com.pmease.commons.lang.diff.DiffMatchPatch.Operation;
-import com.pmease.commons.lang.tokenizers.CmToken;
-
-public class DiffLine implements Serializable {
-
- private static final long serialVersionUID = 1L;
-
- private final DiffMatchPatch.Operation operation;
-
- private final List<CmToken> tokens;
-
- private final int oldLineNo, newLineNo;
-
- public DiffLine(DiffMatchPatch.Operation operation, List<CmToken> tokens,
- int oldLineNo, int newLineNo) {
- this.operation = operation;
- this.tokens = tokens;
- this.oldLineNo = oldLineNo;
- this.newLineNo = newLineNo;
- }
-
- public DiffMatchPatch.Operation getOperation() {
- return operation;
- }
-
- public List<CmToken> getTokens() {
- return tokens;
- }
-
- public int getOldLineNo() {
- return oldLineNo;
- }
-
- public int getNewLineNo() {
- return newLineNo;
- }
-
- @Override
- public String toString() {
- StringBuffer buffer = new StringBuffer();
- if (operation == Operation.INSERT)
- buffer.append("+");
- else if (operation == Operation.DELETE)
- buffer.append("-");
- else
- buffer.append(" ");
- for (CmToken token: tokens)
- buffer.append(token);
- return buffer.toString();
- }
-
-}
diff --git a/commons.lang/src/main/java/com/pmease/commons/lang/diff/DiffUtils.java b/commons.lang/src/main/java/com/pmease/commons/lang/diff/DiffUtils.java
index da107947a8..1d1199b447 100644
--- a/commons.lang/src/main/java/com/pmease/commons/lang/diff/DiffUtils.java
+++ b/commons.lang/src/main/java/com/pmease/commons/lang/diff/DiffUtils.java
@@ -75,14 +75,10 @@ public class DiffUtils {
}
}
- public static List<DiffBlock> diff(List<String> oldLines, List<String> newLines) {
- return diff(oldLines, null, newLines, null);
- }
-
/**
* Diff two list of strings.
*/
- public static List<DiffBlock> diff(List<String> oldLines, @Nullable String oldFileName,
+ public static List<DiffBlock<List<CmToken>>> diff(List<String> oldLines, @Nullable String oldFileName,
List<String> newLines, @Nullable String newFileName) {
Preconditions.checkArgument(oldLines.size() + newLines.size() <= MAX_DIFF_SIZE,
"Total size of old lines and new lines should be less than " + MAX_DIFF_SIZE + ".");
@@ -95,7 +91,7 @@ public class DiffUtils {
List<DiffMatchPatch.Diff> diffs = dmp.diff_main(result1.chars1, result1.chars2, false);
- List<DiffBlock> diffBlocks = new ArrayList<>();
+ List<DiffBlock<List<CmToken>>> diffBlocks = new ArrayList<>();
int oldLineNo = 0;
int newLineNo = 0;
for (Diff diff : diffs) {
@@ -106,32 +102,71 @@ public class DiffUtils {
oldLineNo++;
newLineNo++;
}
- diffBlocks.add(new DiffBlock(diff.operation, lines, oldLineNo-lines.size(), newLineNo-lines.size()));
+ diffBlocks.add(new DiffBlock<List<CmToken>>(diff.operation, lines,
+ oldLineNo-lines.size(), newLineNo-lines.size()));
} else if (diff.operation == Operation.INSERT) {
for (int i = 0; i < diff.text.length(); i++)
lines.add(newTokenizedLines.get(newLineNo++));
- diffBlocks.add(new DiffBlock(diff.operation, lines, oldLineNo, newLineNo-lines.size()));
+ diffBlocks.add(new DiffBlock<List<CmToken>>(diff.operation, lines,
+ oldLineNo, newLineNo-lines.size()));
} else {
for (int i = 0; i < diff.text.length(); i++)
lines.add(oldTokenizedLines.get(oldLineNo++));
- diffBlocks.add(new DiffBlock(diff.operation, lines, oldLineNo-lines.size(), newLineNo));
+ diffBlocks.add(new DiffBlock<List<CmToken>>(diff.operation, lines,
+ oldLineNo-lines.size(), newLineNo));
+ }
+ }
+
+ return diffBlocks;
+ }
+
+ public static <T> List<DiffBlock<T>> diff(List<T> oldLines, List<T> newLines) {
+ Preconditions.checkArgument(oldLines.size() + newLines.size() <= MAX_DIFF_SIZE,
+ "Total size of old lines and new lines should be less than " + MAX_DIFF_SIZE + ".");
+
+ DiffMatchPatch dmp = new DiffMatchPatch();
+ TokensToCharsResult<T> result1 = tokensToChars(oldLines, newLines);
+
+ List<DiffMatchPatch.Diff> diffs = dmp.diff_main(result1.chars1, result1.chars2, false);
+
+ List<DiffBlock<T>> diffBlocks = new ArrayList<>();
+ int oldLineNo = 0;
+ int newLineNo = 0;
+ for (Diff diff : diffs) {
+ List<T> lines = new ArrayList<>();
+ if (diff.operation == Operation.EQUAL) {
+ for (int i = 0; i < diff.text.length(); i++) {
+ lines.add(newLines.get(newLineNo));
+ oldLineNo++;
+ newLineNo++;
+ }
+ diffBlocks.add(new DiffBlock<T>(diff.operation, lines, oldLineNo-lines.size(), newLineNo-lines.size()));
+ } else if (diff.operation == Operation.INSERT) {
+ for (int i = 0; i < diff.text.length(); i++)
+ lines.add(newLines.get(newLineNo++));
+ diffBlocks.add(new DiffBlock<T>(diff.operation, lines, oldLineNo, newLineNo-lines.size()));
+ } else {
+ for (int i = 0; i < diff.text.length(); i++)
+ lines.add(oldLines.get(oldLineNo++));
+ diffBlocks.add(new DiffBlock<T>(diff.operation, lines, oldLineNo-lines.size(), newLineNo));
}
}
return diffBlocks;
}
- public static LinkedHashMap<Integer, LineModification> calcLineChange(DiffBlock deleteBlock, DiffBlock insertBlock) {
- LinkedHashMap<Integer, LineModification> lineModifications = new LinkedHashMap<>();
+ public static LinkedHashMap<Integer, LineDiff> align(
+ DiffBlock<List<CmToken>> deleteBlock, DiffBlock<List<CmToken>> insertBlock) {
+ LinkedHashMap<Integer, LineDiff> lineDiffs = new LinkedHashMap<>();
DiffMatchPatch dmp = new DiffMatchPatch();
long time = System.currentTimeMillis();
int nextInsert = 0;
- for (int i=0; i<deleteBlock.getLines().size(); i++) {
- List<CmToken> deleteLine = deleteBlock.getLines().get(i);
- for (int j=nextInsert; j<insertBlock.getLines().size(); j++) {
- List<CmToken> insertLine = insertBlock.getLines().get(j);
+ for (int i=0; i<deleteBlock.getUnits().size(); i++) {
+ List<CmToken> deleteLine = deleteBlock.getUnits().get(i);
+ for (int j=nextInsert; j<insertBlock.getUnits().size(); j++) {
+ List<CmToken> insertLine = insertBlock.getUnits().get(j);
TokensToCharsResult<CmToken> result = DiffUtils.tokensToChars(deleteLine, insertLine);
List<DiffMatchPatch.Diff> diffs = dmp.diff_main(result.chars1, result.chars2, false);
int equal = 0;
@@ -148,7 +183,7 @@ public class DiffUtils {
}
}
if (equal*3 >= total) {
- List<TokenDiffBlock> diffBlocks = new ArrayList<>();
+ List<DiffBlock<CmToken>> diffBlocks = new ArrayList<>();
int oldLineNo = 0;
int newLineNo = 0;
for (Diff diff : diffs) {
@@ -159,73 +194,42 @@ public class DiffUtils {
oldLineNo++;
newLineNo++;
}
- diffBlocks.add(new TokenDiffBlock(diff.operation, tokens, oldLineNo-tokens.size(), newLineNo-tokens.size()));
+ diffBlocks.add(new DiffBlock<CmToken>(diff.operation, tokens, oldLineNo-tokens.size(), newLineNo-tokens.size()));
} else if (diff.operation == Operation.INSERT) {
for (int k = 0; k < diff.text.length(); k++)
tokens.add(insertLine.get(newLineNo++));
- diffBlocks.add(new TokenDiffBlock(diff.operation, tokens, oldLineNo, newLineNo-tokens.size()));
+ diffBlocks.add(new DiffBlock<CmToken>(diff.operation, tokens, oldLineNo, newLineNo-tokens.size()));
} else {
for (int k = 0; k < diff.text.length(); k++)
tokens.add(deleteLine.get(oldLineNo++));
- diffBlocks.add(new TokenDiffBlock(diff.operation, tokens, oldLineNo-tokens.size(), newLineNo));
+ diffBlocks.add(new DiffBlock<CmToken>(diff.operation, tokens, oldLineNo-tokens.size(), newLineNo));
}
}
- LineModification lineModification = new LineModification(j, diffBlocks);
- lineModifications.put(i, lineModification);
+ LineDiff lineDiff = new LineDiff(j, diffBlocks);
+ lineDiffs.put(i, lineDiff);
nextInsert = j+1;
break;
} else {
if (System.currentTimeMillis()-time > CHANGE_CALC_TIMEOUT) {
- nextInsert = insertBlock.getLines().size();
+ nextInsert = insertBlock.getUnits().size();
break;
}
}
}
}
- return lineModifications;
+ return lineDiffs;
}
- public static AroundContext around(List<DiffBlock> diffBlocks, int oldLine, int newLine, int contextSize) {
- List<DiffLine> diffLines = new ArrayList<>();
- for (DiffBlock diffBlock: diffBlocks)
- diffLines.addAll(diffBlock.asDiffLines());
-
- List<DiffLine> contextDiffs = new ArrayList<>();
- int index = -1;
- for (int i=0; i<diffLines.size(); i++) {
- DiffLine diffLine = diffLines.get(i);
- if (oldLine != -1 && diffLine.getOperation() != Operation.INSERT && diffLine.getOldLineNo() == oldLine
- || newLine != -1 && diffLine.getOperation() != Operation.DELETE && diffLine.getNewLineNo() == newLine) {
- index = i;
- break;
- }
- }
-
- Preconditions.checkState(index != -1);
-
- int start = index - contextSize;
- if (start < 0)
- start = 0;
- int end = index + contextSize;
- if (end > diffLines.size() - 1)
- end = diffLines.size() - 1;
-
- for (int i=start; i<=end; i++)
- contextDiffs.add(diffLines.get(i));
-
- return new AroundContext(contextDiffs, index-start, start>0, end<diffLines.size()-1);
- }
-
- public static Map<Integer, Integer> mapLines(List<String> oldLines, List<String> newLines) {
+ public static <T> Map<Integer, Integer> mapLines(List<T> oldLines, List<T> newLines) {
return mapLines(diff(oldLines, newLines));
}
- public static Map<Integer, Integer> mapLines(List<DiffBlock> diffBlocks) {
+ public static <T> Map<Integer, Integer> mapLines(List<DiffBlock<T>> diffBlocks) {
Map<Integer, Integer> lineMapping = new HashMap<Integer, Integer>();
- for (DiffBlock diffBlock: diffBlocks) {
+ for (DiffBlock<T> diffBlock: diffBlocks) {
if (diffBlock.getOperation() == Operation.EQUAL) {
- for (int i=0; i<diffBlock.getLines().size(); i++)
+ for (int i=0; i<diffBlock.getUnits().size(); i++)
lineMapping.put(i+diffBlock.getOldStart(), i+diffBlock.getNewStart());
}
}
diff --git a/commons.lang/src/main/java/com/pmease/commons/lang/diff/LineModification.java b/commons.lang/src/main/java/com/pmease/commons/lang/diff/LineDiff.java
similarity index 55%
rename from commons.lang/src/main/java/com/pmease/commons/lang/diff/LineModification.java
rename to commons.lang/src/main/java/com/pmease/commons/lang/diff/LineDiff.java
index b6d11750a0..e55b8e24fc 100644
--- a/commons.lang/src/main/java/com/pmease/commons/lang/diff/LineModification.java
+++ b/commons.lang/src/main/java/com/pmease/commons/lang/diff/LineDiff.java
@@ -3,15 +3,17 @@ package com.pmease.commons.lang.diff;
import java.io.Serializable;
import java.util.List;
-public class LineModification implements Serializable {
+import com.pmease.commons.lang.tokenizers.CmToken;
+
+public class LineDiff implements Serializable {
private static final long serialVersionUID = 1L;
private final int compareLine;
- private final List<TokenDiffBlock> tokenDiffs;
+ private final List<DiffBlock<CmToken>> tokenDiffs;
- public LineModification(int line, List<TokenDiffBlock> diffs) {
+ public LineDiff(int line, List<DiffBlock<CmToken>> diffs) {
this.compareLine = line;
this.tokenDiffs = diffs;
}
@@ -20,7 +22,7 @@ public class LineModification implements Serializable {
return compareLine;
}
- public List<TokenDiffBlock> getTokenDiffs() {
+ public List<DiffBlock<CmToken>> getTokenDiffs() {
return tokenDiffs;
}
diff --git a/commons.lang/src/main/java/com/pmease/commons/lang/diff/TokenDiffBlock.java b/commons.lang/src/main/java/com/pmease/commons/lang/diff/TokenDiffBlock.java
deleted file mode 100644
index 211d1da44b..0000000000
--- a/commons.lang/src/main/java/com/pmease/commons/lang/diff/TokenDiffBlock.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package com.pmease.commons.lang.diff;
-
-import java.io.Serializable;
-import java.util.List;
-
-import com.pmease.commons.lang.diff.DiffMatchPatch.Operation;
-import com.pmease.commons.lang.tokenizers.CmToken;
-
-public class TokenDiffBlock implements Serializable {
-
- private static final long serialVersionUID = 1L;
-
- private final DiffMatchPatch.Operation operation;
-
- private final List<CmToken> tokens;
-
- private final int oldStart, newStart;
-
- public TokenDiffBlock(DiffMatchPatch.Operation operation, List<CmToken> tokens,
- int oldStart, int newStart) {
- this.operation = operation;
- this.tokens = tokens;
- this.oldStart = oldStart;
- this.newStart = newStart;
- }
-
- public DiffMatchPatch.Operation getOperation() {
- return operation;
- }
-
- public List<CmToken> getTokens() {
- return tokens;
- }
-
- public int getOldStart() {
- return oldStart;
- }
-
- public int getNewStart() {
- return newStart;
- }
-
- public int getOldEnd() {
- if (operation == Operation.INSERT)
- return oldStart;
- else
- return oldStart + tokens.size();
- }
-
- public int getNewEnd() {
- if (operation == Operation.DELETE)
- return newStart;
- else
- return newStart + tokens.size();
- }
-
-}
diff --git a/commons.lang/src/test/java/com/pmease/commons/lang/diff/DiffUtilsTest.java b/commons.lang/src/test/java/com/pmease/commons/lang/diff/DiffUtilsTest.java
index 9edca9ac47..3e3e620e7a 100644
--- a/commons.lang/src/test/java/com/pmease/commons/lang/diff/DiffUtilsTest.java
+++ b/commons.lang/src/test/java/com/pmease/commons/lang/diff/DiffUtilsTest.java
@@ -33,7 +33,7 @@ public class DiffUtilsTest extends AppLoaderMocker {
" System.out.println(\"hello tim\");",
" }",
"}");
- List<DiffBlock> diffBlocks = DiffUtils.diff(oldLines, "test.java", newLines, "test.java");
+ List<DiffBlock<List<CmToken>>> diffBlocks = DiffUtils.diff(oldLines, "test.java", newLines, "test.java");
assertEquals(""
+ "-public class HelloRobin {\n", diffBlocks.get(0).toString());
assertEquals(""
@@ -62,35 +62,6 @@ public class DiffUtilsTest extends AppLoaderMocker {
assertEquals(4, diffBlocks.get(5).getNewStart());
}
- @Test
- public void testAround() {
- List<String> oldLines = Lists.newArrayList(
- "public class HelloRobin {",
- " public static void main(String[] args) {",
- " System.out.println(\"hello robin\");",
- " }",
- "}");
- List<String> newLines = Lists.newArrayList(
- "package test;",
- "public class HelloTim {",
- " public static void main(String[] args) {",
- " System.out.println(\"hello tim\");",
- " }",
- "}");
- List<DiffBlock> diffBlocks = DiffUtils.diff(oldLines, "test.java", newLines, "test.java");
- AroundContext aroundContext = DiffUtils.around(diffBlocks, 2, -1, 2);
- assertEquals("+public class HelloTim {",
- aroundContext.getDiffLines().get(0).toString());
- assertEquals(" public static void main(String[] args) {",
- aroundContext.getDiffLines().get(1).toString());
- assertEquals("- System.out.println(\"hello robin\");",
- aroundContext.getDiffLines().get(2).toString());
- assertEquals("+ System.out.println(\"hello tim\");",
- aroundContext.getDiffLines().get(3).toString());
- assertEquals(" }",
- aroundContext.getDiffLines().get(4).toString());
- }
-
@Test
public void testMapLines() {
List<String> oldLines = Lists.newArrayList(
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/InlineComment.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/InlineComment.java
index 8ec237d7bc..e6705f0cd3 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/InlineComment.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/InlineComment.java
@@ -1,15 +1,11 @@
package com.pmease.gitplex.core.comment;
import com.pmease.commons.git.BlobIdent;
-import com.pmease.commons.lang.diff.AroundContext;
public interface InlineComment extends Comment {
- public static final int CONTEXT_SIZE = 3;
-
BlobIdent getBlobIdent();
int getLine();
- AroundContext getContext();
-}
+}
\ No newline at end of file
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/InlineCommentSupport.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/InlineCommentSupport.java
index c1ae7067d2..0a24ce504d 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/InlineCommentSupport.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/InlineCommentSupport.java
@@ -5,14 +5,13 @@ import java.util.List;
import java.util.Map;
import com.pmease.commons.git.BlobIdent;
-import com.pmease.commons.lang.diff.AroundContext;
public interface InlineCommentSupport extends Serializable {
Map<Integer, List<InlineComment>> getComments(BlobIdent blobIdent);
InlineComment addComment(BlobIdent commentAt, BlobIdent compareWith,
- AroundContext commentContext, int line, String content);
+ int line, String content);
InlineComment getConcernedComment();
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestCommentManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestCommentManager.java
index 0c8accbce1..0c99e54df8 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestCommentManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestCommentManager.java
@@ -14,11 +14,9 @@ import com.pmease.commons.git.BlobIdent;
import com.pmease.commons.git.Change;
import com.pmease.commons.hibernate.Transactional;
import com.pmease.commons.hibernate.dao.Dao;
-import com.pmease.commons.lang.diff.AroundContext;
import com.pmease.commons.lang.diff.DiffBlock;
import com.pmease.commons.lang.diff.DiffUtils;
import com.pmease.commons.markdown.MarkdownManager;
-import com.pmease.gitplex.core.comment.InlineComment;
import com.pmease.gitplex.core.comment.MentionParser;
import com.pmease.gitplex.core.listeners.PullRequestListener;
import com.pmease.gitplex.core.manager.PullRequestCommentManager;
@@ -71,25 +69,6 @@ public class DefaultPullRequestCommentManager implements PullRequestCommentManag
if (newBlobIdent != null) {
Blob.Text oldText = comment.getRepository().getBlob(comment.getBlobIdent()).getText();
Preconditions.checkNotNull(oldText);
- List<String> newLines;
- if (newBlobIdent.path != null) {
- Blob.Text newText = comment.getRepository().getBlob(newBlobIdent).getText();
- if (newText != null)
- newLines = newText.getLines();
- else
- newLines = null;
- } else {
- newLines = new ArrayList<>();
- }
- if (newLines != null) {
- List<DiffBlock> diffs = DiffUtils.diff(oldText.getLines(),
- comment.getBlobIdent().getFileName(), newLines, newBlobIdent.getFileName());
- AroundContext context = DiffUtils.around(
- diffs, comment.getLine(), -1, InlineComment.CONTEXT_SIZE);
- comment.setContext(context);
- } else {
- comment.setContext(null);
- }
comment.setCompareWith(newBlobIdent);
} else {
comment.getCompareWith().revision = latestCommitHash;
@@ -116,43 +95,16 @@ public class DefaultPullRequestCommentManager implements PullRequestCommentManag
newLines = new ArrayList<>();
}
if (newLines != null) {
- List<DiffBlock> diffs = DiffUtils.diff(oldText.getLines(), comment.getBlobIdent().getFileName(),
- newLines, newBlobIdent.getFileName());
+ List<DiffBlock<String>> diffs = DiffUtils.diff(oldText.getLines(), newLines);
Integer newLineNo = DiffUtils.mapLines(diffs).get(comment.getLine());
if (newLineNo != null) {
comment.setBlobIdent(newBlobIdent);
comment.setLine(newLineNo);
-
- List<String> oldLines;
- if (comment.getCompareWith().path != null) {
- oldText = comment.getRepository().getBlob(comment.getCompareWith()).getText();
- if (oldText != null)
- oldLines = oldText.getLines();
- else
- oldLines = null;
- } else {
- oldLines = new ArrayList<>();
- }
- if (oldLines != null) {
- diffs = DiffUtils.diff(oldLines,
- comment.getCompareWith().getFileName(),
- newLines, newBlobIdent.getFileName());
- AroundContext context = DiffUtils.around(
- diffs, -1, newLineNo, InlineComment.CONTEXT_SIZE);
- comment.setContext(context);
- } else {
- comment.setContext(null);
- }
} else {
comment.setCompareWith(newBlobIdent);
-
- AroundContext context = DiffUtils.around(
- diffs, comment.getLine(), -1, InlineComment.CONTEXT_SIZE);
- comment.setContext(context);
}
} else {
comment.setCompareWith(newBlobIdent);
- comment.setContext(null);
}
} else {
comment.getBlobIdent().revision = latestCommitHash;
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/InlineInfo.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/InlineInfo.java
index dbf20cd2d5..0bc4963398 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/InlineInfo.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/InlineInfo.java
@@ -7,10 +7,8 @@ import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.Embedded;
-import javax.persistence.Lob;
import com.pmease.commons.git.BlobIdent;
-import com.pmease.commons.lang.diff.AroundContext;
@Embeddable
public class InlineInfo implements Serializable {
@@ -39,10 +37,6 @@ public class InlineInfo implements Serializable {
// embedded as nullable property of JPA entities
private Integer line;
- @Lob
- @Column(length=65535)
- private AroundContext context;
-
public BlobIdent getBlobIdent() {
return blobIdent;
}
@@ -67,12 +61,4 @@ public class InlineInfo implements Serializable {
this.line = line;
}
- public AroundContext getContext() {
- return context;
- }
-
- public void setContext(AroundContext context) {
- this.context = context;
- }
-
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestComment.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestComment.java
index dbc2205c24..33c30e4dd7 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestComment.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestComment.java
@@ -23,7 +23,6 @@ import com.google.common.base.Preconditions;
import com.pmease.commons.git.BlobIdent;
import com.pmease.commons.hibernate.AbstractEntity;
import com.pmease.commons.hibernate.dao.Dao;
-import com.pmease.commons.lang.diff.AroundContext;
import com.pmease.commons.util.Pair;
import com.pmease.gitplex.core.GitPlex;
import com.pmease.gitplex.core.comment.CommentReply;
@@ -191,17 +190,6 @@ public class PullRequestComment extends AbstractEntity implements InlineComment
inlineInfo.setLine(line);
}
- @Override
- public AroundContext getContext() {
- return Preconditions.checkNotNull(inlineInfo).getContext();
- }
-
- public void setContext(AroundContext context) {
- if (inlineInfo == null)
- inlineInfo = new InlineInfo();
- inlineInfo.setContext(context);
- }
-
@Override
public Date getLastVisitDate() {
return GitPlex.getInstance(PullRequestManager.class).getLastVisitDate(getRequest());
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CommentPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CommentPanel.html
index 6464a7b7a8..aee6d5782a 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CommentPanel.html
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CommentPanel.html
@@ -1,7 +1,7 @@
<wicket:panel>
<div class="comment">
<div wicket:id="head" class="head activity-summary">
- <span wicket:id="user" class="user"></span> commented <span wicket:id="age"></span>
+ <span wicket:id="user" class="user"></span> <span wicket:id="action"></span> <span wicket:id="age"></span>
<span class="operations">
<a wicket:id="edit" title="Edit comment"><span class="fa fa-pencil"></span></a>
<a wicket:id="delete" title="Delete comment"><span class="fa fa-times"></span></a>
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CommentPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CommentPanel.java
index 32a4468e54..af0b55add9 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CommentPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CommentPanel.java
@@ -101,6 +101,7 @@ public class CommentPanel extends Panel {
add(head);
head.add(new UserLink("user", new UserModel(getComment().getUser()), AvatarMode.NAME));
+ head.add(newActionComponent("action"));
head.add(new Label("age", DateUtils.formatAge(getComment().getDate())));
head.add(new AjaxLink<Void>("edit") {
@@ -437,6 +438,10 @@ public class CommentPanel extends Panel {
protected Component newAdditionalReplyOperations(String id, CommentReply reply) {
return new WebMarkupContainer(id);
}
+
+ protected Component newActionComponent(String id) {
+ return new Label(id, "commented");
+ }
@Override
protected void onDetach() {
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.java
index 299ef0deb9..3e207bdff1 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.java
@@ -40,12 +40,10 @@ import org.apache.wicket.util.time.Duration;
import com.pmease.commons.git.BlobChange;
import com.pmease.commons.git.BlobIdent;
-import com.pmease.commons.lang.diff.AroundContext;
import com.pmease.commons.lang.diff.DiffBlock;
import com.pmease.commons.lang.diff.DiffMatchPatch.Operation;
import com.pmease.commons.lang.diff.DiffUtils;
-import com.pmease.commons.lang.diff.LineModification;
-import com.pmease.commons.lang.diff.TokenDiffBlock;
+import com.pmease.commons.lang.diff.LineDiff;
import com.pmease.commons.lang.tokenizers.CmToken;
import com.pmease.commons.util.StringUtils;
import com.pmease.commons.wicket.behavior.DirtyIgnoreBehavior;
@@ -231,7 +229,6 @@ public class TextDiffPanel extends Panel {
BlobIdent commentAt;
BlobIdent compareWith;
int lineNo;
- AroundContext commentContext;
if (newLineNo == -1) {
commentAt = change.getOldBlobIdent();
@@ -242,11 +239,8 @@ public class TextDiffPanel extends Panel {
compareWith = change.getOldBlobIdent();
lineNo = newLineNo;
}
- commentContext = DiffUtils.around(change.getDiffBlocks(), oldLineNo, newLineNo,
- InlineComment.CONTEXT_SIZE);
- commentSupport.addComment(commentAt, compareWith, commentContext,
- lineNo, input.getModelObject());
+ commentSupport.addComment(commentAt, compareWith, lineNo, input.getModelObject());
CommentAndPos lastComment = listOfCommentAndPosModel.getObject().get(listOfCommentAndPosModel.getObject().size()-1);
Component commentRow = newCommentRow(commentRows.newChildId(), lastComment);
@@ -300,17 +294,17 @@ public class TextDiffPanel extends Panel {
}
private void appendEquals(StringBuilder builder, int index, int lastContextSize, int contextSize) {
- DiffBlock block = change.getDiffBlocks().get(index);
+ DiffBlock<List<CmToken>> block = change.getDiffBlocks().get(index);
if (index == 0) {
- int start = block.getLines().size()-contextSize;
+ int start = block.getUnits().size()-contextSize;
if (start < 0)
start=0;
else if (start > 0)
appendExpander(builder, index, start);
- for (int j=start; j<block.getLines().size()-lastContextSize; j++)
+ for (int j=start; j<block.getUnits().size()-lastContextSize; j++)
appendEqual(builder, block, j, lastContextSize);
} else if (index == change.getDiffBlocks().size()-1) {
- int end = block.getLines().size();
+ int end = block.getUnits().size();
int skipped = 0;
if (end > contextSize) {
skipped = end-contextSize;
@@ -320,14 +314,14 @@ public class TextDiffPanel extends Panel {
appendEqual(builder, block, j, lastContextSize);
if (skipped != 0)
appendExpander(builder, index, skipped);
- } else if (2*contextSize < block.getLines().size()) {
+ } else if (2*contextSize < block.getUnits().size()) {
for (int j=lastContextSize; j<contextSize; j++)
appendEqual(builder, block, j, lastContextSize);
- appendExpander(builder, index, block.getLines().size() - 2*contextSize);
- for (int j=block.getLines().size()-contextSize; j<block.getLines().size()-lastContextSize; j++)
+ appendExpander(builder, index, block.getUnits().size() - 2*contextSize);
+ for (int j=block.getUnits().size()-contextSize; j<block.getUnits().size()-lastContextSize; j++)
appendEqual(builder, block, j, lastContextSize);
} else {
- for (int j=lastContextSize; j<block.getLines().size()-lastContextSize; j++)
+ for (int j=lastContextSize; j<block.getUnits().size()-lastContextSize; j++)
appendEqual(builder, block, j, lastContextSize);
}
}
@@ -354,19 +348,19 @@ public class TextDiffPanel extends Panel {
builder.append("</col><col></col><col width=40></col>");
builder.append("<col></col></colgroup>");
for (int i=0; i<change.getDiffBlocks().size(); i++) {
- DiffBlock block = change.getDiffBlocks().get(i);
+ DiffBlock<List<CmToken>> block = change.getDiffBlocks().get(i);
if (block.getOperation() == Operation.EQUAL) {
appendEquals(builder, i, 0, contextSize);
} else if (block.getOperation() == Operation.DELETE) {
if (i+1<change.getDiffBlocks().size()) {
- DiffBlock nextBlock = change.getDiffBlocks().get(i+1);
+ DiffBlock<List<CmToken>> nextBlock = change.getDiffBlocks().get(i+1);
if (nextBlock.getOperation() == Operation.INSERT) {
- LinkedHashMap<Integer, LineModification> lineChanges = DiffUtils.calcLineChange(block, nextBlock);
+ LinkedHashMap<Integer, LineDiff> lineChanges = DiffUtils.align(block, nextBlock);
int prevDeleteLineIndex = 0;
int prevInsertLineIndex = 0;
- for (Map.Entry<Integer, LineModification> entry: lineChanges.entrySet()) {
+ for (Map.Entry<Integer, LineDiff> entry: lineChanges.entrySet()) {
int deleteLineIndex = entry.getKey();
- LineModification lineChange = entry.getValue();
+ LineDiff lineChange = entry.getValue();
int insertLineIndex = lineChange.getCompareLine();
appendDeletesAndInserts(builder, block, nextBlock, prevDeleteLineIndex, deleteLineIndex,
@@ -377,27 +371,28 @@ public class TextDiffPanel extends Panel {
prevDeleteLineIndex = deleteLineIndex+1;
prevInsertLineIndex = insertLineIndex+1;
}
- appendDeletesAndInserts(builder, block, nextBlock, prevDeleteLineIndex, block.getLines().size(),
- prevInsertLineIndex, nextBlock.getLines().size());
+ appendDeletesAndInserts(builder, block, nextBlock, prevDeleteLineIndex, block.getUnits().size(),
+ prevInsertLineIndex, nextBlock.getUnits().size());
i++;
} else {
- for (int j=0; j<block.getLines().size(); j++)
+ for (int j=0; j<block.getUnits().size(); j++)
appendDelete(builder, block, j);
}
} else {
- for (int j=0; j<block.getLines().size(); j++)
+ for (int j=0; j<block.getUnits().size(); j++)
appendDelete(builder, block, j);
}
} else {
- for (int j=0; j<block.getLines().size(); j++)
+ for (int j=0; j<block.getUnits().size(); j++)
appendInsert(builder, block, j);
}
}
return builder.toString();
}
- private void appendDeletesAndInserts(StringBuilder builder, DiffBlock deleteBlock, DiffBlock insertBlock,
- int fromDeleteLineIndex, int toDeleteLineIndex, int fromInsertLineIndex, int toInsertLineIndex) {
+ private void appendDeletesAndInserts(StringBuilder builder, DiffBlock<List<CmToken>> deleteBlock,
+ DiffBlock<List<CmToken>> insertBlock, int fromDeleteLineIndex, int toDeleteLineIndex,
+ int fromInsertLineIndex, int toInsertLineIndex) {
if (diffMode == DiffMode.UNIFIED) {
for (int i=fromDeleteLineIndex; i<toDeleteLineIndex; i++)
appendDelete(builder, deleteBlock, i);
@@ -429,7 +424,7 @@ public class TextDiffPanel extends Panel {
}
}
- private void appendEqual(StringBuilder builder, DiffBlock block, int lineIndex, int lastContextSize) {
+ private void appendEqual(StringBuilder builder, DiffBlock<List<CmToken>> block, int lineIndex, int lastContextSize) {
if (lastContextSize != 0)
builder.append("<tr class='code expanded'>");
else
@@ -442,7 +437,7 @@ public class TextDiffPanel extends Panel {
if (lastContextSize == 0)
appendAddComment(contentBuilder, oldLineNo, newLineNo);
contentBuilder.append("<span class='operation'>&nbsp;</span>");
- for (CmToken token: block.getLines().get(lineIndex))
+ for (CmToken token: block.getUnits().get(lineIndex))
contentBuilder.append(token.toHtml(Operation.EQUAL));
contentBuilder.append("</td>");
@@ -459,7 +454,7 @@ public class TextDiffPanel extends Panel {
builder.append("</tr>");
}
- private void appendInsert(StringBuilder builder, DiffBlock block, int lineIndex) {
+ private void appendInsert(StringBuilder builder, DiffBlock<List<CmToken>> block, int lineIndex) {
builder.append("<tr class='code intrinsic'>");
int newLineNo = block.getNewStart() + lineIndex;
@@ -467,7 +462,7 @@ public class TextDiffPanel extends Panel {
contentBuilder.append("<td class='content new new").append(newLineNo).append("'>");
appendAddComment(contentBuilder, -1, newLineNo);
contentBuilder.append("<span class='operation'>+</span>");
- List<CmToken> tokens = block.getLines().get(lineIndex);
+ List<CmToken> tokens = block.getUnits().get(lineIndex);
for (int i=0; i<tokens.size(); i++)
contentBuilder.append(tokens.get(i).toHtml(Operation.EQUAL));
contentBuilder.append("</td>");
@@ -484,7 +479,7 @@ public class TextDiffPanel extends Panel {
builder.append("</tr>");
}
- private void appendDelete(StringBuilder builder, DiffBlock block, int lineIndex) {
+ private void appendDelete(StringBuilder builder, DiffBlock<List<CmToken>> block, int lineIndex) {
builder.append("<tr class='code intrinsic'>");
int oldLineNo = block.getOldStart() + lineIndex;
@@ -492,7 +487,7 @@ public class TextDiffPanel extends Panel {
contentBuilder.append("<td class='content old old").append(oldLineNo).append("'>");
appendAddComment(contentBuilder, oldLineNo, -1);
contentBuilder.append("<span class='operation'>-</span>");
- List<CmToken> tokens = block.getLines().get(lineIndex);
+ List<CmToken> tokens = block.getUnits().get(lineIndex);
for (int i=0; i<tokens.size(); i++)
contentBuilder.append(tokens.get(i).toHtml(Operation.EQUAL));
contentBuilder.append("</td>");
@@ -509,8 +504,8 @@ public class TextDiffPanel extends Panel {
builder.append("</tr>");
}
- private void appendSideBySide(StringBuilder builder, DiffBlock deleteBlock, DiffBlock insertBlock,
- int deleteLineIndex, int insertLineIndex) {
+ private void appendSideBySide(StringBuilder builder, DiffBlock<List<CmToken>> deleteBlock,
+ DiffBlock<List<CmToken>> insertBlock, int deleteLineIndex, int insertLineIndex) {
builder.append("<tr class='code intrinsic'>");
int oldLineNo = deleteBlock.getOldStart()+deleteLineIndex;
@@ -518,7 +513,7 @@ public class TextDiffPanel extends Panel {
builder.append("<td class='content old old").append(oldLineNo).append("'>");
appendAddComment(builder, oldLineNo, -1);
builder.append("<span class='operation'>-</span>");
- for (CmToken token: deleteBlock.getLines().get(deleteLineIndex))
+ for (CmToken token: deleteBlock.getUnits().get(deleteLineIndex))
builder.append(token.toHtml(Operation.EQUAL));
builder.append("</td>");
@@ -527,15 +522,16 @@ public class TextDiffPanel extends Panel {
builder.append("<td class='content new new").append(newLineNo).append("'>");
appendAddComment(builder, -1, newLineNo);
builder.append("<span class='operation'>+</span>");
- for (CmToken token: insertBlock.getLines().get(insertLineIndex))
+ for (CmToken token: insertBlock.getUnits().get(insertLineIndex))
builder.append(token.toHtml(Operation.EQUAL));
builder.append("</td>");
builder.append("</tr>");
}
- private void appendModification(StringBuilder builder, DiffBlock deleteBlock, DiffBlock insertBlock,
- int deleteLineIndex, int insertLineIndex, List<TokenDiffBlock> tokenDiffs) {
+ private void appendModification(StringBuilder builder, DiffBlock<List<CmToken>> deleteBlock,
+ DiffBlock<List<CmToken>> insertBlock, int deleteLineIndex, int insertLineIndex,
+ List<DiffBlock<CmToken>> tokenDiffs) {
builder.append("<tr class='code intrinsic'>");
int oldLineNo = deleteBlock.getOldStart() + deleteLineIndex;
@@ -546,8 +542,8 @@ public class TextDiffPanel extends Panel {
builder.append("<td class='content old new old").append(oldLineNo).append(" new").append(newLineNo).append("'>");
appendAddComment(builder, oldLineNo, newLineNo);
builder.append("<span class='operation'>*</span>");
- for (TokenDiffBlock tokenBlock: tokenDiffs) {
- for (CmToken token: tokenBlock.getTokens())
+ for (DiffBlock<CmToken> tokenBlock: tokenDiffs) {
+ for (CmToken token: tokenBlock.getUnits())
builder.append(token.toHtml(tokenBlock.getOperation()));
}
builder.append("</td>");
@@ -556,8 +552,8 @@ public class TextDiffPanel extends Panel {
builder.append("<td class='content old old").append(oldLineNo).append("'>");
appendAddComment(builder, oldLineNo, -1);
builder.append("<span class='operation'>-</span>");
- for (TokenDiffBlock tokenBlock: tokenDiffs) {
- for (CmToken token: tokenBlock.getTokens()) {
+ for (DiffBlock<CmToken> tokenBlock: tokenDiffs) {
+ for (CmToken token: tokenBlock.getUnits()) {
if (tokenBlock.getOperation() != Operation.INSERT)
builder.append(token.toHtml(tokenBlock.getOperation()));
}
@@ -568,8 +564,8 @@ public class TextDiffPanel extends Panel {
builder.append("<td class='content new new").append(newLineNo).append("'>");
appendAddComment(builder, -1, newLineNo);
builder.append("<span class='operation'>+</span>");
- for (TokenDiffBlock tokenBlock: tokenDiffs) {
- for (CmToken token: tokenBlock.getTokens()) {
+ for (DiffBlock<CmToken> tokenBlock: tokenDiffs) {
+ for (CmToken token: tokenBlock.getUnits()) {
if (tokenBlock.getOperation() != Operation.DELETE)
builder.append(token.toHtml(tokenBlock.getOperation()));
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/requestdetail/compare/RequestComparePage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/requestdetail/compare/RequestComparePage.java
index 14e3e63a53..982c4d6ce9 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/requestdetail/compare/RequestComparePage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/requestdetail/compare/RequestComparePage.java
@@ -35,7 +35,6 @@ import com.pmease.commons.git.Commit;
import com.pmease.commons.git.GitUtils;
import com.pmease.commons.hibernate.HibernateUtils;
import com.pmease.commons.hibernate.dao.Dao;
-import com.pmease.commons.lang.diff.AroundContext;
import com.pmease.commons.loader.InheritableThreadLocalData;
import com.pmease.commons.wicket.ajaxlistener.IndicateLoadingListener;
import com.pmease.commons.wicket.behavior.StickyBehavior;
@@ -630,7 +629,7 @@ public class RequestComparePage extends RequestDetailPage {
@Override
public InlineComment addComment(BlobIdent blobInfo, BlobIdent compareWith,
- AroundContext commentContext, int line, String content) {
+ int line, String content) {
User user = GitPlex.getInstance(UserManager.class).getCurrent();
Preconditions.checkNotNull(user);
PullRequestComment comment = new PullRequestComment();
@@ -642,7 +641,6 @@ public class RequestComparePage extends RequestDetailPage {
comment.setBlobIdent(blobInfo);
comment.setCompareWith(compareWith);
comment.setLine(line);
- comment.setContext(commentContext);
InheritableThreadLocalData.set(new WebSocketRenderBehavior.PageId(getPageId()));
try {
GitPlex.getInstance(PullRequestCommentManager.class).save(comment, true);
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/requestdetail/overview/CommentActivityPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/requestdetail/overview/CommentActivityPanel.html
index 33505f7732..d6f110d331 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/requestdetail/overview/CommentActivityPanel.html
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/requestdetail/overview/CommentActivityPanel.html
@@ -1,3 +1,3 @@
<wicket:panel>
- <div wicket:id="content" class="comment"></div>
+ <div wicket:id="content" class="request-comment"></div>
</wicket:panel>
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/requestdetail/overview/InlineCommentActivityPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/requestdetail/overview/InlineCommentActivityPanel.html
index b97cdf0e6f..2cedd99d15 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/requestdetail/overview/InlineCommentActivityPanel.html
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/requestdetail/overview/InlineCommentActivityPanel.html
@@ -1,36 +1,6 @@
<wicket:panel>
- <div class="inline-comment activity-summary">
- <span wicket:id="name" class="user"></span>
- added inline comment
- <span wicket:id="age"></span>
- </div>
- <div class="inline-comment panel panel-default">
- <div class="panel-heading">
- <span wicket:id="file"></span>
- <span class="operations">
- <a wicket:id="compareView" class="fa fa-file-text" title="View full context"></a>
- </span>
- </div>
- <table wicket:id="context" class="table-diff">
- <tr wicket:id="aboveOmitted" class="omit">
- <td colspan="3"><i class="fa fa-ellipsis-h"></i></td>
- </tr>
- <tr wicket:id="lines" class="line diff">
- <td class="old line-no">
- <span wicket:id="oldLineNo"></span>
- </td>
- <td class="new line-no">
- <span wicket:id="newLineNo"></span>
- </td>
- <td class="text"><wicket:container wicket:id="diffMark"></wicket:container><wicket:container wicket:id="tokens"><span wicket:id="token"></span></wicket:container></td>
- </tr>
- <tr wicket:id="belowOmitted" class="omit">
- <td colspan="3"><i class="fa fa-ellipsis-h"></i></td>
- </tr>
- </table>
- <div wicket:id="noContext" class="panel-body">
- <div class="alert alert-warning before-comment">Line context is not available as file is binary.</div>
- </div>
- <div wicket:id="comment"></div>
- </div>
+ <div wicket:id="content" class="inline-comment"></div>
+ <wicket:fragment wicket:id="actionFrag">
+ added inline comment on file <a wicket:id="fileLink" class="file"></a>
+ </wicket:fragment>
</wicket:panel>
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/requestdetail/overview/InlineCommentActivityPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/requestdetail/overview/InlineCommentActivityPanel.java
index 7748577f7e..9bd81ebb74 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/requestdetail/overview/InlineCommentActivityPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/requestdetail/overview/InlineCommentActivityPanel.java
@@ -1,34 +1,16 @@
package com.pmease.gitplex.web.page.repository.pullrequest.requestdetail.overview;
-import java.util.List;
-
-import org.apache.wicket.ajax.AjaxRequestTarget;
-import org.apache.wicket.behavior.AttributeAppender;
-import org.apache.wicket.event.IEvent;
-import org.apache.wicket.markup.head.IHeaderResponse;
-import org.apache.wicket.markup.head.OnDomReadyHeaderItem;
-import org.apache.wicket.markup.html.WebMarkupContainer;
-import org.apache.wicket.markup.html.basic.Label;
-import org.apache.wicket.markup.html.link.Link;
-import org.apache.wicket.markup.html.list.ListItem;
-import org.apache.wicket.markup.html.list.ListView;
+import org.apache.wicket.Component;
+import org.apache.wicket.markup.html.link.BookmarkablePageLink;
+import org.apache.wicket.markup.html.panel.Fragment;
import org.apache.wicket.markup.html.panel.Panel;
-import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.Model;
+import org.apache.wicket.request.mapper.parameter.PageParameters;
-import com.pmease.commons.lang.diff.DiffLine;
-import com.pmease.commons.lang.diff.DiffMatchPatch.Operation;
-import com.pmease.commons.lang.tokenizers.CmToken;
-import com.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.core.manager.PullRequestCommentManager;
import com.pmease.gitplex.core.model.PullRequestComment;
-import com.pmease.gitplex.web.component.avatar.AvatarMode;
import com.pmease.gitplex.web.component.comment.CommentPanel;
-import com.pmease.gitplex.web.component.userlink.UserLink;
-import com.pmease.gitplex.web.model.UserModel;
-import com.pmease.gitplex.web.page.repository.pullrequest.PullRequestChanged;
import com.pmease.gitplex.web.page.repository.pullrequest.requestdetail.compare.RequestComparePage;
-import com.pmease.gitplex.web.utils.DateUtils;
@SuppressWarnings("serial")
class InlineCommentActivityPanel extends Panel {
@@ -45,189 +27,25 @@ class InlineCommentActivityPanel extends Panel {
protected void onInitialize() {
super.onInitialize();
- PullRequestComment comment = commentModel.getObject();
- GitPlex.getInstance(PullRequestCommentManager.class).updateInline(comment);
- add(new UserLink("name", new UserModel(comment.getUser()), AvatarMode.NAME));
- add(new Label("age", DateUtils.formatAge(comment.getDate())));
-
- add(new Label("file", comment.getBlobIdent().path) {
-
- @Override
- public void onEvent(IEvent<?> event) {
- super.onEvent(event);
-
- if (event.getPayload() instanceof PullRequestChanged) {
- PullRequestChanged pullRequestChanged = (PullRequestChanged) event.getPayload();
- AjaxRequestTarget target = pullRequestChanged.getTarget();
- target.add(this);
- }
- }
-
- }.setOutputMarkupId(true));
-
- add(new Link<Void>("compareView") {
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- setVisible(commentModel.getObject().getContext() != null);
- }
+ add(new CommentPanel("content", commentModel) {
@Override
- public void onClick() {
+ protected Component newActionComponent(String id) {
+ Fragment fragment = new Fragment(id, "actionFrag", InlineCommentActivityPanel.this);
PullRequestComment comment = commentModel.getObject();
- setResponsePage(RequestComparePage.class,
- RequestComparePage.paramsOf(comment.getRequest(), comment, null, null, null));
- }
-
- });
-
- WebMarkupContainer contextContainer = new WebMarkupContainer("context") {
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- setVisible(commentModel.getObject().getContext() != null);
- }
-
- @Override
- public void onEvent(IEvent<?> event) {
- super.onEvent(event);
-
- if (event.getPayload() instanceof PullRequestChanged) {
- PullRequestChanged pullRequestChanged = (PullRequestChanged) event.getPayload();
- AjaxRequestTarget target = pullRequestChanged.getTarget();
- target.add(this);
- }
- }
-
- };
- contextContainer.setOutputMarkupPlaceholderTag(true);
- add(contextContainer);
-
- contextContainer.add(new WebMarkupContainer("aboveOmitted") {
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- setVisible(commentModel.getObject().getContext().isAboveOmitted());
- }
-
- });
- contextContainer.add(new WebMarkupContainer("belowOmitted") {
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- setVisible(commentModel.getObject().getContext().isBelowOmitted());
- }
-
- });
- contextContainer.add(new ListView<DiffLine>("lines", new AbstractReadOnlyModel<List<DiffLine>>() {
-
- @Override
- public List<DiffLine> getObject() {
- return commentModel.getObject().getContext().getDiffLines();
- }
-
- }) {
-
- @Override
- protected void populateItem(final ListItem<DiffLine> item) {
- DiffLine diffLine = item.getModelObject();
-
- if (diffLine.getOperation() == Operation.INSERT) {
- item.add(AttributeAppender.append("class", " new"));
- item.add(new Label("oldLineNo"));
- item.add(new Label("newLineNo", diffLine.getNewLineNo() + 1));
- item.add(new Label("diffMark", "+"));
- } else if (diffLine.getOperation() == Operation.DELETE) {
- item.add(AttributeAppender.append("class", " old"));
- item.add(new Label("oldLineNo", diffLine.getOldLineNo() + 1));
- item.add(new Label("newLineNo"));
- item.add(new Label("diffMark", "-"));
- } else {
- item.add(AttributeAppender.append("class", " equal"));
- item.add(new Label("oldLineNo", diffLine.getOldLineNo()+1));
- item.add(new Label("newLineNo", diffLine.getNewLineNo()+1));
- item.add(new Label("diffMark", " "));
- }
- item.add(new ListView<CmToken>("tokens", diffLine.getTokens()) {
+ final String path = comment.getInlineInfo().getBlobIdent().path;
+ PageParameters params = RequestComparePage.paramsOf(
+ comment.getRequest(), comment, null, null, path);
+ fragment.add(new BookmarkablePageLink<Void>("fileLink", RequestComparePage.class, params) {
@Override
- protected void populateItem(ListItem<CmToken> item) {
- CmToken token = item.getModelObject();
- Label label;
- if (token.getText().equals("\r"))
- label = new Label("token", " ");
- else
- label = new Label("token", token.getText());
- item.add(label);
+ public IModel<?> getBody() {
+ return Model.of(path);
}
});
-
- if (item.getIndex() == commentModel.getObject().getContext().getLine())
- item.add(AttributeAppender.append("class", " before-comment"));
- }
-
- });
- add(new WebMarkupContainer("noContext") {
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- setVisible(commentModel.getObject().getContext() == null);
- }
-
- @Override
- public void onEvent(IEvent<?> event) {
- super.onEvent(event);
-
- if (event.getPayload() instanceof PullRequestChanged) {
- PullRequestChanged pullRequestChanged = (PullRequestChanged) event.getPayload();
- AjaxRequestTarget target = pullRequestChanged.getTarget();
- target.add(this);
- }
- }
-
- }.setOutputMarkupPlaceholderTag(true));
-
- /*
- * Make comment panel independent of context in order not to reset comment content while editing
- * when we update context of the inline comment
- */
- add(new CommentPanel("comment", commentModel) {
-
- @Override
- public void onEvent(IEvent<?> event) {
- super.onEvent(event);
-
- if (event.getPayload() instanceof PullRequestChanged) {
- PullRequestChanged pullRequestChanged = (PullRequestChanged) event.getPayload();
- AjaxRequestTarget target = pullRequestChanged.getTarget();
- target.prependJavaScript(String.format("$('body').append($('#%s'));", getMarkupId(true)));
- target.appendJavaScript(getAppendScript());
- }
- }
-
- private String getAppendScript() {
- return String.format(""
- + "var $beforeComment = $('#%s .before-comment');"
- + "if ($beforeComment.hasClass('line')) {"
- + " var $tr = $('<tr class=\"line comments\"><td colspan=\"3\"></td></tr>').insertAfter($beforeComment);"
- + " $tr.children().append($('#%s'));"
- + "} else {"
- + " $('#%s').insertAfter($beforeComment);"
- + "}",
- InlineCommentActivityPanel.this.getMarkupId(true), getMarkupId(true), getMarkupId(true));
- }
-
- @Override
- public void renderHead(IHeaderResponse response) {
- super.renderHead(response);
- response.render(OnDomReadyHeaderItem.forScript(getAppendScript()));
+ return fragment;
}
});
@@ -238,5 +56,4 @@ class InlineCommentActivityPanel extends Panel {
commentModel.detach();
super.onDetach();
}
-
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/requestdetail/overview/request-overview.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/requestdetail/overview/request-overview.css
index 94cbcead1b..208e3737e0 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/requestdetail/overview/request-overview.css
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/requestdetail/overview/request-overview.css
@@ -106,32 +106,12 @@
#request-detail .activities .activity>.detail>.update>.body td.status .running {
color: #AFAD1F;
}
-#request-detail .activities .activity.new>.avatar {
- background: #FCF6D6;
-}
-#request-detail .activities .table-diff>tbody>.line.comments>td {
- padding: 12px;
-}
-#request-detail .activities .table-diff>tbody>tr.omit>td .fa {
- font-size: 24px;
- color: #888;
- margin-left: 12px;
-}
-#request-detail .activities .inline-comment.panel>.panel-heading {
- padding: 8px;
-}
-#request-detail .activities .inline-comment.panel>.panel-heading .actions {
- margin-left: 12px;
-}
-#request-detail .activities .inline-comment.panel>.panel-heading .actions a {
- color: #BBB;
- margin-right: 4px;
-}
-#request-detail .activities .inline-comment.panel>.panel-heading:hover .actions a {
+#request-detail .activities .activity-summary a.file {
color: #666;
+ font-weight: bold;
}
-#request-detail .activities .inline-comment.panel {
- margin-bottom: 4px;
+#request-detail .activities .activity.new>.avatar {
+ background: #FCF6D6;
}
#request-detail .activities .activity>.detail>.discard>.icon {