-
-
Notifications
You must be signed in to change notification settings - Fork 214
Description
Describe the bug
A clear and concise description of what the bug is.
This is not bug, but a improvement issue. we need to get exact changed lines when using UnifiedDiffUtils.parseUnifiedDiff in current version we will get a Patch<String>
java-diff-utils/java-diff-utils/src/main/java/com/github/difflib/UnifiedDiffUtils.java
Line 43 in 73c4c30
| public static Patch<String> parseUnifiedDiff(List<String> diff) { |
In Patch<String>, the core is the structure Chunk<T>
java-diff-utils/java-diff-utils/src/main/java/com/github/difflib/UnifiedDiffUtils.java
Lines 110 to 112 in 73c4c30
| patch.addDelta(new ChangeDelta<>(new Chunk<>( | |
| old_ln - 1, oldChunkLines), new Chunk<>( | |
| new_ln - 1, newChunkLines))); |
but now the information that we can use only the position and lines
java-diff-utils/java-diff-utils/src/main/java/com/github/difflib/patch/Chunk.java
Lines 38 to 39 in e11c159
| private final int position; | |
| private List<T> lines; |
and in the lines, we can't tell the difference between no changed lines and changed lines, because we do not do this work when we get the lines:
java-diff-utils/java-diff-utils/src/main/java/com/github/difflib/UnifiedDiffUtils.java
Lines 93 to 115 in e11c159
| private static void processLinesInPrevChunk(List<String[]> rawChunk, Patch<String> patch, int old_ln, int new_ln) { | |
| String tag; | |
| String rest; | |
| if (!rawChunk.isEmpty()) { | |
| List<String> oldChunkLines = new ArrayList<>(); | |
| List<String> newChunkLines = new ArrayList<>(); | |
| for (String[] raw_line : rawChunk) { | |
| tag = raw_line[0]; | |
| rest = raw_line[1]; | |
| if (" ".equals(tag) || "-".equals(tag)) { | |
| oldChunkLines.add(rest); | |
| } | |
| if (" ".equals(tag) || "+".equals(tag)) { | |
| newChunkLines.add(rest); | |
| } | |
| } | |
| patch.addDelta(new ChangeDelta<>(new Chunk<>( | |
| old_ln - 1, oldChunkLines), new Chunk<>( | |
| new_ln - 1, newChunkLines))); | |
| rawChunk.clear(); | |
| } | |
| } |
we do not make full use of tag, actually we can:
java-diff-utils/java-diff-utils/src/main/java/com/github/difflib/UnifiedDiffUtils.java
Line 103 in e11c159
| if (" ".equals(tag) || "-".equals(tag)) { |
java-diff-utils/java-diff-utils/src/main/java/com/github/difflib/UnifiedDiffUtils.java
Line 106 in e11c159
| if (" ".equals(tag) || "+".equals(tag)) { |
To Reproduce
Steps to reproduce the behavior:
- Example data
- simple programm snippet
- See error
no reproduce, this is improvement issue.
Expected behavior
A clear and concise description of what you expected to happen.
System
- Java version
- Version [e.g. 22]
latest master branch in Github.