/// <summary>Construct a new note map from an existing note bucket.</summary>
 /// <remarks>Construct a new note map from an existing note bucket.</remarks>
 /// <param name="root">the root bucket of this note map</param>
 /// <param name="reader">
 /// reader to scan the note branch with. This reader may be
 /// retained by the NoteMap for the life of the map in order to
 /// support lazy loading of entries.
 /// </param>
 /// <returns>the note map built from the note bucket</returns>
 internal static NGit.Notes.NoteMap NewMap(InMemoryNoteBucket root, ObjectReader reader
                                           )
 {
     NGit.Notes.NoteMap map = new NGit.Notes.NoteMap(reader);
     map.root = root;
     return(map);
 }
示例#2
0
        public virtual void TestNonNotesWithNonNoteConflict()
        {
            NoteMapMerger merger           = new NoteMapMerger(db, null, MergeStrategy.RESOLVE);
            RevCommit     treeWithNonNotes = tr.Commit().Add(noteAId.Name, noteABlob).Add("a.txt"
                                                                                          , tr.Blob("content of a.txt")).Create();

            // this is a note
            // this is a non-note
            tr.ParseBody(treeWithNonNotes);
            NoteMap @base = NoteMap.Read(reader, treeWithNonNotes);

            treeWithNonNotes = tr.Commit().Add(noteAId.Name, noteABlob).Add("a.txt", tr.Blob(
                                                                                "change 1")).Create();
            tr.ParseBody(treeWithNonNotes);
            NoteMap ours = NoteMap.Read(reader, treeWithNonNotes);

            treeWithNonNotes = tr.Commit().Add(noteAId.Name, noteABlob).Add("a.txt", tr.Blob(
                                                                                "change 2")).Create();
            tr.ParseBody(treeWithNonNotes);
            NoteMap theirs = NoteMap.Read(reader, treeWithNonNotes);

            try
            {
                merger.Merge(@base, ours, theirs);
                NUnit.Framework.Assert.Fail("NotesMergeConflictException was expected");
            }
            catch (NotesMergeConflictException)
            {
            }
        }
 /// <exception cref="System.IO.IOException"></exception>
 private RevCommit CommitNoteMap(NoteMap map)
 {
     tr.Tick(600);
     NGit.CommitBuilder builder = new NGit.CommitBuilder();
     builder.TreeId = map.WriteTree(inserter);
     tr.SetAuthorAndCommitter(builder);
     return(tr.GetRevWalk().ParseCommit(inserter.Insert(builder)));
 }
示例#4
0
        public virtual void TestFanoutAndLeafWithoutConflict()
        {
            NoteMapMerger merger    = new NoteMapMerger(db, null, null);
            NoteMap       largeTree = CreateLargeNoteMap("note_1_", "content_1_", 300, 0);
            NoteMap       result    = merger.Merge(map_a, map_a_b, largeTree);

            NUnit.Framework.Assert.AreEqual(301, CountNotes(result));
        }
示例#5
0
        public virtual void TestDeleteDifferentNotes()
        {
            NoteMapMerger merger = new NoteMapMerger(db, null, null);
            NoteMap       map_b  = NoteMap.Read(reader, sampleTree_a_b);

            map_b.Set(noteAId, null);
            // delete note a
            map_b.WriteTree(inserter);
            NUnit.Framework.Assert.AreEqual(0, CountNotes(merger.Merge(map_a_b, map_a, map_b)
                                                          ));
        }
示例#6
0
        private static int CountNonNotes(NoteMap map)
        {
            int          c        = 0;
            NonNoteEntry nonNotes = map.GetRoot().nonNotes;

            while (nonNotes != null)
            {
                c++;
                nonNotes = nonNotes.next;
            }
            return(c);
        }
示例#7
0
        // expected
        private static int CountNotes(NoteMap map)
        {
            int             c  = 0;
            Iterator <Note> it = map.Iterator();

            while (it.HasNext())
            {
                it.Next();
                c++;
            }
            return(c);
        }
        /// <exception cref="System.Exception"></exception>
        public virtual void TestShorteningNoteRefName()
        {
            string expectedShortName = "review";
            string noteRefName       = Constants.R_NOTES + expectedShortName;

            NUnit.Framework.Assert.AreEqual(expectedShortName, NoteMap.ShortenRefName(noteRefName
                                                                                      ));
            string nonNoteRefName = Constants.R_HEADS + expectedShortName;

            NUnit.Framework.Assert.AreEqual(nonNoteRefName, NoteMap.ShortenRefName(expectedShortName
                                                                                   ));
        }
示例#9
0
        /// <exception cref="System.Exception"></exception>
        private NoteMap CreateLargeNoteMap(string noteNamePrefix, string noteContentPrefix
                                           , int notesCount, int firstIndex)
        {
            NoteMap result = NoteMap.NewEmptyMap();

            for (int i = 0; i < notesCount; i++)
            {
                result.Set(tr.Blob(noteNamePrefix + (firstIndex + i)), tr.Blob(noteContentPrefix
                                                                               + (firstIndex + i)));
            }
            result.WriteTree(inserter);
            return(result);
        }
示例#10
0
        public virtual void TestFanoutAndLeafWitConflict()
        {
            NoteMapMerger merger        = new NoteMapMerger(db, new DefaultNoteMerger(), null);
            NoteMap       largeTree_b1  = CreateLargeNoteMap("note_1_", "content_1_", 300, 0);
            string        noteBContent1 = noteBContent + "change";

            largeTree_b1.Set(noteBId, tr.Blob(noteBContent1));
            largeTree_b1.WriteTree(inserter);
            NoteMap result = merger.Merge(map_a, map_a_b, largeTree_b1);

            NUnit.Framework.Assert.AreEqual(301, CountNotes(result));
            NUnit.Framework.Assert.AreEqual(tr.Blob(noteBContent + noteBContent1), result.Get
                                                (noteBId));
        }
示例#11
0
 /// <summary>Performs the merge.</summary>
 /// <remarks>Performs the merge.</remarks>
 /// <param name="base">base version of the note tree</param>
 /// <param name="ours">ours version of the note tree</param>
 /// <param name="theirs">theirs version of the note tree</param>
 /// <returns>merge result as a new NoteMap</returns>
 /// <exception cref="System.IO.IOException">System.IO.IOException</exception>
 public virtual NoteMap Merge(NoteMap @base, NoteMap ours, NoteMap theirs)
 {
     try
     {
         InMemoryNoteBucket mergedBucket = Merge(0, @base.GetRoot(), ours.GetRoot(), theirs
                                                 .GetRoot());
         inserter.Flush();
         return(NoteMap.NewMap(mergedBucket, reader));
     }
     finally
     {
         reader.Release();
         inserter.Release();
     }
 }
示例#12
0
        public virtual void TestCollapseFanoutAfterMerge()
        {
            NoteMapMerger merger    = new NoteMapMerger(db, null, null);
            NoteMap       largeTree = CreateLargeNoteMap("note_", "content_", 257, 0);

            NUnit.Framework.Assert.IsTrue(largeTree.GetRoot() is FanoutBucket);
            NoteMap deleteFirstHundredNotes = CreateLargeNoteMap("note_", "content_", 157, 100
                                                                 );
            NoteMap deleteLastHundredNotes = CreateLargeNoteMap("note_", "content_", 157, 0);
            NoteMap result = merger.Merge(largeTree, deleteFirstHundredNotes, deleteLastHundredNotes
                                          );

            NUnit.Framework.Assert.AreEqual(57, CountNotes(result));
            NUnit.Framework.Assert.IsTrue(result.GetRoot() is LeafBucket);
        }
示例#13
0
        public virtual void TestEditDeleteConflict()
        {
            NoteMapMerger merger = new NoteMapMerger(db, new DefaultNoteMerger(), null);
            NoteMap       result;
            NoteMap       map_a_b1      = NoteMap.Read(reader, sampleTree_a_b);
            string        noteBContent1 = noteBContent + "change";
            RevBlob       noteBBlob1    = tr.Blob(noteBContent1);

            map_a_b1.Set(noteBId, noteBBlob1);
            map_a_b1.WriteTree(inserter);
            result = merger.Merge(map_a_b, map_a_b1, map_a);
            NUnit.Framework.Assert.AreEqual(2, CountNotes(result));
            NUnit.Framework.Assert.AreEqual(noteABlob, result.Get(noteAId));
            NUnit.Framework.Assert.AreEqual(noteBBlob1, result.Get(noteBId));
        }
示例#14
0
        public virtual void TestLargeTreesWithConflict()
        {
            NoteMapMerger merger     = new NoteMapMerger(db, new DefaultNoteMerger(), null);
            NoteMap       largeTree1 = CreateLargeNoteMap("note_1_", "content_1_", 300, 0);
            NoteMap       largeTree2 = CreateLargeNoteMap("note_1_", "content_2_", 300, 0);
            NoteMap       result     = merger.Merge(empty, largeTree1, largeTree2);

            NUnit.Framework.Assert.AreEqual(300, CountNotes(result));
            // check a few random notes
            NUnit.Framework.Assert.AreEqual(tr.Blob("content_1_59content_2_59"), result.Get(tr
                                                                                            .Blob("note_1_59")));
            NUnit.Framework.Assert.AreEqual(tr.Blob("content_1_10content_2_10"), result.Get(tr
                                                                                            .Blob("note_1_10")));
            NUnit.Framework.Assert.AreEqual(tr.Blob("content_1_99content_2_99"), result.Get(tr
                                                                                            .Blob("note_1_99")));
        }
示例#15
0
        public virtual void TestLargeTreesWithoutConflict()
        {
            NoteMapMerger merger = new NoteMapMerger(db, null, null);
            NoteMap       map1   = CreateLargeNoteMap("note_1_", "content_1_", 300, 0);
            NoteMap       map2   = CreateLargeNoteMap("note_2_", "content_2_", 300, 0);
            NoteMap       result = merger.Merge(empty, map1, map2);

            NUnit.Framework.Assert.AreEqual(600, CountNotes(result));
            // check a few random notes
            NUnit.Framework.Assert.AreEqual(tr.Blob("content_1_59"), result.Get(tr.Blob("note_1_59"
                                                                                        )));
            NUnit.Framework.Assert.AreEqual(tr.Blob("content_2_10"), result.Get(tr.Blob("note_2_10"
                                                                                        )));
            NUnit.Framework.Assert.AreEqual(tr.Blob("content_2_99"), result.Get(tr.Blob("note_2_99"
                                                                                        )));
        }
        public virtual void TestGetCachedBytes()
        {
            string    exp  = "this is test data";
            RevBlob   a    = tr.Blob("a");
            RevBlob   data = tr.Blob(exp);
            RevCommit r    = tr.Commit().Add(a.Name, data).Create();

            //
            //
            tr.ParseBody(r);
            NoteMap map = NoteMap.Read(reader, r);

            byte[] act = map.GetCachedBytes(a, exp.Length * 4);
            NUnit.Framework.Assert.IsNotNull(act, "has data for a");
            NUnit.Framework.Assert.AreEqual(exp, RawParseUtils.Decode(act));
        }
示例#17
0
        public virtual void TestAddDifferentNotes()
        {
            NoteMapMerger merger = new NoteMapMerger(db, null, null);
            NoteMap       result;
            NoteMap       map_a_c   = NoteMap.Read(reader, sampleTree_a);
            RevBlob       noteCId   = tr.Blob("c");
            RevBlob       noteCBlob = tr.Blob("noteCContent");

            map_a_c.Set(noteCId, noteCBlob);
            map_a_c.WriteTree(inserter);
            result = merger.Merge(map_a, map_a_b, map_a_c);
            NUnit.Framework.Assert.AreEqual(3, CountNotes(result));
            NUnit.Framework.Assert.AreEqual(noteABlob, result.Get(noteAId));
            NUnit.Framework.Assert.AreEqual(noteBBlob, result.Get(noteBId));
            NUnit.Framework.Assert.AreEqual(noteCBlob, result.Get(noteCId));
        }
        public virtual void TestEditFlat()
        {
            RevBlob   a     = tr.Blob("a");
            RevBlob   b     = tr.Blob("b");
            RevBlob   data1 = tr.Blob("data1");
            RevBlob   data2 = tr.Blob("data2");
            RevCommit r     = tr.Commit().Add(a.Name, data1).Add(b.Name, data2).Add(".gitignore",
                                                                                    string.Empty).Add("zoo-animals.txt", b).Create();

            //
            //
            //
            //
            //
            tr.ParseBody(r);
            NoteMap map = NoteMap.Read(reader, r);

            map.Set(a, data2);
            map.Set(b, null);
            map.Set(data1, b);
            map.Set(data2, null);
            NUnit.Framework.Assert.AreEqual(data2, map.Get(a));
            NUnit.Framework.Assert.AreEqual(b, map.Get(data1));
            NUnit.Framework.Assert.IsFalse(map.Contains(b), "no b");
            NUnit.Framework.Assert.IsFalse(map.Contains(data2), "no data2");
            MutableObjectId id = new MutableObjectId();

            for (int p = 42; p > 0; p--)
            {
                id.SetByte(1, p);
                map.Set(id, data1);
            }
            for (int p_1 = 42; p_1 > 0; p_1--)
            {
                id.SetByte(1, p_1);
                NUnit.Framework.Assert.IsTrue(map.Contains(id), "contains " + id);
            }
            RevCommit n = CommitNoteMap(map);

            map = NoteMap.Read(reader, n);
            NUnit.Framework.Assert.AreEqual(data2, map.Get(a));
            NUnit.Framework.Assert.AreEqual(b, map.Get(data1));
            NUnit.Framework.Assert.IsFalse(map.Contains(b), "no b");
            NUnit.Framework.Assert.IsFalse(map.Contains(data2), "no data2");
            NUnit.Framework.Assert.AreEqual(b, TreeWalk.ForPath(reader, "zoo-animals.txt", n.
                                                                Tree).GetObjectId(0));
        }
        public virtual void TestRemoveDeletesTreeFanout2_38()
        {
            RevBlob   a     = tr.Blob("a");
            RevBlob   data1 = tr.Blob("data1");
            RevTree   empty = tr.Tree();
            RevCommit r     = tr.Commit().Add(Fanout(2, a.Name), data1).Create();

            //
            //
            tr.ParseBody(r);
            NoteMap map = NoteMap.Read(reader, r);

            map.Set(a, null);
            RevCommit n = CommitNoteMap(map);

            NUnit.Framework.Assert.AreEqual(empty, n.Tree, "empty tree");
        }
        /// <exception cref="System.Exception"></exception>
        public virtual void TestIteratorFullyFannedOut()
        {
            RevBlob   a       = tr.Blob("a");
            RevBlob   b       = tr.Blob("b");
            RevBlob   data1   = tr.Blob("data1");
            RevBlob   data2   = tr.Blob("data2");
            RevBlob   nonNote = tr.Blob("non note");
            RevCommit r       = tr.Commit().Add(Fanout(38, a.Name), data1).Add(Fanout(38, b.Name),
                                                                               data2).Add("nonNote", nonNote).Create();

            //
            //
            //
            //
            tr.ParseBody(r);
            Iterator it = NoteMap.Read(reader, r).Iterator();

            NUnit.Framework.Assert.AreEqual(2, Count(it));
        }
        public virtual void TestLeafSplitsWhenFull()
        {
            RevBlob         data1 = tr.Blob("data1");
            MutableObjectId idBuf = new MutableObjectId();
            RevCommit       r     = tr.Commit().Add(data1.Name, data1).Create();

            //
            //
            tr.ParseBody(r);
            NoteMap map = NoteMap.Read(reader, r);

            for (int i = 0; i < 254; i++)
            {
                idBuf.SetByte(Constants.OBJECT_ID_LENGTH - 1, i);
                map.Set(idBuf, data1);
            }
            RevCommit n  = CommitNoteMap(map);
            TreeWalk  tw = new TreeWalk(reader);

            tw.Reset(n.Tree);
            while (tw.Next())
            {
                NUnit.Framework.Assert.IsFalse(tw.IsSubtree, "no fan-out subtree");
            }
            for (int i_1 = 254; i_1 < 256; i_1++)
            {
                idBuf.SetByte(Constants.OBJECT_ID_LENGTH - 1, i_1);
                map.Set(idBuf, data1);
            }
            idBuf.SetByte(Constants.OBJECT_ID_LENGTH - 2, 1);
            map.Set(idBuf, data1);
            n = CommitNoteMap(map);
            // The 00 bucket is fully split.
            string path = Fanout(38, idBuf.Name);

            tw = TreeWalk.ForPath(reader, path, n.Tree);
            NUnit.Framework.Assert.IsNotNull(tw, "has " + path);
            // The other bucket is not.
            path = Fanout(2, data1.Name);
            tw   = TreeWalk.ForPath(reader, path, n.Tree);
            NUnit.Framework.Assert.IsNotNull(tw, "has " + path);
        }
示例#22
0
        public virtual void TestEditSameNoteDifferentContent()
        {
            NoteMapMerger merger = new NoteMapMerger(db, new DefaultNoteMerger(), null);
            NoteMap       result;
            NoteMap       map_a1        = NoteMap.Read(reader, sampleTree_a);
            string        noteAContent1 = noteAContent + "change1";
            RevBlob       noteABlob1    = tr.Blob(noteAContent1);

            map_a1.Set(noteAId, noteABlob1);
            map_a1.WriteTree(inserter);
            NoteMap map_a2        = NoteMap.Read(reader, sampleTree_a);
            string  noteAContent2 = noteAContent + "change2";
            RevBlob noteABlob2    = tr.Blob(noteAContent2);

            map_a2.Set(noteAId, noteABlob2);
            map_a2.WriteTree(inserter);
            result = merger.Merge(map_a, map_a1, map_a2);
            NUnit.Framework.Assert.AreEqual(1, CountNotes(result));
            NUnit.Framework.Assert.AreEqual(tr.Blob(noteAContent1 + noteAContent2), result.Get
                                                (noteAId));
        }
示例#23
0
 public override void SetUp()
 {
     base.SetUp();
     tr           = new TestRepository <Repository>(db);
     reader       = db.NewObjectReader();
     inserter     = db.NewObjectInserter();
     noRoot       = NoteMap.NewMap(null, reader);
     empty        = NoteMap.NewEmptyMap();
     noteAId      = tr.Blob("a");
     noteAContent = "noteAContent";
     noteABlob    = tr.Blob(noteAContent);
     sampleTree_a = tr.Commit().Add(noteAId.Name, noteABlob).Create();
     tr.ParseBody(sampleTree_a);
     map_a          = NoteMap.Read(reader, sampleTree_a);
     noteBId        = tr.Blob("b");
     noteBContent   = "noteBContent";
     noteBBlob      = tr.Blob(noteBContent);
     sampleTree_a_b = tr.Commit().Add(noteAId.Name, noteABlob).Add(noteBId.Name, noteBBlob
                                                                   ).Create();
     tr.ParseBody(sampleTree_a_b);
     map_a_b = NoteMap.Read(reader, sampleTree_a_b);
 }
        public virtual void TestReadFlatTwoNotes()
        {
            RevBlob   a     = tr.Blob("a");
            RevBlob   b     = tr.Blob("b");
            RevBlob   data1 = tr.Blob("data1");
            RevBlob   data2 = tr.Blob("data2");
            RevCommit r     = tr.Commit().Add(a.Name, data1).Add(b.Name, data2).Create();

            //
            //
            //
            tr.ParseBody(r);
            NoteMap map = NoteMap.Read(reader, r);

            NUnit.Framework.Assert.IsNotNull(map, "have map");
            NUnit.Framework.Assert.IsTrue(map.Contains(a), "has note for a");
            NUnit.Framework.Assert.IsTrue(map.Contains(b), "has note for b");
            NUnit.Framework.Assert.AreEqual(data1, map.Get(a));
            NUnit.Framework.Assert.AreEqual(data2, map.Get(b));
            NUnit.Framework.Assert.IsFalse(map.Contains(data1), "no note for data1");
            NUnit.Framework.Assert.IsNull(map.Get(data1), "no note for data1");
        }
        public virtual void TestEditFanout2_38()
        {
            RevBlob   a     = tr.Blob("a");
            RevBlob   b     = tr.Blob("b");
            RevBlob   data1 = tr.Blob("data1");
            RevBlob   data2 = tr.Blob("data2");
            RevCommit r     = tr.Commit().Add(Fanout(2, a.Name), data1).Add(Fanout(2, b.Name), data2
                                                                            ).Add(".gitignore", string.Empty).Add("zoo-animals.txt", b).Create();

            //
            //
            //
            //
            //
            tr.ParseBody(r);
            NoteMap map = NoteMap.Read(reader, r);

            map.Set(a, data2);
            map.Set(b, null);
            map.Set(data1, b);
            map.Set(data2, null);
            NUnit.Framework.Assert.AreEqual(data2, map.Get(a));
            NUnit.Framework.Assert.AreEqual(b, map.Get(data1));
            NUnit.Framework.Assert.IsFalse(map.Contains(b), "no b");
            NUnit.Framework.Assert.IsFalse(map.Contains(data2), "no data2");
            RevCommit n = CommitNoteMap(map);

            map.Set(a, null);
            map.Set(data1, null);
            NUnit.Framework.Assert.IsFalse(map.Contains(a), "no a");
            NUnit.Framework.Assert.IsFalse(map.Contains(data1), "no data1");
            map = NoteMap.Read(reader, n);
            NUnit.Framework.Assert.AreEqual(data2, map.Get(a));
            NUnit.Framework.Assert.AreEqual(b, map.Get(data1));
            NUnit.Framework.Assert.IsFalse(map.Contains(b), "no b");
            NUnit.Framework.Assert.IsFalse(map.Contains(data2), "no data2");
            NUnit.Framework.Assert.AreEqual(b, TreeWalk.ForPath(reader, "zoo-animals.txt", n.
                                                                Tree).GetObjectId(0));
        }
        public virtual void TestCreateFromEmpty()
        {
            RevBlob a     = tr.Blob("a");
            RevBlob b     = tr.Blob("b");
            RevBlob data1 = tr.Blob("data1");
            RevBlob data2 = tr.Blob("data2");
            NoteMap map   = NoteMap.NewEmptyMap();

            NUnit.Framework.Assert.IsFalse(map.Contains(a), "no a");
            NUnit.Framework.Assert.IsFalse(map.Contains(b), "no b");
            map.Set(a, data1);
            map.Set(b, data2);
            NUnit.Framework.Assert.AreEqual(data1, map.Get(a));
            NUnit.Framework.Assert.AreEqual(data2, map.Get(b));
            map.Remove(a);
            map.Remove(b);
            NUnit.Framework.Assert.IsFalse(map.Contains(a), "no a");
            NUnit.Framework.Assert.IsFalse(map.Contains(b), "no b");
            map.Set(a, "data1", inserter);
            NUnit.Framework.Assert.AreEqual(data1, map.Get(a));
            map.Set(a, null, inserter);
            NUnit.Framework.Assert.IsFalse(map.Contains(a), "no a");
        }
示例#27
0
        public virtual void TestNonNotesWithoutNonNoteConflict()
        {
            NoteMapMerger merger           = new NoteMapMerger(db, null, MergeStrategy.RESOLVE);
            RevCommit     treeWithNonNotes = tr.Commit().Add(noteAId.Name, noteABlob).Add("a.txt"
                                                                                          , tr.Blob("content of a.txt")).Create();

            // this is a note
            // this is a non-note
            tr.ParseBody(treeWithNonNotes);
            NoteMap @base = NoteMap.Read(reader, treeWithNonNotes);

            treeWithNonNotes = tr.Commit().Add(noteAId.Name, noteABlob).Add("a.txt", tr.Blob(
                                                                                "content of a.txt")).Add("b.txt", tr.Blob("content of b.txt")).Create();
            tr.ParseBody(treeWithNonNotes);
            NoteMap ours = NoteMap.Read(reader, treeWithNonNotes);

            treeWithNonNotes = tr.Commit().Add(noteAId.Name, noteABlob).Add("a.txt", tr.Blob(
                                                                                "content of a.txt")).Add("c.txt", tr.Blob("content of c.txt")).Create();
            tr.ParseBody(treeWithNonNotes);
            NoteMap theirs = NoteMap.Read(reader, treeWithNonNotes);
            NoteMap result = merger.Merge(@base, ours, theirs);

            NUnit.Framework.Assert.AreEqual(3, CountNonNotes(result));
        }
        public virtual void TestWriteUnchangedFlat()
        {
            RevBlob   a     = tr.Blob("a");
            RevBlob   b     = tr.Blob("b");
            RevBlob   data1 = tr.Blob("data1");
            RevBlob   data2 = tr.Blob("data2");
            RevCommit r     = tr.Commit().Add(a.Name, data1).Add(b.Name, data2).Add(".gitignore",
                                                                                    string.Empty).Add("zoo-animals.txt", string.Empty).Create();

            //
            //
            //
            //
            //
            tr.ParseBody(r);
            NoteMap map = NoteMap.Read(reader, r);

            NUnit.Framework.Assert.IsTrue(map.Contains(a), "has note for a");
            NUnit.Framework.Assert.IsTrue(map.Contains(b), "has note for b");
            RevCommit n = CommitNoteMap(map);

            NUnit.Framework.Assert.AreNotSame(r, n, "is new commit");
            NUnit.Framework.Assert.AreSame(r.Tree, n.Tree, "same tree");
        }
示例#29
0
		/// <summary>Load a collection of notes from a tree.</summary>
		/// <remarks>Load a collection of notes from a tree.</remarks>
		/// <param name="reader">
		/// reader to scan the note branch with. This reader may be
		/// retained by the NoteMap for the life of the map in order to
		/// support lazy loading of entries.
		/// </param>
		/// <param name="treeId">the note tree to read.</param>
		/// <returns>the note map read from the tree.</returns>
		/// <exception cref="System.IO.IOException">the repository cannot be accessed through the reader.
		/// 	</exception>
		/// <exception cref="NGit.Errors.CorruptObjectException">a tree object is corrupt and cannot be read.
		/// 	</exception>
		/// <exception cref="NGit.Errors.IncorrectObjectTypeException">a tree object wasn't actually a tree.
		/// 	</exception>
		/// <exception cref="NGit.Errors.MissingObjectException">a reference tree object doesn't exist.
		/// 	</exception>
		public static NGit.Notes.NoteMap ReadTree(ObjectReader reader, ObjectId treeId)
		{
			NGit.Notes.NoteMap map = new NGit.Notes.NoteMap(reader);
			map.Load(treeId);
			return map;
		}
示例#30
0
		// expected
		private static int CountNotes(NoteMap map)
		{
			int c = 0;
			Iterator<Note> it = map.Iterator();
			while (it.HasNext())
			{
				it.Next();
				c++;
			}
			return c;
		}
示例#31
0
		private static int CountNonNotes(NoteMap map)
		{
			int c = 0;
			NonNoteEntry nonNotes = map.GetRoot().nonNotes;
			while (nonNotes != null)
			{
				c++;
				nonNotes = nonNotes.next;
			}
			return c;
		}
        public virtual void TestIteratorEmptyMap()
        {
            Iterator <Note> it = NoteMap.NewEmptyMap().Iterator();

            NUnit.Framework.Assert.IsFalse(it.HasNext());
        }
示例#33
0
		public override void SetUp()
		{
			base.SetUp();
			tr = new TestRepository<Repository>(db);
			reader = db.NewObjectReader();
			inserter = db.NewObjectInserter();
			noRoot = NoteMap.NewMap(null, reader);
			empty = NoteMap.NewEmptyMap();
			noteAId = tr.Blob("a");
			noteAContent = "noteAContent";
			noteABlob = tr.Blob(noteAContent);
			sampleTree_a = tr.Commit().Add(noteAId.Name, noteABlob).Create();
			tr.ParseBody(sampleTree_a);
			map_a = NoteMap.Read(reader, sampleTree_a);
			noteBId = tr.Blob("b");
			noteBContent = "noteBContent";
			noteBBlob = tr.Blob(noteBContent);
			sampleTree_a_b = tr.Commit().Add(noteAId.Name, noteABlob).Add(noteBId.Name, noteBBlob
				).Create();
			tr.ParseBody(sampleTree_a_b);
			map_a_b = NoteMap.Read(reader, sampleTree_a_b);
		}
示例#34
0
		/// <summary>Construct a new empty note map.</summary>
		/// <remarks>Construct a new empty note map.</remarks>
		/// <returns>an empty note map.</returns>
		public static NGit.Notes.NoteMap NewEmptyMap()
		{
			NGit.Notes.NoteMap r = new NGit.Notes.NoteMap(null);
			r.root = new LeafBucket(0);
			return r;
		}
示例#35
0
		/// <exception cref="System.IO.IOException"></exception>
		private RevCommit CommitNoteMap(NoteMap map)
		{
			tr.Tick(600);
			NGit.CommitBuilder builder = new NGit.CommitBuilder();
			builder.TreeId = map.WriteTree(inserter);
			tr.SetAuthorAndCommitter(builder);
			return tr.GetRevWalk().ParseCommit(inserter.Insert(builder));
		}
示例#36
0
		/// <summary>Performs the merge.</summary>
		/// <remarks>Performs the merge.</remarks>
		/// <param name="base">base version of the note tree</param>
		/// <param name="ours">ours version of the note tree</param>
		/// <param name="theirs">theirs version of the note tree</param>
		/// <returns>merge result as a new NoteMap</returns>
		/// <exception cref="System.IO.IOException">System.IO.IOException</exception>
		public virtual NoteMap Merge(NoteMap @base, NoteMap ours, NoteMap theirs)
		{
			try
			{
				InMemoryNoteBucket mergedBucket = Merge(0, @base.GetRoot(), ours.GetRoot(), theirs
					.GetRoot());
				inserter.Flush();
				return NoteMap.NewMap(mergedBucket, reader);
			}
			finally
			{
				reader.Release();
				inserter.Release();
			}
		}
 /// <summary>Construct a new empty note map.</summary>
 /// <remarks>Construct a new empty note map.</remarks>
 /// <returns>an empty note map.</returns>
 public static NGit.Notes.NoteMap NewEmptyMap()
 {
     NGit.Notes.NoteMap r = new NGit.Notes.NoteMap(null);
     r.root = new LeafBucket(0);
     return(r);
 }