Skip to content

Commit 7453a0c

Browse files
committed
refactor: delegate checking VerifyChunk type to ConflictOutput implementations
1 parent 0837235 commit 7453a0c

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

src/commonMain/kotlin/io/github/petertrr/diffutils/patch/ConflictProducingConflictOutput.kt

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,19 @@ public class ConflictProducingConflictOutput : ConflictOutput<String> {
2424
throw UnsupportedOperationException("Not supported yet")
2525
}
2626

27-
val orgData = ArrayList<String>()
27+
if (verifyChunk != VerifyChunk.OK) {
28+
val orgData = ArrayList<String>()
2829

29-
repeat(delta.source.size()) {
30-
orgData.add(result.removeAt(delta.source.position))
31-
}
30+
repeat(delta.source.size()) {
31+
orgData.add(result.removeAt(delta.source.position))
32+
}
33+
34+
orgData.add(0, "<<<<<< HEAD")
35+
orgData.add("======")
36+
orgData.addAll(delta.source.lines)
37+
orgData.add(">>>>>>> PATCH")
3238

33-
orgData.add(0, "<<<<<< HEAD")
34-
orgData.add("======")
35-
orgData.addAll(delta.source.lines)
36-
orgData.add(">>>>>>> PATCH")
37-
result.addAll(delta.source.position, orgData)
39+
result.addAll(delta.source.position, orgData)
40+
}
3841
}
3942
}

src/commonMain/kotlin/io/github/petertrr/diffutils/patch/ExceptionProducingConflictOutput.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
package io.github.petertrr.diffutils.patch
2020

2121
public class ExceptionProducingConflictOutput<T> : ConflictOutput<T> {
22-
override fun processConflict(verifyChunk: VerifyChunk, delta: Delta<T>, result: MutableList<T>): Nothing =
23-
throw PatchFailedException("Could not apply patch due to: $verifyChunk")
22+
override fun processConflict(verifyChunk: VerifyChunk, delta: Delta<T>, result: MutableList<T>) {
23+
if (verifyChunk != VerifyChunk.OK) {
24+
throw PatchFailedException("Could not apply patch due to: $verifyChunk")
25+
}
26+
}
2427
}

src/commonMain/kotlin/io/github/petertrr/diffutils/patch/Patch.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,7 @@ public class Patch<T>(private var conflictOutput: ConflictOutput<T> = ExceptionP
4747
while (it.hasPrevious()) {
4848
val delta = it.previous()
4949
val verifyChunk = delta.verifyAndApplyTo(result)
50-
51-
if (verifyChunk != VerifyChunk.OK) {
52-
conflictOutput.processConflict(verifyChunk, delta, result)
53-
}
50+
conflictOutput.processConflict(verifyChunk, delta, result)
5451
}
5552

5653
return result

0 commit comments

Comments
 (0)