/// <exception cref="System.IO.IOException"></exception> private ObjectId InsertTree(Tree tree) { ObjectInserter oi = db.NewObjectInserter(); try { ObjectId id = oi.Insert(Constants.OBJ_TREE, tree.Format()); oi.Flush(); return(id); } finally { oi.Release(); } }
/// <summary>Construct and write tree out of index.</summary> /// <remarks>Construct and write tree out of index.</remarks> /// <returns>SHA-1 of the constructed tree</returns> /// <exception cref="System.IO.IOException">System.IO.IOException</exception> public virtual ObjectId WriteTree() { CheckWriteOk(); ObjectInserter inserter = db.NewObjectInserter(); try { Tree current = new Tree(db); Stack <Tree> trees = new Stack <Tree>(); trees.Push(current); string[] prevName = new string[0]; foreach (GitIndex.Entry e in entries.Values) { if (e.GetStage() != 0) { continue; } string[] newName = SplitDirPath(e.GetName()); int c = LongestCommonPath(prevName, newName); while (c < trees.Count - 1) { current.SetId(inserter.Insert(Constants.OBJ_TREE, current.Format())); trees.Pop(); current = trees.IsEmpty() ? null : (Tree)trees.Peek(); } while (trees.Count < newName.Length) { if (!current.ExistsTree(newName[trees.Count - 1])) { current = new Tree(current, Constants.Encode(newName[trees.Count - 1])); current.GetParent().AddEntry(current); trees.Push(current); } else { current = (Tree)current.FindTreeMember(newName[trees.Count - 1]); trees.Push(current); } } FileTreeEntry ne = new FileTreeEntry(current, e.sha1, Constants.Encode(newName[newName .Length - 1]), (e.mode & FileMode.EXECUTABLE_FILE.GetBits()) == FileMode.EXECUTABLE_FILE .GetBits()); current.AddEntry(ne); } while (!trees.IsEmpty()) { current.SetId(inserter.Insert(Constants.OBJ_TREE, current.Format())); trees.Pop(); if (!trees.IsEmpty()) { current = trees.Peek(); } } inserter.Flush(); return(current.GetId()); } finally { inserter.Release(); } }
/// <exception cref="System.IO.IOException"></exception> private ObjectId InsertTree(Tree tree) { ObjectInserter oi = db.NewObjectInserter(); try { ObjectId id = oi.Insert(Constants.OBJ_TREE, tree.Format()); oi.Flush(); return id; } finally { oi.Release(); } }
public virtual void TestEmptyTreeCorruption() { ObjectId bId = ObjectId.FromString("abbbfafe3129f85747aba7bfac992af77134c607"); RevTree tree_root; RevTree tree_A; RevTree tree_AB; RevCommit b; { Tree root = new Tree(db); Tree A = root.AddTree("A"); FileTreeEntry B = root.AddFile("B"); B.SetId(bId); Tree A_A = A.AddTree("A"); Tree A_B = A.AddTree("B"); ObjectInserter inserter = db.NewObjectInserter(); try { A_A.SetId(inserter.Insert(Constants.OBJ_TREE, A_A.Format())); A_B.SetId(inserter.Insert(Constants.OBJ_TREE, A_B.Format())); A.SetId(inserter.Insert(Constants.OBJ_TREE, A.Format())); root.SetId(inserter.Insert(Constants.OBJ_TREE, root.Format())); inserter.Flush(); } finally { inserter.Release(); } tree_root = rw.ParseTree(root.GetId()); tree_A = rw.ParseTree(A.GetId()); tree_AB = rw.ParseTree(A_A.GetId()); NUnit.Framework.Assert.AreSame(tree_AB, rw.ParseTree(A_B.GetId())); b = Commit(rw.ParseTree(root.GetId())); } MarkStart(b); AssertCommit(b, objw.Next()); NUnit.Framework.Assert.IsNull(objw.Next()); NUnit.Framework.Assert.AreSame(tree_root, objw.NextObject()); NUnit.Framework.Assert.AreSame(tree_A, objw.NextObject()); NUnit.Framework.Assert.AreSame(tree_AB, objw.NextObject()); NUnit.Framework.Assert.AreSame(rw.LookupBlob(bId), objw.NextObject()); NUnit.Framework.Assert.IsNull(objw.NextObject()); }
/// <exception cref="System.IO.IOException"></exception> public override void EndVisitTree(Tree t) { base.EndVisitTree(t); try { t.SetId(inserter.Insert(Constants.OBJ_TREE, t.Format())); inserter.Flush(); } finally { inserter.Release(); } }
public virtual void TestMissingSubtree_DetectFileAdded_FileModified() { ObjectInserter inserter = db.NewObjectInserter(); ObjectId aFileId = inserter.Insert(Constants.OBJ_BLOB, Constants.Encode("a")); ObjectId bFileId = inserter.Insert(Constants.OBJ_BLOB, Constants.Encode("b")); ObjectId cFileId1 = inserter.Insert(Constants.OBJ_BLOB, Constants.Encode("c-1")); ObjectId cFileId2 = inserter.Insert(Constants.OBJ_BLOB, Constants.Encode("c-2")); // Create sub-a/empty, sub-c/empty = hello. ObjectId oldTree; { Tree root = new Tree(db); { Tree subA = root.AddTree("sub-a"); subA.AddFile("empty").SetId(aFileId); subA.SetId(inserter.Insert(Constants.OBJ_TREE, subA.Format())); } { Tree subC = root.AddTree("sub-c"); subC.AddFile("empty").SetId(cFileId1); subC.SetId(inserter.Insert(Constants.OBJ_TREE, subC.Format())); } oldTree = inserter.Insert(Constants.OBJ_TREE, root.Format()); } // Create sub-a/empty, sub-b/empty, sub-c/empty. ObjectId newTree; { Tree root = new Tree(db); { Tree subA = root.AddTree("sub-a"); subA.AddFile("empty").SetId(aFileId); subA.SetId(inserter.Insert(Constants.OBJ_TREE, subA.Format())); } { Tree subB = root.AddTree("sub-b"); subB.AddFile("empty").SetId(bFileId); subB.SetId(inserter.Insert(Constants.OBJ_TREE, subB.Format())); } { Tree subC = root.AddTree("sub-c"); subC.AddFile("empty").SetId(cFileId2); subC.SetId(inserter.Insert(Constants.OBJ_TREE, subC.Format())); } newTree = inserter.Insert(Constants.OBJ_TREE, root.Format()); } inserter.Flush(); inserter.Release(); TreeWalk tw = new TreeWalk(db); tw.Reset(oldTree, newTree); tw.Recursive = true; tw.Filter = TreeFilter.ANY_DIFF; NUnit.Framework.Assert.IsTrue(tw.Next()); NUnit.Framework.Assert.AreEqual("sub-b/empty", tw.PathString); NUnit.Framework.Assert.AreEqual(FileMode.MISSING, tw.GetFileMode(0)); NUnit.Framework.Assert.AreEqual(FileMode.REGULAR_FILE, tw.GetFileMode(1)); NUnit.Framework.Assert.AreEqual(ObjectId.ZeroId, tw.GetObjectId(0)); NUnit.Framework.Assert.AreEqual(bFileId, tw.GetObjectId(1)); NUnit.Framework.Assert.IsTrue(tw.Next()); NUnit.Framework.Assert.AreEqual("sub-c/empty", tw.PathString); NUnit.Framework.Assert.AreEqual(FileMode.REGULAR_FILE, tw.GetFileMode(0)); NUnit.Framework.Assert.AreEqual(FileMode.REGULAR_FILE, tw.GetFileMode(1)); NUnit.Framework.Assert.AreEqual(cFileId1, tw.GetObjectId(0)); NUnit.Framework.Assert.AreEqual(cFileId2, tw.GetObjectId(1)); NUnit.Framework.Assert.IsFalse(tw.Next()); }