Пример #1
0
 /// <summary>
 /// Adds an entry in the <see cref="Index"/> from a <see cref="Blob"/>.
 /// <para>
 ///   If an entry with the same path already exists in the <see cref="Index"/>,
 ///   the newly added one will overwrite it.
 /// </para>
 /// </summary>
 /// <param name="blob">The <see cref="Blob"/> which content should be added to the <see cref="Index"/>.</param>
 /// <param name="indexEntryPath">The path to be used in the <see cref="Index"/>.</param>
 /// <param name="indexEntryMode">Either <see cref="Mode.NonExecutableFile"/>, <see cref="Mode.ExecutableFile"/>
 /// or <see cref="Mode.SymbolicLink"/>.</param>
 public virtual void Add(Blob blob, string indexEntryPath, Mode indexEntryMode)
 {
     Ensure.ArgumentConformsTo(indexEntryMode, m => m.HasAny(TreeEntryDefinition.BlobModes), "indexEntryMode");
     Ensure.ArgumentNotNull(blob, "blob");
     Ensure.ArgumentNotNull(indexEntryPath, "indexEntryPath");
     AddEntryToTheIndex(indexEntryPath, blob.Id, indexEntryMode);
 }
Пример #2
0
        /// <summary>
        /// Adds the provided backend to the object database with the specified priority.
        /// <para>
        /// If the provided backend implements <see cref="IDisposable"/>, the <see cref="IDisposable.Dispose"/>
        /// method will be honored and invoked upon the disposal of the repository.
        /// </para>
        /// </summary>
        /// <param name="backend">The backend to add</param>
        /// <param name="priority">The priority at which libgit2 should consult this backend (higher values are consulted first)</param>
        public virtual void AddBackend(OdbBackend backend, int priority)
        {
            Ensure.ArgumentNotNull(backend, "backend");
            Ensure.ArgumentConformsTo(priority, s => s > 0, "priority");

            Proxy.git_odb_add_backend(handle, backend.GitOdbBackendPointer, priority);
        }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ObjectId"/> class.
 /// </summary>
 /// <param name="rawId">The byte array.</param>
 public ObjectId(byte[] rawId)
     : this(new GitOid {
     Id = rawId
 })
 {
     Ensure.ArgumentNotNull(rawId, "rawId");
     Ensure.ArgumentConformsTo(rawId, b => b.Length == rawSize, "rawId");
 }
Пример #4
0
        internal Reference UpdateHeadTarget(Reference target, string logMessage)
        {
            Ensure.ArgumentConformsTo(target, r => (r is DirectReference || r is SymbolicReference), "target");

            Add("HEAD", target, logMessage, true);

            return(repo.Refs.Head);
        }
Пример #5
0
        /// <summary>
        /// Creates a new logging configuration to call the given
        /// delegate when logging occurs at the given level.
        /// </summary>
        /// <param name="level">Level to log at</param>
        /// <param name="handler">Handler to call when logging occurs</param>
        public LogConfiguration(LogLevel level, LogHandler handler)
        {
            Ensure.ArgumentConformsTo <LogLevel>(level, (t) => { return(level != LogLevel.None); }, "level");
            Ensure.ArgumentNotNull(handler, "handler");

            Level   = level;
            Handler = handler;
        }
Пример #6
0
        /// <summary>
        ///   Adds or replaces a <see cref="TreeEntryDefinition"/>, dynamically built from the provided <see cref="Blob"/>, at the specified <paramref name="targetTreeEntryPath"/> location.
        /// </summary>
        /// <param name="targetTreeEntryPath">The path within this <see cref="TreeDefinition"/>.</param>
        /// <param name="blob">The <see cref="Blob"/> to be stored at the described location.</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, Blob blob, Mode mode)
        {
            Ensure.ArgumentNotNull(blob, "blob");
            Ensure.ArgumentConformsTo(mode, m => m.HasAny(TreeEntryDefinition.BlobModes), "mode");

            TreeEntryDefinition ted = TreeEntryDefinition.From(blob, mode);

            return(Add(targetTreeEntryPath, ted));
        }
Пример #7
0
        private GitObject RetreiveTreeEntryTarget()
        {
            GitObject treeEntryTarget = repo.Lookup(targetOid);

            //TODO: Warning submodules will appear as targets of type Commit
            Ensure.ArgumentConformsTo(treeEntryTarget.GetType(), t => typeof(Blob).IsAssignableFrom(t) || typeof(Tree).IsAssignableFrom(t), "treeEntryTarget");

            return(treeEntryTarget);
        }
Пример #8
0
        internal static TreeEntryDefinition TransientBlobFrom(string filePath, Mode mode)
        {
            Ensure.ArgumentConformsTo(mode, m => m.HasAny(BlobModes), "mode");

            return(new TransientBlobTreeEntryDefinition
            {
                Builder = odb => odb.CreateBlob(filePath),
                Mode = mode,
            });
        }
Пример #9
0
        internal static TreeEntryDefinition TransientBlobFrom(string filePath, Mode mode)
        {
            Ensure.ArgumentConformsTo(mode, m => m.HasAny(new[] { Mode.NonExecutableFile, Mode.ExecutableFile, Mode.NonExecutableGroupWriteableFile }), "mode");

            return(new TransientBlobTreeEntryDefinition
            {
                Builder = odb => odb.CreateBlob(filePath),
                Mode = mode,
            });
        }
Пример #10
0
        /// <summary>
        ///   Adds or replaces a <see cref="TreeEntryDefinition"/>, dynamically built from the provided <see cref="Blob"/>, at the specified <paramref name="targetTreeEntryPath"/> location.
        /// </summary>
        /// <param name="targetTreeEntryPath">The path within this <see cref="TreeDefinition"/>.</param>
        /// <param name="blob">The <see cref="Blob"/> to be stored at the described location.</param>
        /// <param name="mode">The file related <see cref="Mode"/> attributes.</param>
        /// <returns>The current <see cref="TreeDefinition"/>.</returns>
        public TreeDefinition Add(string targetTreeEntryPath, Blob blob, Mode mode)
        {
            Ensure.ArgumentNotNull(blob, "blob");
            Ensure.ArgumentConformsTo(mode,
                                      m => m.HasAny(new[] { Mode.ExecutableFile, Mode.NonExecutableFile, Mode.NonExecutableGroupWriteableFile }), "mode");

            TreeEntryDefinition ted = TreeEntryDefinition.From(blob, mode);

            return(Add(targetTreeEntryPath, ted));
        }
Пример #11
0
        /// <summary>
        /// Creates a new logging configuration to call the given
        /// delegate when logging occurs at the given level.
        /// </summary>
        /// <param name="level">Level to log at</param>
        /// <param name="handler">Handler to call when logging occurs</param>
        public LogConfiguration(LogLevel level, LogHandler handler)
        {
            Ensure.ArgumentConformsTo <LogLevel>(level, (t) => { return(level != LogLevel.None); }, "level");
            Ensure.ArgumentNotNull(handler, "handler");

            Level   = level;
            Handler = handler;

            // Explicitly create (and hold a reference to) a callback-delegate to wrap GitTraceHandler().
            GitTraceCallback = GitTraceHandler;
        }
Пример #12
0
        /// <summary>
        /// Adds an entry in the <see cref="Index"/> from a <see cref="Blob"/>.
        /// <para>
        ///   If an entry with the same path already exists in the <see cref="Index"/>,
        ///   the newly added one will overwrite it.
        /// </para>
        /// </summary>
        /// <param name="blob">The <see cref="Blob"/> which content should be added to the <see cref="Index"/>.</param>
        /// <param name="indexEntryPath">The path to be used in the <see cref="Index"/>.</param>
        /// <param name="indexEntryMode">Either <see cref="Mode.NonExecutableFile"/>, <see cref="Mode.ExecutableFile"/>
        /// or <see cref="Mode.SymbolicLink"/>.</param>
        public virtual void Add(Blob blob, string indexEntryPath, Mode indexEntryMode)
        {
            Ensure.ArgumentConformsTo(indexEntryMode, m => m.HasAny(TreeEntryDefinition.BlobModes), "indexEntryMode");

            if (blob == null)
            {
                throw new ArgumentNullException("blob");
            }

            if (indexEntryPath == null)
            {
                throw new ArgumentNullException("indexEntryPath");
            }

            AddEntryToTheIndex(indexEntryPath, blob.Id, indexEntryMode);

            UpdatePhysicalIndex();
        }
Пример #13
0
        private static string Shorten(string tagName)
        {
            Ensure.ArgumentConformsTo(tagName, s => s.StartsWith("refs/tags/", StringComparison.Ordinal), "tagName");

            return(tagName.Substring("refs/tags/".Length));
        }
Пример #14
0
        /// <summary>
        ///   Returns the friendly shortened name from a canonical name.
        /// </summary>
        /// <param name="canonicalName">The canonical name to shorten.</param>
        /// <returns></returns>
        protected override string Shorten(string canonicalName)
        {
            Ensure.ArgumentConformsTo(canonicalName, s => s.StartsWith("refs/tags/", StringComparison.Ordinal), "tagName");

            return(canonicalName.Substring("refs/tags/".Length));
        }