mirror of
https://github.com/java-diff-utils/java-diff-utils.git
synced 2026-03-13 10:11:17 +08:00
Merge origin/master
This commit is contained in:
10
CHANGELOG.md
10
CHANGELOG.md
@@ -82,8 +82,10 @@ This project uses a custom versioning scheme (and not [Semantic Versioning](http
|
||||
* Ant build script
|
||||
* Generate output in unified diff format (thanks for Bill James)
|
||||
|
||||
[Unreleased]: https://github.com/java-diff-utils/java-diff-utils/compare/java-diff-utils-4.0...HEAD
|
||||
[4.0]: https://github.com/java-diff-utils/java-diff-utils/compare/diff-utils-3.0...java-diff-utils-4.0
|
||||
[3.0]: https://github.com/java-diff-utils/java-diff-utils/compare/diff-utils-2.2...diff-utils-3.0
|
||||
[2.2]: https://github.com/java-diff-utils/java-diff-utils/compare/diff-utils-2.0...diff-utils-2.2
|
||||
[Unreleased]: https://github.com/java-diff-utils/java-diff-utils/compare/java-diff-utils-parent-4.5...HEAD
|
||||
[4.5]: https://github.com/java-diff-utils/java-diff-utils/compare/java-diff-utils-parent-4.4...java-diff-utils-parent-4.5
|
||||
[4.4]: https://github.com/java-diff-utils/java-diff-utils/compare/java-diff-utils-4.0...java-diff-utils-parent-4.4
|
||||
[4.0]: https://github.com/java-diff-utils/java-diff-utils/compare/diffutils-3.0...java-diff-utils-4.0
|
||||
[3.0]: https://github.com/java-diff-utils/java-diff-utils/compare/diffutils-2.2...diffutils-3.0
|
||||
[2.2]: https://github.com/java-diff-utils/java-diff-utils/compare/diffutils-2.0...diffutils-2.2
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ Just add the code below to your maven dependencies:
|
||||
<dependency>
|
||||
<groupId>io.github.java-diff-utils</groupId>
|
||||
<artifactId>java-diff-utils</artifactId>
|
||||
<version>4.4</version>
|
||||
<version>4.5</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
@@ -88,5 +88,5 @@ or using gradle:
|
||||
|
||||
```groovy
|
||||
// https://mvnrepository.com/artifact/io.github.java-diff-utils/java-diff-utils
|
||||
implementation "io.github.java-diff-utils:java-diff-utils:4.4"
|
||||
implementation "io.github.java-diff-utils:java-diff-utils:4.5"
|
||||
```
|
||||
|
||||
@@ -59,25 +59,7 @@ public final class UnifiedDiffUtils {
|
||||
Matcher m = UNIFIED_DIFF_CHUNK_REGEXP.matcher(line);
|
||||
if (m.find()) {
|
||||
// Process the lines in the previous chunk
|
||||
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();
|
||||
}
|
||||
processLinesInPrevChunk(rawChunk, patch, old_ln, new_ln);
|
||||
// Parse the @@ header
|
||||
old_ln = m.group(1) == null ? 1 : Integer.parseInt(m.group(1));
|
||||
new_ln = m.group(3) == null ? 1 : Integer.parseInt(m.group(3));
|
||||
@@ -102,6 +84,14 @@ public final class UnifiedDiffUtils {
|
||||
}
|
||||
|
||||
// Process the lines in the last chunk
|
||||
processLinesInPrevChunk(rawChunk, patch, old_ln, new_ln);
|
||||
|
||||
return patch;
|
||||
}
|
||||
|
||||
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<>();
|
||||
@@ -116,14 +106,11 @@ public final class UnifiedDiffUtils {
|
||||
newChunkLines.add(rest);
|
||||
}
|
||||
}
|
||||
|
||||
patch.addDelta(new ChangeDelta<>(new Chunk<>(
|
||||
old_ln - 1, oldChunkLines), new Chunk<>(new_ln - 1,
|
||||
newChunkLines)));
|
||||
old_ln - 1, oldChunkLines), new Chunk<>(
|
||||
new_ln - 1, newChunkLines)));
|
||||
rawChunk.clear();
|
||||
}
|
||||
|
||||
return patch;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user