Beispiel #1
0
        public void testMerge_WithPrefix()
        {
            global::GitSharp.Core.Ref a = newRef("refs/heads/A", ID_ONE);
            global::GitSharp.Core.Ref b = newRef("refs/heads/foo/bar/B", ID_TWO);
            global::GitSharp.Core.Ref c = newRef("refs/heads/foo/rab/C", ID_TWO);
            global::GitSharp.Core.Ref g = newRef("refs/heads/g", ID_ONE);
            packed = toList(a, b, c, g);

            RefMap map = new RefMap("refs/heads/foo/", packed, loose, resolved);

            Assert.AreEqual(2, map.size());

            Assert.AreSame(b, map.get("bar/B"));
            Assert.AreSame(c, map.get("rab/C"));
            Assert.IsNull(map.get("refs/heads/foo/bar/B"));
            Assert.IsNull(map.get("refs/heads/A"));

            Assert.IsTrue(map.containsKey("bar/B"));
            Assert.IsTrue(map.containsKey("rab/C"));
            Assert.IsFalse(map.containsKey("refs/heads/foo/bar/B"));
            Assert.IsFalse(map.containsKey("refs/heads/A"));

            IteratorBase <RefMap.Ent> itr = map.entrySet().iterator();

            RefMap.Ent ent;
            Assert.IsTrue(itr.hasNext());
            ent = itr.next();
            Assert.AreEqual("bar/B", ent.getKey());
            Assert.AreSame(b, ent.getValue());
            Assert.IsTrue(itr.hasNext());
            ent = itr.next();
            Assert.AreEqual("rab/C", ent.getKey());
            Assert.AreSame(c, ent.getValue());
            Assert.IsFalse(itr.hasNext());
        }
        private void buttonSearch_Click(object sender, EventArgs e)
        {
            Console.WriteLine("search button click");
            TypeBookNo   bno   = new TypeBookNo(int.Parse(textBoxBookNo.Text));
            TypeBookName bname = new TypeBookName(textBoxBookName.Text);
            //TypeRentalState rental = new TypeRentalState(TypeRentalState.RentalState.NoRental);

            //パラメータ設定
            ParamList param = new ParamBooksSearch();

            param.SetParam(bno);
            param.SetParam(bname);
            //param.SetParam(rental);

            //検索実行
            ServiceInterface srv = new ServiceBooksSearch(param);

            srv.Run();

            //検索結果の取り出し
            TypeBookAggregate books = (TypeBookAggregate)param.GetParam(DataType.BookAggregate);
            AggregateBase     agb   = books.BookAggregate();
            IteratorBase      ite   = agb.Iterator();

            if (ite.HasNext())
            {
                DataListBookInfo info = (DataListBookInfo)ite.Next();
                //  Console.WriteLine(info.BookName());
            }
        }
Beispiel #3
0
        public void testMerge_HeadMaster()
        {
            global::GitSharp.Core.Ref master = newRef("refs/heads/master", ID_ONE);
            global::GitSharp.Core.Ref headU  = newRef("HEAD", "refs/heads/master");
            global::GitSharp.Core.Ref headR  = newRef("HEAD", master);

            loose    = toList(headU, master);
            resolved = toList(headR);

            RefMap map = new RefMap("", packed, loose, resolved);

            Assert.AreEqual(2, map.size());
            Assert.IsFalse(map.isEmpty());
            Assert.IsTrue(map.containsKey("refs/heads/master"));
            Assert.AreSame(master, map.get("refs/heads/master"));

            // resolved overrides loose given same name
            Assert.AreSame(headR, map.get("HEAD"));

            IteratorBase <global::GitSharp.Core.Ref> itr = map.values().iterator();

            Assert.IsTrue(itr.hasNext());
            Assert.AreSame(headR, itr.next());
            Assert.IsTrue(itr.hasNext());
            Assert.AreSame(master, itr.next());
            Assert.IsFalse(itr.hasNext());
        }
Beispiel #4
0
        public void testEntryType()
        {
            global::GitSharp.Core.Ref a = newRef("refs/heads/A", ID_ONE);
            global::GitSharp.Core.Ref b = newRef("refs/heads/B", ID_TWO);

            packed = toList(a, b);

            RefMap map = new RefMap("refs/heads/", packed, loose, resolved);
            IteratorBase <RefMap.Ent> itr = map.entrySet().iterator();

            RefMap.Ent ent_a = itr.next();
            RefMap.Ent ent_b = itr.next();

            Assert.AreEqual(ent_a.GetHashCode(), "A".GetHashCode());
            Assert.IsTrue(ent_a.Equals(ent_a));
            Assert.IsFalse(ent_a.Equals(ent_b));

            Assert.AreEqual(a.ToString(), ent_a.ToString());
        }
Beispiel #5
0
            public void CreateIterator(IServiceProvider serviceProvider)
            {
                if (_findTarget != null)
                {
                    Iterator = new SingleTargetIterator(_findTarget);
                }
                else
                {
                    switch (Options & NiFindOptions.TargetMask)
                    {
                    case NiFindOptions.OpenDocument: Iterator = new OpenDocumentIterator(this, serviceProvider); break;

                    case NiFindOptions.Project: Iterator = new ProjectIterator(this, serviceProvider); break;

                    case NiFindOptions.Files: Iterator = new FilesIterator(this, serviceProvider); break;

                    default: Iterator = new DocumentIterator(this, serviceProvider); break;
                    }
                }
            }
Beispiel #6
0
        public void testIterator_FailsAtEnd()
        {
            global::GitSharp.Core.Ref master = newRef("refs/heads/master", ID_ONE);
            loose = toList(master);

            RefMap map = new RefMap("", packed, loose, resolved);
            IteratorBase <global::GitSharp.Core.Ref> itr = map.values().iterator();

            Assert.IsTrue(itr.hasNext());
            Assert.AreSame(master, itr.next());
            try
            {
                itr.next();
                Assert.Fail("iterator allowed next");
            }
            catch (IndexOutOfRangeException)
            {
                // expected
            }
        }
Beispiel #7
0
        public void testIterator_RefusesRemove()
        {
            global::GitSharp.Core.Ref master = newRef("refs/heads/master", ID_ONE);
            loose = toList(master);

            RefMap map = new RefMap("", packed, loose, resolved);
            IteratorBase <global::GitSharp.Core.Ref> itr = map.values().iterator();

            Assert.IsTrue(itr.hasNext());
            Assert.AreSame(master, itr.next());
            try
            {
                itr.remove();
                Assert.Fail("iterator allowed remove");
            }
            catch (NotSupportedException)
            {
                // expected
            }
        }
Beispiel #8
0
        public void testIterator_MissingUnresolvedSymbolicRefIsBug()
        {
            global::GitSharp.Core.Ref master = newRef("refs/heads/master", ID_ONE);
            global::GitSharp.Core.Ref headR  = newRef("HEAD", master);

            loose = toList(master);
            // loose should have added newRef("HEAD", "refs/heads/master")
            resolved = toList(headR);

            var map = new RefMap("", packed, loose, resolved);
            IteratorBase <global::GitSharp.Core.Ref> itr = map.values().iterator();

            try
            {
                itr.hasNext();
                Assert.Fail("iterator did not catch bad input");
            }
            catch (InvalidOperationException)
            {
                // expected
            }
        }
Beispiel #9
0
 /// <summary>
 /// Helper method which returns the next Edit for an Iterator over Edits.
 /// When there are no more edits left this method will return the constant
 /// END_EDIT.
 /// </summary>
 /// <param name="it">the iterator for which the next edit should be returned</param>
 /// <returns>the next edit from the iterator or END_EDIT if there no more edits</returns>
 private static Edit nextEdit(IteratorBase<Edit> it)
 {
     return (it.hasNext() ? it.next() : END_EDIT);
 }
        /// <summary>
        /// Does the three way merge between a common base and two sequences.
        /// </summary>
        /// <param name="base">base the common base sequence</param>
        /// <param name="ours">ours the first sequence to be merged</param>
        /// <param name="theirs">theirs the second sequence to be merged</param>
        /// <returns>the resulting content</returns>
        public static MergeResult merge(Sequence @base, Sequence ours,
                                        Sequence theirs)
        {
            List <Sequence> sequences = new List <Sequence>(3);

            sequences.Add(@base);
            sequences.Add(ours);
            sequences.Add(theirs);
            MergeResult         result       = new MergeResult(sequences);
            EditList            oursEdits    = new MyersDiff(@base, ours).getEdits();
            IteratorBase <Edit> baseToOurs   = oursEdits.iterator();
            EditList            theirsEdits  = new MyersDiff(@base, theirs).getEdits();
            IteratorBase <Edit> baseToTheirs = theirsEdits.iterator();
            int current = 0; // points to the next line (first line is 0) of base
            // which was not handled yet
            Edit oursEdit   = nextEdit(baseToOurs);
            Edit theirsEdit = nextEdit(baseToTheirs);

            // iterate over all edits from base to ours and from base to theirs
            // leave the loop when there are no edits more for ours or for theirs
            // (or both)
            while (theirsEdit != END_EDIT || oursEdit != END_EDIT)
            {
                if (oursEdit.EndA <= theirsEdit.BeginA)
                {
                    // something was changed in ours not overlapping with any change
                    // from theirs. First add the common part in front of the edit
                    // then the edit.
                    if (current != oursEdit.BeginA)
                    {
                        result.add(0, current, oursEdit.BeginA,
                                   MergeChunk.ConflictState.NO_CONFLICT);
                    }
                    result.add(1, oursEdit.BeginB, oursEdit.EndB,
                               MergeChunk.ConflictState.NO_CONFLICT);
                    current  = oursEdit.EndA;
                    oursEdit = nextEdit(baseToOurs);
                }
                else if (theirsEdit.EndA <= oursEdit.BeginA)
                {
                    // something was changed in theirs not overlapping with any
                    // from ours. First add the common part in front of the edit
                    // then the edit.
                    if (current != theirsEdit.BeginA)
                    {
                        result.add(0, current, theirsEdit.BeginA,
                                   MergeChunk.ConflictState.NO_CONFLICT);
                    }
                    result.add(2, theirsEdit.BeginB, theirsEdit.EndB,
                               MergeChunk.ConflictState.NO_CONFLICT);
                    current    = theirsEdit.EndA;
                    theirsEdit = nextEdit(baseToTheirs);
                }
                else
                {
                    // here we found a real overlapping modification

                    // if there is a common part in front of the conflict add it
                    if (oursEdit.BeginA != current &&
                        theirsEdit.BeginA != current)
                    {
                        result.add(0, current, Math.Min(oursEdit.BeginA,
                                                        theirsEdit.BeginA), MergeChunk.ConflictState.NO_CONFLICT);
                    }

                    // set some initial values for the ranges in A and B which we
                    // want to handle
                    int oursBeginB   = oursEdit.BeginB;
                    int theirsBeginB = theirsEdit.BeginB;
                    // harmonize the start of the ranges in A and B
                    if (oursEdit.BeginA < theirsEdit.BeginA)
                    {
                        theirsBeginB -= theirsEdit.BeginA
                                        - oursEdit.BeginA;
                    }
                    else
                    {
                        oursBeginB -= oursEdit.BeginA - theirsEdit.BeginA;
                    }

                    // combine edits:
                    // Maybe an Edit on one side corresponds to multiple Edits on
                    // the other side. Then we have to combine the Edits of the
                    // other side - so in the end we can merge together two single
                    // edits.
                    //
                    // It is important to notice that this combining will extend the
                    // ranges of our conflict always downwards (towards the end of
                    // the content). The starts of the conflicting ranges in ours
                    // and theirs are not touched here.
                    //
                    // This combining is an iterative process: after we have
                    // combined some edits we have to do the check again. The
                    // combined edits could now correspond to multiple edits on the
                    // other side.
                    //
                    // Example: when this combining algorithm works on the following
                    // edits
                    // oursEdits=((0-5,0-5),(6-8,6-8),(10-11,10-11)) and
                    // theirsEdits=((0-1,0-1),(2-3,2-3),(5-7,5-7))
                    // it will merge them into
                    // oursEdits=((0-8,0-8),(10-11,10-11)) and
                    // theirsEdits=((0-7,0-7))
                    //
                    // Since the only interesting thing to us is how in ours and
                    // theirs the end of the conflicting range is changing we let
                    // oursEdit and theirsEdit point to the last conflicting edit
                    Edit nextOursEdit   = nextEdit(baseToOurs);
                    Edit nextTheirsEdit = nextEdit(baseToTheirs);
                    for (; ;)
                    {
                        if (oursEdit.EndA > nextTheirsEdit.BeginA)
                        {
                            theirsEdit     = nextTheirsEdit;
                            nextTheirsEdit = nextEdit(baseToTheirs);
                        }
                        else if (theirsEdit.EndA > nextOursEdit.BeginA)
                        {
                            oursEdit     = nextOursEdit;
                            nextOursEdit = nextEdit(baseToOurs);
                        }
                        else
                        {
                            break;
                        }
                    }

                    // harmonize the end of the ranges in A and B
                    int oursEndB   = oursEdit.EndB;
                    int theirsEndB = theirsEdit.EndB;
                    if (oursEdit.EndA < theirsEdit.EndA)
                    {
                        oursEndB += theirsEdit.EndA - oursEdit.EndA;
                    }
                    else
                    {
                        theirsEndB += oursEdit.EndA - theirsEdit.EndA;
                    }

                    // Add the conflict
                    result.add(1, oursBeginB, oursEndB,
                               MergeChunk.ConflictState.FIRST_CONFLICTING_RANGE);
                    result.add(2, theirsBeginB, theirsEndB,
                               MergeChunk.ConflictState.NEXT_CONFLICTING_RANGE);

                    current    = Math.Max(oursEdit.EndA, theirsEdit.EndA);
                    oursEdit   = nextOursEdit;
                    theirsEdit = nextTheirsEdit;
                }
            }
            // maybe we have a common part behind the last edit: copy it to the
            // result
            if (current < @base.size())
            {
                result.add(0, current, @base.size(), MergeChunk.ConflictState.NO_CONFLICT);
            }
            return(result);
        }
 /// <summary>
 /// Helper method which returns the next Edit for an Iterator over Edits.
 /// When there are no more edits left this method will return the constant
 /// END_EDIT.
 /// </summary>
 /// <param name="it">the iterator for which the next edit should be returned</param>
 /// <returns>the next edit from the iterator or END_EDIT if there no more edits</returns>
 private static Edit nextEdit(IteratorBase <Edit> it)
 {
     return(it.hasNext() ? it.next() : END_EDIT);
 }