Skip to content

Commit 4a74085

Browse files
committed
Adding diff3_dig
1 parent cb1e18b commit 4a74085

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

lib/src/diff.dart

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ class conflictRegion {
9393
int file2RegionEnd;
9494
}
9595

96+
97+
class Diff3DigResult {
98+
bool Conflict;
99+
List<String> Text;
100+
}
101+
96102
//
97103
// Merge Result Objects
98104
//
@@ -646,3 +652,45 @@ List<IMergeResultBlock> diff3_merge(List<String> a, List<String> o, List<String>
646652
flushOk(okLines, result);
647653
return result;
648654
}
655+
656+
Diff3DigResult diff3_dig(String ours, String base, String theirs) {
657+
List<String> a = ours.split("\n");
658+
List<String> b = theirs.split("\n");
659+
List<String> o = base.split("\n");
660+
661+
List<IMergeResultBlock> merger = diff3_merge(a, o, b, false);
662+
663+
bool conflict = false;
664+
List<String> lines = new List<String>();
665+
666+
for (int i = 0; i < merger.length; i++) {
667+
IMergeResultBlock item = merger[i];
668+
669+
if (item is MergeOKResultBlock) {
670+
lines.addAll(item.ContentLines);
671+
} else if (item is MergeConflictResultBlock) {
672+
List<commonOrDifferentThing> inners = diff_comm(item.LeftLines, item.RightLines);
673+
for (int j = 0; j < inners.length; j++) {
674+
commonOrDifferentThing inner = inners[j];
675+
if (inner.common.length > 0) {
676+
lines.addAll(inner.common);
677+
} else {
678+
conflict = true;
679+
lines.add("<<<<<<<<<");
680+
lines.addAll(inner.file1);
681+
lines.add("=========");
682+
lines.addAll(inner.file2);
683+
lines.add(">>>>>>>>>");
684+
}
685+
}
686+
687+
} else {
688+
throw new StateError("item type is not expected: ${item.runtimeType}");
689+
}
690+
}
691+
692+
Diff3DigResult diff3DigResult = new Diff3DigResult();
693+
diff3DigResult.Conflict = conflict;
694+
diff3DigResult.Text = lines;
695+
return diff3DigResult;
696+
}

0 commit comments

Comments
 (0)