/// <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(); } }
/// <summary>Look up an entry with the specified path.</summary> /// <remarks>Look up an entry with the specified path.</remarks> /// <param name="path"></param> /// <returns>index entry for the path or null if not in index.</returns> /// <exception cref="Sharpen.UnsupportedEncodingException">Sharpen.UnsupportedEncodingException /// </exception> public virtual GitIndex.Entry GetEntry(string path) { return(entries.Get(Repository.GitInternalSlash(Constants.Encode(path)))); }
/// <exception cref="System.IO.IOException"></exception> private TreeEntry FindMember(string s, byte slast) { return(FindMember(Repository.GitInternalSlash(Constants.Encode(s)), slast, 0)); }
/// <summary>Adds a new or existing Tree with the specified name to this tree.</summary> /// <remarks> /// Adds a new or existing Tree with the specified name to this tree. /// Trees are added if necessary as the name may contain '/':s. /// </remarks> /// <param name="name">Name</param> /// <returns> /// a /// <see cref="FileTreeEntry">FileTreeEntry</see> /// for the added tree. /// </returns> /// <exception cref="System.IO.IOException">System.IO.IOException</exception> public virtual NGit.Tree AddTree(string name) { return(AddTree(Repository.GitInternalSlash(Constants.Encode(name)), 0)); }
/// <summary>Adds a new or existing file with the specified name to this tree.</summary> /// <remarks> /// Adds a new or existing file with the specified name to this tree. /// Trees are added if necessary as the name may contain '/':s. /// </remarks> /// <param name="name">Name</param> /// <returns> /// a /// <see cref="FileTreeEntry">FileTreeEntry</see> /// for the added file. /// </returns> /// <exception cref="System.IO.IOException">System.IO.IOException</exception> public virtual FileTreeEntry AddFile(string name) { return(AddFile(Repository.GitInternalSlash(Constants.Encode(name)), 0)); }
/// <summary>Rename this entry.</summary> /// <remarks>Rename this entry.</remarks> /// <param name="n">The new name</param> /// <exception cref="System.IO.IOException">System.IO.IOException</exception> public virtual void Rename(string n) { Rename(Constants.Encode(n)); }
/// <summary>Append any entry to the tree.</summary> /// <remarks>Append any entry to the tree.</remarks> /// <param name="name">name of the entry.</param> /// <param name="mode"> /// mode describing the treatment of /// <code>id</code> /// . /// </param> /// <param name="id">the ObjectId to store in this entry.</param> public virtual void Append(string name, FileMode mode, AnyObjectId id) { Append(Constants.Encode(name), mode, id); }