/// <summary> /// Adds or replaces a <see cref="TreeEntryDefinition"/>, dynamically built from the provided <see cref="Tree"/>, at the specified <paramref name="targetTreeEntryPath"/> location. /// </summary> /// <param name="targetTreeEntryPath">The path within this <see cref="TreeDefinition"/>.</param> /// <param name="tree">The <see cref="Tree"/> to be stored at the described location.</param> /// <returns>The current <see cref="TreeDefinition"/>.</returns> public virtual TreeDefinition Add(string targetTreeEntryPath, Tree tree) { Ensure.ArgumentNotNull(tree, "tree"); TreeEntryDefinition ted = TreeEntryDefinition.From(tree); return(Add(targetTreeEntryPath, ted)); }
/// <summary> /// Adds or replaces a gitlink <see cref="TreeEntryDefinition"/>, /// referencing the commit identified by <paramref name="objectId"/>, /// at the specified <paramref name="targetTreeEntryPath"/> location. /// </summary> /// <param name="targetTreeEntryPath">The path within this <see cref="TreeDefinition"/>.</param> /// <param name="objectId">The <see cref="ObjectId"/> of the commit to be linked at the described location.</param> /// <returns>The current <see cref="TreeDefinition"/>.</returns> public virtual TreeDefinition AddGitLink(string targetTreeEntryPath, ObjectId objectId) { Ensure.ArgumentNotNull(objectId, "objectId"); var ted = TreeEntryDefinition.From(objectId); return(Add(targetTreeEntryPath, ted)); }
/// <summary> /// Adds or replaces a <see cref="TreeEntryDefinition"/> from an existing blob specified by its Object ID at the specified <paramref name="targetTreeEntryPath"/> location. /// </summary> /// <param name="targetTreeEntryPath">The path within this <see cref="TreeDefinition"/>.</param> /// <param name="id">The object ID for this entry.</param> /// <param name="mode">The file related <see cref="Mode"/> attributes.</param> /// <returns>The current <see cref="TreeDefinition"/>.</returns> public virtual TreeDefinition Add(string targetTreeEntryPath, ObjectId id, Mode mode) { Ensure.ArgumentNotNull(id, "id"); Ensure.ArgumentConformsTo(mode, m => m.HasAny(TreeEntryDefinition.BlobModes), "mode"); TreeEntryDefinition ted = TreeEntryDefinition.From(id, mode); return(Add(targetTreeEntryPath, ted)); }
private void WrapAllTreeDefinitions(Repository repository) { foreach (KeyValuePair <string, TreeDefinition> pair in unwrappedTrees) { Tree tree = pair.Value.Build(repository); entries[pair.Key] = TreeEntryDefinition.From(tree); } unwrappedTrees.Clear(); }
internal Tree Build(Repository repository) { WrapAllTreeDefinitions(repository); using (var builder = new TreeBuilder(repository)) { var builtTreeEntryDefinitions = new List <Tuple <string, TreeEntryDefinition> >(entries.Count); foreach (KeyValuePair <string, TreeEntryDefinition> kvp in entries) { string name = kvp.Key; TreeEntryDefinition ted = kvp.Value; var transient = ted as TransientBlobTreeEntryDefinition; if (transient == null) { builder.Insert(name, ted); continue; } Blob blob = transient.Builder(repository.ObjectDatabase); TreeEntryDefinition ted2 = TreeEntryDefinition.From(blob, ted.Mode); builtTreeEntryDefinitions.Add(new Tuple <string, TreeEntryDefinition>(name, ted2)); builder.Insert(name, ted2); } builtTreeEntryDefinitions.ForEach(t => entries[t.Item1] = t.Item2); ObjectId treeId = builder.Write(); var result = repository.Lookup <Tree>(treeId); if (result == null) { throw new GitException("Unable to read created tree"); } return(result); } }