Skip to content

Commit ce05cbf

Browse files
committed
1 parent f71275d commit ce05cbf

File tree

2 files changed

+54
-6
lines changed

2 files changed

+54
-6
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*-
2+
* #%L
3+
* java-diff-utils
4+
* %%
5+
* Copyright (C) 2009 - 2017 java-diff-utils
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
* #L%
19+
*/
20+
package com.github.difflib.patch;
21+
22+
import java.util.List;
23+
24+
/**
25+
*
26+
* @author tw
27+
*/
28+
@FunctionalInterface
29+
public interface ConflictOutput<T> {
30+
31+
public void processConflict(VerifyChunk verifyChunk, AbstractDelta<T> delta, List<T> result) throws PatchFailedException;
32+
}

java-diff-utils/src/main/java/com/github/difflib/patch/Patch.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@
2929
import java.util.ListIterator;
3030

3131
/**
32-
* Describes the patch holding all deltas between the original and revised texts.
33-
*
32+
* Describes the patch holding all deltas between the original and revised
33+
* texts.
34+
*
3435
* @author <a href="dm.naumenko@gmail.com">Dmitry Naumenko</a>
3536
* @param <T> The type of the compared elements in the 'lines'.
3637
*/
@@ -57,10 +58,25 @@ public List<T> applyTo(List<T> target) throws PatchFailedException {
5758
ListIterator<AbstractDelta<T>> it = getDeltas().listIterator(deltas.size());
5859
while (it.hasPrevious()) {
5960
AbstractDelta<T> delta = it.previous();
60-
delta.verifyAntApplyTo(result);
61+
VerifyChunk valid = delta.verifyAntApplyTo(result);
62+
if (valid != VerifyChunk.OK) {
63+
64+
}
6165
}
6266
return result;
6367
}
68+
69+
private ConflictOutput<T> conflictOutput = (VerifyChunk verifyChunk, AbstractDelta<T> delta, List<T> result) -> {
70+
throw new PatchFailedException("could not apply patch due to " + verifyChunk.toString());
71+
};
72+
73+
/**
74+
* Alter normal conflict output behaviour to e.g. inclide some conflict statements in the result, like git does it.
75+
*/
76+
public Patch withConflictOutput(ConflictOutput<T> conflictOutput) {
77+
this.conflictOutput = conflictOutput;
78+
return this;
79+
}
6480

6581
/**
6682
* Restore the text to original. Opposite to applyTo() method.
@@ -114,14 +130,14 @@ public static <T> Patch<T> generate(List<T> original, List<T> revised, List<Chan
114130
Patch<T> patch = new Patch<>(_changes.size());
115131
int startOriginal = 0;
116132
int startRevised = 0;
117-
133+
118134
List<Change> changes = _changes;
119-
135+
120136
if (includeEquals) {
121137
changes = new ArrayList<Change>(_changes);
122138
Collections.sort(changes, comparing(d -> d.startOriginal));
123139
}
124-
140+
125141
for (Change change : changes) {
126142

127143
if (includeEquals && startOriginal < change.startOriginal) {

0 commit comments

Comments
 (0)