GitSharp.Core.ObjectWriter.WriteTree C# (CSharp) Method

WriteTree() public method

public WriteTree ( Tree t ) : ObjectId
t Tree
return ObjectId
        public ObjectId WriteTree(Tree t)
        {
            var output = new MemoryStream();
            var writer = new BinaryWriter(output);
            foreach (TreeEntry entry in t.Members)
            {
                ObjectId id = entry.Id;
                if (id == null)
                {
                    throw new ObjectWritingException("object at path \"" + entry.FullName +
                                                     "\" does not have an id assigned.  All object ids must be assigned prior to writing a tree.");
                }
                entry.Mode.CopyTo(output);
                writer.Write((byte) 0x20);
                writer.Write(entry.NameUTF8);
                writer.Write((byte) 0);
                id.copyRawTo(output);
            }
            return WriteCanonicalTree(output.ToArray());
        }

Same methods

ObjectWriter::WriteTree ( long len, Stream input ) : ObjectId

Usage Example

コード例 #1
0
        ///	<summary>
        /// Construct and write tree out of index.
        ///	</summary>
        ///	<returns> SHA-1 of the constructed tree</returns>
        /// <exception cref="IOException"></exception>
        public ObjectId writeTree()
        {
            CheckWriteOk();
            var writer  = new ObjectWriter(Repository);
            var current = new Tree(Repository);
            var trees   = new Stack <Tree>();

            trees.Push(current);
            var prevName = new string[0];

            foreach (Entry e in _entries.Values)
            {
                if (e.Stage != STAGE_0)
                {
                    continue;
                }

                string[] newName = SplitDirPath(e.Name);
                int      c       = LongestCommonPath(prevName, newName);
                while (c < trees.Count - 1)
                {
                    current.Id = writer.WriteTree(current);
                    trees.Pop();
                    current = trees.Count == 0 ? null : 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.Parent.AddEntry(current);
                        trees.Push(current);
                    }
                    else
                    {
                        current = (Tree)current.findTreeMember(newName[trees.Count - 1]);
                        trees.Push(current);
                    }
                }

                var ne = new FileTreeEntry(current, e.ObjectId, Constants.encode(newName[newName.Length - 1]),
                                           (e.Mode & FileMode.ExecutableFile.Bits) == FileMode.ExecutableFile.Bits);
                current.AddEntry(ne);
            }

            while (trees.Count != 0)
            {
                current.Id = writer.WriteTree(current);
                trees.Pop();

                if (trees.Count != 0)
                {
                    current = trees.Peek();
                }
            }

            return(current.TreeId);
        }
All Usage Examples Of GitSharp.Core.ObjectWriter::WriteTree