Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Conflict"/> class.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="changeset1">The changeset1.</param>
        /// <param name="changeset2">The changeset2.</param>
        /// <param name="conflictBlocks">The conflict blocks.</param>
        /// <exception cref="System.ArgumentNullException"></exception>
        /// <exception cref="System.ArgumentOutOfRangeException"></exception>
        internal Conflict(IReadOnlyList <string> source, MergableChangeset changeset1, MergableChangeset changeset2,
                          ConflictBlocks conflictBlocks)
        {
            if ((source == null) || (changeset1 == null) || (changeset2 == null))
            {
                throw new ArgumentNullException();
            }

            var allChanges  = new HashSet <IMergableChange>(changeset1.Values.Union(changeset2.Values));
            int start       = allChanges.Min(c => c.Start);
            int afterFinish = allChanges.Max(c => c.AfterFinish);

            if ((start > source.Count) || (afterFinish > source.Count))
            {
                throw new ArgumentOutOfRangeException();
            }

            int removedAmount = afterFinish - start;

            IEnumerable <string> originalBlock = Utils.GetSubArray(source, start, afterFinish);
            IEnumerable <string> changedBlock1 = GetChangedBlock(source, start, afterFinish, changeset1);
            IEnumerable <string> changedBlock2 = GetChangedBlock(source, start, afterFinish, changeset2);

            IEnumerable <string> newContent =
                GetNewContent(originalBlock, changedBlock1, changedBlock2, conflictBlocks);

            Initialize(start, removedAmount, newContent.ToArray());
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the new content.
        /// </summary>
        /// <param name="originalBlock">The original block.</param>
        /// <param name="changedBlock1">The changed block1.</param>
        /// <param name="changedBlock2">The changed block2.</param>
        /// <param name="conflictBlocks">The conflict blocks.</param>
        /// <returns></returns>
        private static IEnumerable <string> GetNewContent(IEnumerable <string> originalBlock,
                                                          IEnumerable <string> changedBlock1,
                                                          IEnumerable <string> changedBlock2,
                                                          ConflictBlocks conflictBlocks)
        {
            yield return(conflictBlocks.ConflictBlockBegin);

            yield return(conflictBlocks.ConflictBlockSource);

            foreach (string line in originalBlock)
            {
                yield return(line);
            }

            yield return(conflictBlocks.ConflictBlockChanged1);

            foreach (string line in changedBlock1)
            {
                yield return(line);
            }

            yield return(conflictBlocks.ConflictBlockChanged2);

            foreach (string line in changedBlock2)
            {
                yield return(line);
            }

            yield return(conflictBlocks.ConflictBlockEnd);
        }
Esempio n. 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Conflict"/> class.
        /// </summary>
        /// <param name="change1">The change1.</param>
        /// <param name="change2">The change2.</param>
        /// <param name="source">The source.</param>
        /// <param name="conflictBlocks">The conflict blocks.</param>
        /// <exception cref="System.ArgumentNullException"></exception>
        /// <exception cref="System.ArgumentOutOfRangeException">
        /// </exception>
        /// <exception cref="System.ArgumentException"></exception>
        internal Conflict(IMergableChange change1, IMergableChange change2, IReadOnlyList <string> source,
                          ConflictBlocks conflictBlocks)
        {
            if ((change1 == null) || (change2 == null) || (source == null))
            {
                throw new ArgumentNullException();
            }

            int start = Math.Min(change1.Start, change2.Start);

            if (start > source.Count)
            {
                throw new ArgumentOutOfRangeException();
            }

            int afterFinish = Math.Max(change1.AfterFinish, change2.AfterFinish);

            if (afterFinish > source.Count)
            {
                throw new ArgumentOutOfRangeException();
            }

            if ((change1.Start >= change2.AfterFinish) || (change2.Start >= change1.AfterFinish))
            {
                if (change1.Start != change2.Start)
                {
                    throw new ArgumentException();
                }
            }

            int removedAmount = afterFinish - start;

            IEnumerable <string> originalBlock = Utils.GetSubArray(source, start, afterFinish);
            IEnumerable <string> changedBlock1 = GetChangedBlock(source, start, afterFinish, change1);
            IEnumerable <string> changedBlock2 = GetChangedBlock(source, start, afterFinish, change2);

            IEnumerable <string> newContent =
                GetNewContent(originalBlock, changedBlock1, changedBlock2, conflictBlocks);

            Initialize(start, removedAmount, newContent.ToArray());
        }
Esempio n. 4
0
 public CustomMerger(ConflictBlocks conflictBlocks)
     : base(conflictBlocks)
 {
 }
Esempio n. 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CustomMerger"/> class.
 /// </summary>
 /// <param name="conflictBlocks">The conflict blocks.</param>
 public SimpleMerger(ConflictBlocks conflictBlocks)
 {
     ConflictBlocks = conflictBlocks;
 }