コード例 #1
0
        private string merge(string commonBase, string ours, string theirs)
        {
            MergeResult r = MergeAlgorithm.merge(new RawText(Constants.encode(commonBase)), new RawText(Constants.encode(ours)), new RawText(Constants.encode(theirs)));

            using (var ms = new MemoryStream())
                using (var bo = new BinaryWriter(ms))
                {
                    fmt.formatMerge(bo, r, "B", "O", "T", Constants.CHARSET.WebName);
                    return(Constants.CHARSET.GetString(ms.ToArray()));
                }
        }
コード例 #2
0
        public void MergeAlgorithm_Merge_BehaviorTest_AddTextToStart()
        {
            MergeAlgorithm m = new MergeAlgorithm();
            String[] original = new String[] { "Orig", "ina", "l Text" };
            String[] latest = new String[] { "Lat", "est T", "est", "Orig", "ina", "l Text" };

            String[] merged = m.Merge(original, latest);

            Assert.AreEqual(latest.Length, merged.Length);
            for (int i = 0; i < merged.Length; i++)
            {
                Assert.AreEqual(latest[i], merged[i]);
            }
            // This is good
        }
コード例 #3
0
        public void AppendToEmptyCollection()
        {
            MergeAlgorithm<NamedObject> mergeAlgorithm = new MergeAlgorithm<NamedObject>();
            mergeAlgorithm.Merge(_emptyNodeCollection, _nodeCollection);

            Assert.AreEqual(4, _emptyNodeCollection.Count);
            Assert.AreEqual("File", _emptyNodeCollection[0].Content.Name);
            Assert.That(_emptyNodeCollection[0].Children, Is.Null.Or.Empty);
            Assert.AreEqual("Edit", _emptyNodeCollection[1].Content.Name);
            Assert.AreEqual(2, _emptyNodeCollection[1].Children.Count);
            Assert.AreEqual("Undo", _emptyNodeCollection[1].Children[0].Content.Name);
            Assert.That(_emptyNodeCollection[1].Children[0].Children, Is.Null.Or.Empty);
            Assert.AreEqual("Redo", _emptyNodeCollection[1].Children[1].Content.Name);
            Assert.That(_emptyNodeCollection[1].Children[1].Children, Is.Null.Or.Empty);
            Assert.AreEqual("Tools", _emptyNodeCollection[2].Content.Name);
            Assert.That(_emptyNodeCollection[2].Children, Is.Null.Or.Empty);
            Assert.AreEqual("Help", _emptyNodeCollection[3].Content.Name);
            Assert.That(_emptyNodeCollection[3].Children, Is.Null.Or.Empty);
        }
コード例 #4
0
		/// <param name="local"></param>
		/// <param name="inCore"></param>
		protected internal ResolveMerger(Repository local, bool inCore) : base(local)
		{
			DiffAlgorithm.SupportedAlgorithm diffAlg = local.GetConfig().GetEnum(ConfigConstants
				.CONFIG_DIFF_SECTION, null, ConfigConstants.CONFIG_KEY_ALGORITHM, DiffAlgorithm.SupportedAlgorithm
				.HISTOGRAM);
			mergeAlgorithm = new MergeAlgorithm(DiffAlgorithm.GetAlgorithm(diffAlg));
			commitNames = new string[] { "BASE", "OURS", "THEIRS" };
			oi = GetObjectInserter();
			this.inCore = inCore;
			if (inCore)
			{
				dircache = DirCache.NewInCore();
			}
		}
コード例 #5
0
 /// <exception cref="System.IO.IOException"></exception>
 private string Merge(string commonBase, string ours, string theirs)
 {
     MergeResult<RawText> r = new MergeAlgorithm().Merge(RawTextComparator.DEFAULT, RT(commonBase
         ), RT(ours), RT(theirs));
     ByteArrayOutputStream bo = new ByteArrayOutputStream(50);
     fmt.FormatMerge(bo, r, "B", "O", "T", Constants.CHARACTER_ENCODING);
     return Sharpen.Extensions.CreateString(bo.ToByteArray(), Constants.CHARACTER_ENCODING
         );
 }
コード例 #6
0
 private static void MergeNodes(MergeableNodeCollection<ICommandItem> nodes, params IEnumerable<MergeableNodeCollection<ICommandItem>>[] nodeCollections)
 {
     var mergeAlgorithm = new MergeAlgorithm<ICommandItem> { CloneNodesOnMerge = true };
     foreach (var nodeCollection in nodeCollections)
         foreach (var additionalNodes in nodeCollection)
             mergeAlgorithm.Merge(nodes, additionalNodes);
 }
コード例 #7
0
        public void MergeAlgorithm_Merge_ParameterTest_Null_Null()
        {
            MergeAlgorithm m = new MergeAlgorithm();
            String[] original = null;
            String[] latest = null;

            try
            {
                m.Merge(original, latest);
                Assert.Fail();
            }
            catch
            {
                // This is good
            }
        }
コード例 #8
0
        public void MergeAlgorithm_Merge_ParameterTest_NotNullNotEmpty_NotNullNotEmpty()
        {
            MergeAlgorithm m = new MergeAlgorithm();
            String[] original = new String[] { "Test1", "Test2" };
            String[] latest = new String[] { "Test1", "Test2" };

            m.Merge(original, latest);
            // This is good
        }
コード例 #9
0
        public void MergeAlgorithm_Merge_BehaviorTest_RemoveTextInterleaved()
        {
            MergeAlgorithm m = new MergeAlgorithm();
            String[] original = new String[] { "Orig", "ina", "l ver", "y lo", "ng T", "ext" };
            String[] latest = new String[] { "ina", "y lo", "ext" };

            String[] merged = m.Merge(original, latest);

            Assert.AreEqual(latest.Length, merged.Length);
            for (int i = 0; i < merged.Length; i++)
            {
                Assert.AreEqual(latest[i], merged[i]);
            }
            // This is good
        }
コード例 #10
0
ファイル: MergePlan.cs プロジェクト: pwdlugosz/Horse
        public MergePlan(MergeMethod JM, MergeAlgorithm JA, RecordWriter Output, FNodeSet Fields, Predicate Where, DataSet Data1, DataSet Data2, 
            Key Equality1, Key Equality2, StaticRegister Memory1, StaticRegister Memory2)
            : base()
        {

            this._use_method = JM;
            this._use_algorithm = JA;
            this._output = Output;
            this._fields = Fields;
            this._where = Where;
            this._data1 = Data1;
            this._data2 = Data2;
            this._key1 = Equality1;
            this._key2 = Equality2;
            this._mem1 = Memory1;
            this._mem2 = Memory2;
            this.Name = "MERGE";

        }
コード例 #11
0
ファイル: MergePlan.cs プロジェクト: pwdlugosz/Horse
        // Main Join Functions //
        /// <summary>
        /// Allows the user to perform a join based on the equality predicate AND each predicate link via 'AND'
        /// </summary>
        /// <param name="Output"></param>
        /// <param name="JM"></param>
        /// <param name="JA"></param>
        /// <param name="T1"></param>
        /// <param name="J1"></param>
        /// <param name="T2"></param>
        /// <param name="J2"></param>
        /// <param name="CM"></param>
        public static void Join(MergeMethod JM, MergeAlgorithm JA, RecordWriter Output, FNodeSet Fields, Predicate Where, DataSet Data1, DataSet Data2, 
            Key Equality1, Key Equality2, StaticRegister Memory1, StaticRegister Memory2)
        {

            // Do some checks first //
            if (Where == null)
                Where = Predicate.TrueForAll;
            if (Equality1.Count != Equality2.Count)
                throw new Exception("Both join keys must have the same length");
            if (Equality1.Count == 0)
                JA = MergeAlgorithm.NestedLoop;

            // Nested loop; if the algorithm is nested loop and we have keys, we need to build a new where clause that has the equality predicates //
            FNodeResult nl_node = new FNodeResult(null, new AndMany());
            nl_node.AddChildNode(Where.Node.CloneOfMe());
            for (int i = 0; i < Equality1.Count; i++)
            {

                FNodeFieldRef left = new FNodeFieldRef(null, Equality1[i], Data1.Columns.ColumnAffinity(Equality1[i]), Data1.Columns.ColumnSize(Equality1[i]), Memory1);
                FNodeFieldRef right = new FNodeFieldRef(null, Equality2[i], Data2.Columns.ColumnAffinity(Equality2[i]), Data2.Columns.ColumnSize(Equality2[i]), Memory2);
                FNodeResult eq = new FNodeResult(null, new CellBoolEQ());
                eq.AddChildren(left, right);
                nl_node.AddChildNode(eq);

            }

            Predicate nl_where = (Equality1.Count == 0 ? Where : new Predicate(nl_node));

            // Switch //
            switch (JA)
            {
                case MergeAlgorithm.SortMerge:
                    SortMerge(JM, Output, Fields, Where, Data1, Data2, Equality1, Equality2, Memory1, Memory2);
                    break;
                case MergeAlgorithm.NestedLoop:
                    NestedLoop(JM, Output, Fields, nl_where, Data1, Data2, Memory1, Memory2);
                    break;
                default:
                    HashTable(JM, Output, Fields, Where, Data1, Data2, Equality1, Equality2, Memory1, Memory2);
                    break;
            }

        }
コード例 #12
0
        public void ComplexMerge()
        {
            var nodeCollection = new MergeableNodeCollection<NamedObject>();
            nodeCollection.AddRange(new[]
            {
                new MergeableNode<NamedObject>(new NamedObject("Ignore1"), new MergePoint(MergeOperation.Ignore, null)),
                new MergeableNode<NamedObject>(new NamedObject("Ignore2"), new MergePoint(MergeOperation.Match, "Unknown")),
                new MergeableNode<NamedObject>(new NamedObject("Ignore3"), new MergePoint(MergeOperation.InsertBefore, "Unknown")),
                new MergeableNode<NamedObject>(new NamedObject("Ignore4"), new MergePoint(MergeOperation.InsertAfter, "Unknown")),
                new MergeableNode<NamedObject>(new NamedObject("Ignore5"), new MergePoint(MergeOperation.Replace, "Unknown")),
                new MergeableNode<NamedObject>(new NamedObject("Ignore6"), new MergePoint(MergeOperation.Remove, "Unknown")),

                new MergeableNode<NamedObject>(new NamedObject("PostHelp")),
                new MergeableNode<NamedObject>(new NamedObject("PreFile"), new MergePoint(MergeOperation.Prepend, null)),
                new MergeableNode<NamedObject>(new NamedObject("DoNothing"), new MergePoint(MergeOperation.Match, "Help")),
                new MergeableNode<NamedObject>(new NamedObject("View"), new MergePoint(MergeOperation.InsertAfter, "Edit")),
                new MergeableNode<NamedObject>(new NamedObject("Windows"), new MergePoint(MergeOperation.InsertBefore, "Help")),
                new MergeableNode<NamedObject>(new NamedObject("HelpNew"), new MergePoint(MergeOperation.Replace, "Help")),
                new MergeableNode<NamedObject>(new NamedObject("RemoveTools"), new MergePoint(MergeOperation.Remove, "Tools")),

                new MergeableNode<NamedObject>(
                    new NamedObject("Edit"),
                    new MergePoint(MergeOperation.Append),
                        new MergeableNode<NamedObject>(new NamedObject("Cut"), new MergePoint(MergeOperation.InsertAfter, "Unkown"), new MergePoint(MergeOperation.InsertAfter, "Redo")),
                        new MergeableNode<NamedObject>(new NamedObject("Paste"), new MergePoint(MergeOperation.InsertAfter, "Unkown"), new MergePoint(MergeOperation.Append)),
                        new MergeableNode<NamedObject>(new NamedObject("Copy"), new MergePoint(MergeOperation.InsertAfter, "Unkown"), new MergePoint(MergeOperation.InsertBefore, "Paste")),
                        new MergeableNode<NamedObject>(new NamedObject("Format"),
                            new MergeableNode<NamedObject>(new NamedObject("Comment")),
                            new MergeableNode<NamedObject>(new NamedObject("Uncomment"))),
                        new MergeableNode<NamedObject>(new NamedObject("PreUndo"), new MergePoint(MergeOperation.InsertAfter, "Unkown"), new MergePoint(MergeOperation.Prepend)),
                        new MergeableNode<NamedObject>(new NamedObject("Ignore"), new MergePoint(MergeOperation.InsertAfter, "Unkown"), new MergePoint(MergeOperation.Ignore)),
                        new MergeableNode<NamedObject>(new NamedObject("UndoNew"), new MergePoint(MergeOperation.InsertAfter, "Unkown"), new MergePoint(MergeOperation.Replace, "Undo")),
                        new MergeableNode<NamedObject>(new NamedObject("Redo"), new MergePoint(MergeOperation.InsertAfter, "Unkown"), new MergePoint(MergeOperation.Remove, "Redo"))),
            });

            MergeAlgorithm<NamedObject> mergeAlgorithm = new MergeAlgorithm<NamedObject>();
            mergeAlgorithm.Merge(_nodeCollection, nodeCollection);

            Assert.AreEqual(7, _nodeCollection.Count);
            Assert.AreEqual("PreFile", _nodeCollection[0].Content.Name);
            Assert.That(_nodeCollection[0].Children, Is.Null.Or.Empty);
            Assert.AreEqual("File", _nodeCollection[1].Content.Name);
            Assert.That(_nodeCollection[1].Children, Is.Null.Or.Empty);

            Assert.AreEqual("Edit", _nodeCollection[2].Content.Name);
            Assert.AreEqual(6, _nodeCollection[2].Children.Count);
            Assert.AreEqual("PreUndo", _nodeCollection[2].Children[0].Content.Name);
            Assert.That(_nodeCollection[2].Children[0].Children, Is.Null.Or.Empty);
            Assert.AreEqual("UndoNew", _nodeCollection[2].Children[1].Content.Name);
            Assert.That(_nodeCollection[2].Children[1].Children, Is.Null.Or.Empty);
            Assert.AreEqual("Cut", _nodeCollection[2].Children[2].Content.Name);
            Assert.That(_nodeCollection[2].Children[2].Children, Is.Null.Or.Empty);
            Assert.AreEqual("Copy", _nodeCollection[2].Children[3].Content.Name);
            Assert.That(_nodeCollection[2].Children[3].Children, Is.Null.Or.Empty);
            Assert.AreEqual("Paste", _nodeCollection[2].Children[4].Content.Name);
            Assert.That(_nodeCollection[2].Children[4].Children, Is.Null.Or.Empty);
            Assert.AreEqual("Format", _nodeCollection[2].Children[5].Content.Name);
            Assert.AreEqual(2, _nodeCollection[2].Children[5].Children.Count);
            Assert.AreEqual("Comment", _nodeCollection[2].Children[5].Children[0].Content.Name);
            Assert.That(_nodeCollection[2].Children[5].Children[0].Children, Is.Null.Or.Empty);
            Assert.AreEqual("Uncomment", _nodeCollection[2].Children[5].Children[1].Content.Name);
            Assert.That(_nodeCollection[2].Children[5].Children[1].Children, Is.Null.Or.Empty);

            Assert.AreEqual("View", _nodeCollection[3].Content.Name);
            Assert.That(_nodeCollection[3].Children, Is.Null.Or.Empty);
            Assert.AreEqual("Windows", _nodeCollection[4].Content.Name);
            Assert.That(_nodeCollection[4].Children, Is.Null.Or.Empty);
            Assert.AreEqual("HelpNew", _nodeCollection[5].Content.Name);
            Assert.That(_nodeCollection[5].Children, Is.Null.Or.Empty);
            Assert.AreEqual("PostHelp", _nodeCollection[6].Content.Name);
            Assert.That(_nodeCollection[6].Children, Is.Null.Or.Empty);
        }
コード例 #13
0
 public void MergeShouldThrowWhenNull()
 {
     MergeAlgorithm<NamedObject> mergeAlgorithm = new MergeAlgorithm<NamedObject>();
     Assert.Throws<ArgumentNullException>(() => mergeAlgorithm.Merge(null, _emptyNodeCollection));
     Assert.Throws<ArgumentNullException>(() => mergeAlgorithm.Merge(_emptyNodeCollection, null));
 }
コード例 #14
0
        public void MergeShouldThrowWhenContentIsNull()
        {
            var nodeCollection = new MergeableNodeCollection<NamedObject>();
            nodeCollection.AddRange(new[]
            {
                new MergeableNode<NamedObject>(),
            });

            MergeAlgorithm<NamedObject> mergeAlgorithm = new MergeAlgorithm<NamedObject>();
            Assert.Throws<NotSupportedException>(() => mergeAlgorithm.Merge(_emptyNodeCollection, nodeCollection));
        }