Example #1
0
 internal Hunk (Merge merge, Diff.Hunk [][] hunks, int start, int count, bool same)
 {
     this.merge = merge;
     this.hunks = hunks;
     this.start = start;
     this.count = count;
     this.same = same;
                     
     int ct = 0;
     foreach (Diff.Hunk[] hh in hunks) {
         foreach (Diff.Hunk h in hh) {
             if (!h.Same) {
                 ct++;
                 break;
             }
         }
     }
     conflict = (ct > 1);
 }
Example #2
0
        public static void MergeLists(IList original, IList user, IList newgen, out Queue<Conflict> conflicts, out Queue<ExtendedRange> ranges)
        {
            Merge m = new Merge(original, new []{user, newgen});

            conflicts = new Queue<Conflict>();
            ranges = new Queue<ExtendedRange>();

            foreach (Hunk h in m)
            {
                // Indicate conflict
                if (!h.IsSame(UserIndex) && !h.IsSame(NewGenIndex))
                    conflicts.Enqueue(new Conflict(new []{h.Changes(UserIndex), h.Changes(NewGenIndex), h.Original()}));

                // If one list has changes, take them
                else if (!h.IsSame(UserIndex))
                    ranges.Enqueue(new ExtendedRange(h.Original(), h.Changes(UserIndex), ChangeType.User));

                else if (!h.IsSame(NewGenIndex))
                    ranges.Enqueue(new ExtendedRange(h.Original(), h.Changes(NewGenIndex), ChangeType.Template));
                // If there were no differences in this region, take the original.
                else
                    ranges.Enqueue(new ExtendedRange(h.Original(), h.Original(), ChangeType.None));
            }
        }
Example #3
0
 public static IList MergeLists (IList original, IList [] changed, IComparer comparer, IHashCodeProvider hashcoder)
 {
     Merge m = new Merge (original, changed, comparer, hashcoder);
     ArrayList ret = new ArrayList ();
     ArrayList newlines = new ArrayList ();
     foreach (Hunk h in m) {
         newlines.Clear ();
                         
         for (int i = 0; i < changed.Length; i++)
             if (!h.IsSame (i))
                 newlines.Add (h.Changes (i));
                         
         // If there were no differences in this region, take the original.
         if (newlines.Count == 0)
             ret.AddRange (h.Original ());
                         
                         // If one list has changes, take them
         else if (newlines.Count == 1)
             ret.AddRange ((Range) newlines [0]);
                         
                         // Indicate conflict
         else
             ret.Add (new Conflict ((Range []) newlines.ToArray (typeof(Range))));
     }
     return ret;
 }
        private void ProcessConflict(Merge.Conflict conflict)
        {
            string[] userLines = SlyceMerge.GetLinesFromRange(user, conflict.Ranges[Merge.UserIndex]);
            string[] newgenLines = SlyceMerge.GetLinesFromRange(newgen, conflict.Ranges[Merge.NewGenIndex]);

            if (userLines.Length == 0 && newgenLines.Length == 0)
            {
                // user and template have both deleted some lines. Add them in as virtual lines.
                foreach (string line in SlyceMerge.GetLinesFromRange(prevgen, conflict.Ranges[Merge.PrevGenIndex]))
                {
                    vdo.AddLineToLeft(line, ChangeType.UserAndTemplate);
                }

                return;
            }

            Diff diff = new Diff(userLines, newgenLines, true, true);

            foreach (Diff.Hunk hunk in diff)
            {
                if (hunk.Same)
                {
                    foreach (string line in hunk.Original())
                    {
                        vdo.AddLine(line, ChangeType.None);
                    }
                    continue;
                }

                // Conflict
                VisualDiffOutput.ConflictRange crange = new VisualDiffOutput.ConflictRange();
                crange.StartLineIndex = vdo.LeftLines.Count;
                for (int i = hunk.Left.Start; i <= hunk.Left.End; i++)
                {
                    vdo.LeftLines.Add(new DiffLine(userLines[i], ChangeType.User));
                    vdo.RightLines.Add(new DiffLine("", ChangeType.User, true));
                }
                for (int i = hunk.Right.Start; i <= hunk.Right.End; i++)
                {
                    vdo.LeftLines.Add(new DiffLine(newgenLines[i], ChangeType.Template));
                    vdo.RightLines.Add(new DiffLine("", ChangeType.Template, true));
                }
                crange.EndLineIndex = vdo.LeftLines.Count;
                vdo.ConflictRanges.Add(crange);
                vdo.DiffType = TypeOfDiff.Conflict;
            }
        }