/// <summary>Write (if necessary) this tree to the object store.</summary>
 /// <remarks>Write (if necessary) this tree to the object store.</remarks>
 /// <param name="cache">the complete cache from DirCache.</param>
 /// <param name="cIdx">
 /// first position of <code>cache</code> that is a member of this
 /// tree. The path of <code>cache[cacheIdx].path</code> for the
 /// range <code>[0,pathOff-1)</code> matches the complete path of
 /// this tree, from the root of the repository.
 /// </param>
 /// <param name="pathOffset">
 /// number of bytes of <code>cache[cacheIdx].path</code> that
 /// matches this tree's path. The value at array position
 /// <code>cache[cacheIdx].path[pathOff-1]</code> is always '/' if
 /// <code>pathOff</code> is &gt; 0.
 /// </param>
 /// <param name="ow">the writer to use when serializing to the store.</param>
 /// <returns>identity of this tree.</returns>
 /// <exception cref="NGit.Errors.UnmergedPathException">
 /// one or more paths contain higher-order stages (stage &gt; 0),
 /// which cannot be stored in a tree object.
 /// </exception>
 /// <exception cref="System.IO.IOException">an unexpected error occurred writing to the object store.
 ///     </exception>
 internal virtual ObjectId WriteTree(DirCacheEntry[] cache, int cIdx, int pathOffset
                                     , ObjectInserter ow)
 {
     if (id == null)
     {
         int           endIdx   = cIdx + entrySpan;
         TreeFormatter fmt      = new TreeFormatter(ComputeSize(cache, cIdx, pathOffset, ow));
         int           childIdx = 0;
         int           entryIdx = cIdx;
         while (entryIdx < endIdx)
         {
             DirCacheEntry e  = cache[entryIdx];
             byte[]        ep = e.path;
             if (childIdx < childCnt)
             {
                 NGit.Dircache.DirCacheTree st = children[childIdx];
                 if (st.Contains(ep, pathOffset, ep.Length))
                 {
                     fmt.Append(st.encodedName, FileMode.TREE, st.id);
                     entryIdx += st.entrySpan;
                     childIdx++;
                     continue;
                 }
             }
             fmt.Append(ep, pathOffset, ep.Length - pathOffset, e.FileMode, e.IdBuffer, e.IdOffset
                        );
             entryIdx++;
         }
         id = ow.Insert(fmt);
     }
     return(id);
 }
        private TreeFormatter Build()
        {
            byte[]        nameBuf = new byte[Constants.OBJECT_ID_STRING_LENGTH];
            int           nameLen = Constants.OBJECT_ID_STRING_LENGTH - prefixLen;
            TreeFormatter fmt     = new TreeFormatter(TreeSize(nameLen));
            NonNoteEntry  e       = nonNotes;

            for (int i = 0; i < cnt; i++)
            {
                Note n = notes[i];
                n.CopyTo(nameBuf, 0);
                while (e != null && e.PathCompare(nameBuf, prefixLen, nameLen, FileMode.REGULAR_FILE
                                                  ) < 0)
                {
                    e.Format(fmt);
                    e = e.next;
                }
                fmt.Append(nameBuf, prefixLen, nameLen, FileMode.REGULAR_FILE, n.GetData());
            }
            for (; e != null; e = e.next)
            {
                e.Format(fmt);
            }
            return(fmt);
        }
Esempio n. 3
0
        /// <exception cref="System.IO.IOException"></exception>
        private TreeFormatter Build(bool insert, ObjectInserter inserter)
        {
            byte[]        nameBuf = new byte[2];
            TreeFormatter fmt     = new TreeFormatter(TreeSize());
            NonNoteEntry  e       = nonNotes;

            for (int cell = 0; cell < 256; cell++)
            {
                NoteBucket b = table[cell];
                if (b == null)
                {
                    continue;
                }
                nameBuf[0] = hexchar[(int)(((uint)cell) >> 4)];
                nameBuf[1] = hexchar[cell & unchecked ((int)(0x0f))];
                while (e != null && e.PathCompare(nameBuf, 0, 2, FileMode.TREE) < 0)
                {
                    e.Format(fmt);
                    e = e.next;
                }
                ObjectId id;
                if (insert)
                {
                    id = b.WriteTree(inserter);
                }
                else
                {
                    id = b.GetTreeId();
                }
                fmt.Append(nameBuf, 0, 2, FileMode.TREE, id);
            }
            for (; e != null; e = e.next)
            {
                e.Format(fmt);
            }
            return(fmt);
        }
Esempio n. 4
0
 internal virtual void Format(TreeFormatter fmt)
 {
     fmt.Append(name, mode, this);
 }
Esempio n. 5
0
        public virtual void Test026_CreateCommitMultipleparents()
        {
            ObjectId       treeId;
            ObjectInserter oi = db.NewObjectInserter();

            try
            {
                ObjectId blobId = oi.Insert(Constants.OBJ_BLOB, Sharpen.Runtime.GetBytesForString
                                                ("and this is the data in me\n", Constants.CHARSET.Name()));
                TreeFormatter fmt = new TreeFormatter();
                fmt.Append("i-am-a-file", FileMode.REGULAR_FILE, blobId);
                treeId = oi.Insert(fmt);
                oi.Flush();
            }
            finally
            {
                oi.Release();
            }
            NUnit.Framework.Assert.AreEqual(ObjectId.FromString("00b1f73724f493096d1ffa0b0f1f1482dbb8c936"
                                                                ), treeId);
            NGit.CommitBuilder c1 = new NGit.CommitBuilder();
            c1.Author    = new PersonIdent(author, 1154236443000L, -4 * 60);
            c1.Committer = new PersonIdent(committer, 1154236443000L, -4 * 60);
            c1.Message   = "A Commit\n";
            c1.TreeId    = treeId;
            NUnit.Framework.Assert.AreEqual(treeId, c1.TreeId);
            ObjectId actid1 = InsertCommit(c1);
            ObjectId cmtid1 = ObjectId.FromString("803aec4aba175e8ab1d666873c984c0308179099");

            NUnit.Framework.Assert.AreEqual(cmtid1, actid1);
            NGit.CommitBuilder c2 = new NGit.CommitBuilder();
            c2.Author    = new PersonIdent(author, 1154236443000L, -4 * 60);
            c2.Committer = new PersonIdent(committer, 1154236443000L, -4 * 60);
            c2.Message   = "A Commit 2\n";
            c2.TreeId    = treeId;
            NUnit.Framework.Assert.AreEqual(treeId, c2.TreeId);
            c2.SetParentIds(actid1);
            ObjectId actid2 = InsertCommit(c2);
            ObjectId cmtid2 = ObjectId.FromString("95d068687c91c5c044fb8c77c5154d5247901553");

            NUnit.Framework.Assert.AreEqual(cmtid2, actid2);
            RevCommit rm2 = ParseCommit(cmtid2);

            NUnit.Framework.Assert.AreNotSame(c2, rm2);
            // assert the parsed objects is not from the
            // cache
            NUnit.Framework.Assert.AreEqual(c2.Author, rm2.GetAuthorIdent());
            NUnit.Framework.Assert.AreEqual(actid2, rm2.Id);
            NUnit.Framework.Assert.AreEqual(c2.Message, rm2.GetFullMessage());
            NUnit.Framework.Assert.AreEqual(c2.TreeId, rm2.Tree.Id);
            NUnit.Framework.Assert.AreEqual(1, rm2.ParentCount);
            NUnit.Framework.Assert.AreEqual(actid1, rm2.GetParent(0));
            NGit.CommitBuilder c3 = new NGit.CommitBuilder();
            c3.Author    = new PersonIdent(author, 1154236443000L, -4 * 60);
            c3.Committer = new PersonIdent(committer, 1154236443000L, -4 * 60);
            c3.Message   = "A Commit 3\n";
            c3.TreeId    = treeId;
            NUnit.Framework.Assert.AreEqual(treeId, c3.TreeId);
            c3.SetParentIds(actid1, actid2);
            ObjectId actid3 = InsertCommit(c3);
            ObjectId cmtid3 = ObjectId.FromString("ce6e1ce48fbeeb15a83f628dc8dc2debefa066f4");

            NUnit.Framework.Assert.AreEqual(cmtid3, actid3);
            RevCommit rm3 = ParseCommit(cmtid3);

            NUnit.Framework.Assert.AreNotSame(c3, rm3);
            // assert the parsed objects is not from the
            // cache
            NUnit.Framework.Assert.AreEqual(c3.Author, rm3.GetAuthorIdent());
            NUnit.Framework.Assert.AreEqual(actid3, rm3.Id);
            NUnit.Framework.Assert.AreEqual(c3.Message, rm3.GetFullMessage());
            NUnit.Framework.Assert.AreEqual(c3.TreeId, rm3.Tree.Id);
            NUnit.Framework.Assert.AreEqual(2, rm3.ParentCount);
            NUnit.Framework.Assert.AreEqual(actid1, rm3.GetParent(0));
            NUnit.Framework.Assert.AreEqual(actid2, rm3.GetParent(1));
            NGit.CommitBuilder c4 = new NGit.CommitBuilder();
            c4.Author    = new PersonIdent(author, 1154236443000L, -4 * 60);
            c4.Committer = new PersonIdent(committer, 1154236443000L, -4 * 60);
            c4.Message   = "A Commit 4\n";
            c4.TreeId    = treeId;
            NUnit.Framework.Assert.AreEqual(treeId, c3.TreeId);
            c4.SetParentIds(actid1, actid2, actid3);
            ObjectId actid4 = InsertCommit(c4);
            ObjectId cmtid4 = ObjectId.FromString("d1fca9fe3fef54e5212eb67902c8ed3e79736e27");

            NUnit.Framework.Assert.AreEqual(cmtid4, actid4);
            RevCommit rm4 = ParseCommit(cmtid4);

            NUnit.Framework.Assert.AreNotSame(c4, rm3);
            // assert the parsed objects is not from the
            // cache
            NUnit.Framework.Assert.AreEqual(c4.Author, rm4.GetAuthorIdent());
            NUnit.Framework.Assert.AreEqual(actid4, rm4.Id);
            NUnit.Framework.Assert.AreEqual(c4.Message, rm4.GetFullMessage());
            NUnit.Framework.Assert.AreEqual(c4.TreeId, rm4.Tree.Id);
            NUnit.Framework.Assert.AreEqual(3, rm4.ParentCount);
            NUnit.Framework.Assert.AreEqual(actid1, rm4.GetParent(0));
            NUnit.Framework.Assert.AreEqual(actid2, rm4.GetParent(1));
            NUnit.Framework.Assert.AreEqual(actid3, rm4.GetParent(2));
        }