Example #1
0
        /// <summary>
        /// Adds or replaces a <see cref="TreeEntryDefinition"/> at the specified <paramref name="targetTreeEntryPath"/> location.
        /// </summary>
        /// <param name="targetTreeEntryPath">The path within this <see cref="TreeDefinition"/>.</param>
        /// <param name="treeEntryDefinition">The <see cref="TreeEntryDefinition"/> to be stored at the described location.</param>
        /// <returns>The current <see cref="TreeDefinition"/>.</returns>
        public virtual TreeDefinition Add(string targetTreeEntryPath, TreeEntryDefinition treeEntryDefinition)
        {
            Ensure.ArgumentNotNullOrEmptyString(targetTreeEntryPath, "targetTreeEntryPath");
            Ensure.ArgumentNotNull(treeEntryDefinition, "treeEntryDefinition");

            if (treeEntryDefinition is TransientTreeTreeEntryDefinition)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture,
                                                                  "The {0} references a target which hasn't been created in the {1} yet. " +
                                                                  "This situation can occur when the target is a whole new {2} being created, " +
                                                                  "or when an existing {2} is being updated because some of its children were added/removed.",
                                                                  typeof(TreeEntryDefinition).Name,
                                                                  typeof(ObjectDatabase).Name,
                                                                  typeof(Tree).Name));
            }

            Tuple <string, string> segments = ExtractPosixLeadingSegment(targetTreeEntryPath);

            if (segments.Item2 != null)
            {
                TreeDefinition td = RetrieveOrBuildTreeDefinition(segments.Item1, true);
                td.Add(segments.Item2, treeEntryDefinition);
            }
            else
            {
                AddEntry(segments.Item1, treeEntryDefinition);
            }

            return(this);
        }
Example #2
0
        /// <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));
        }
Example #3
0
        /// <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));
        }
Example #4
0
        /// <summary>
        /// Adds or replaces a <see cref="TreeEntryDefinition"/>, dynamically built from the content of the file, at the specified <paramref name="targetTreeEntryPath"/> location.
        /// </summary>
        /// <param name="targetTreeEntryPath">The path within this <see cref="TreeDefinition"/>.</param>
        /// <param name="filePath">The path to the file from which a <see cref="Blob"/> will be built and stored at the described location. A relative path is allowed to be passed if the target
        /// <see cref="Repository"/> is a standard, non-bare, repository. The path will then be considered as a path relative to the root of the working directory.</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, string filePath, Mode mode)
        {
            Ensure.ArgumentNotNullOrEmptyString(filePath, "filePath");

            TreeEntryDefinition ted = TreeEntryDefinition.TransientBlobFrom(filePath, mode);

            return(Add(targetTreeEntryPath, ted));
        }
Example #5
0
        /// <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));
        }
Example #6
0
        private void AddEntry(string targetTreeEntryName, TreeEntryDefinition treeEntryDefinition)
        {
            if (entries.ContainsKey(targetTreeEntryName))
            {
                WrapTree(targetTreeEntryName, treeEntryDefinition);
                return;
            }

            entries.Add(targetTreeEntryName, treeEntryDefinition);
        }
Example #7
0
        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();
        }
Example #8
0
        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);
            }
        }
Example #9
0
 public void Insert(string name, TreeEntryDefinition treeEntryDefinition)
 {
     Proxy.git_treebuilder_insert(handle, name, treeEntryDefinition);
 }
Example #10
0
 private void WrapTree(string entryName, TreeEntryDefinition treeEntryDefinition)
 {
     entries[entryName] = treeEntryDefinition;
     unwrappedTrees.Remove(entryName);
 }