Example #1
0
        public static void CollectActions(SourceLine[] source,
			VersionLine[] version1,
			VersionLine[] version2,
			List<MergeAction> removeActions,
			List<MergeAction> insertActions)
        {
            int si = 0, v1 = 0, v2 = 0;
            while (si < source.Length || v1 < version1.Length || v2 < version2.Length) {
                if (v1 < version1.Length) {
                    if (version1[v1].SourcePositon >= 0) {
                        v1++;
                    } else {
                        var sp = v1 - 1 >= 0 ? version1[v1 - 1].SourcePositon : 0;
                        var mergeAction = new MergeAction(sp);
                        while (v1 < version1.Length && version1[v1].SourcePositon < 0) {
                            mergeAction.Lines.Add(version1[v1]);
                            v1++;
                        }

                        insertActions.Add(mergeAction);
                    }
                }

                if (v2 < version2.Length) {
                    if (version2[v2].SourcePositon >= 0) {
                        v2++;
                    } else {
                        var sp = v2 - 1 >= 0 ? version2[v2 - 1].SourcePositon : 0;
                        var mergeAction = new MergeAction(sp);
                        while (v2 < version2.Length && version2[v2].SourcePositon < 0) {
                            mergeAction.Lines.Add(version2[v2]);
                            v2++;
                        }
                        insertActions.Add(mergeAction);
                    }
                }

                if (si < source.Length) {
                    if (source[si].ExistsFlag != 2) {
                        var mergeAction = new MergeAction(si);
                        mergeAction.Lines.Add(source[si]);
                        removeActions.Add(mergeAction);
                    }
                    si++;
                }
            }
        }
Example #2
0
        public Merger(string[] source, string[] version1, string[] version2)
        {
            _source = new SourceLine[source.Length];
            for (var i = 0; i < source.Length; i++) {
                _source[i] = new SourceLine(source[i]);
            }

            _version1 = new VersionLine[version1.Length];
            for (var i = 0; i < version1.Length; i++) {
                _version1[i] = new VersionLine(version1[i]);
            }

            _version2 = new VersionLine[version2.Length];
            for (var i = 0; i < version2.Length; i++) {
                _version2[i] = new VersionLine(version2[i]);
            }
        }
Example #3
0
        public static void FindPositions(SourceLine[] source, VersionLine[] version)
        {
            var j = source.Length - 1;
            for (var i = version.Length - 1; i >= 0; i--) {
                var ver = version[i];

                if (j < 0) {
                    continue;
                }

                if (source[j].TrimedContent == ver.TrimedContent) {
                    ver.SourcePositon = j;
                    source[j].ExistsFlag += 1;
                    j--;
                } else {
                    var k = j;
                    k--;
                    while (k >= 0) {
                        if (source[k].TrimedContent == ver.TrimedContent) {
                            j = k;
                            ver.SourcePositon = j;
                            source[j].ExistsFlag += 1;
                            j--;
                            break;
                        }
                        k--;
                    }
                }
            }
        }