From 1bb9d428b08a1742d85281d675fa49fff396751f Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Sun, 10 May 2015 11:53:40 +0200 Subject: Drop optional parameters in ObjectDatabase.cs --- LibGit2Sharp/ObjectDatabase.cs | 79 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 71 insertions(+), 8 deletions(-) diff --git a/LibGit2Sharp/ObjectDatabase.cs b/LibGit2Sharp/ObjectDatabase.cs index 5ec2729d..73bd5e9b 100644 --- a/LibGit2Sharp/ObjectDatabase.cs +++ b/LibGit2Sharp/ObjectDatabase.cs @@ -75,7 +75,7 @@ namespace LibGit2Sharp /// /// Retrieves the header of a GitObject from the object database. The header contains the Size /// and Type of the object. Note that most backends do not support reading only the header - /// of an object, so the whole object will be read and then size would be returned. + /// of an object, so the whole object will be read and then size would be returned. /// /// Object Id of the queried object /// GitObjectMetadata object instance containg object header information @@ -177,6 +177,29 @@ namespace LibGit2Sharp } } + /// + /// Inserts a into the object database, created from the content of a stream. + /// Optionally, git filters will be applied to the content before storing it. + /// + /// The stream from which will be read the content of the blob to be created. + /// The created . + public virtual Blob CreateBlob(Stream stream) + { + return CreateBlob(stream, null, null); + } + + /// + /// Inserts a into the object database, created from the content of a stream. + /// Optionally, git filters will be applied to the content before storing it. + /// + /// The stream from which will be read the content of the blob to be created. + /// The hintpath is used to determine what git filters should be applied to the object before it can be placed to the object database. + /// The created . + public virtual Blob CreateBlob(Stream stream, string hintpath) + { + return CreateBlob(stream, hintpath, null); + } + /// /// Inserts a into the object database, created from the content of a stream. /// Optionally, git filters will be applied to the content before storing it. @@ -185,7 +208,12 @@ namespace LibGit2Sharp /// The hintpath is used to determine what git filters should be applied to the object before it can be placed to the object database. /// The number of bytes to consume from the stream. /// The created . - public virtual Blob CreateBlob(Stream stream, string hintpath = null, int? numberOfBytesToConsume = null) + public virtual Blob CreateBlob(Stream stream, string hintpath, int numberOfBytesToConsume) + { + return CreateBlob(stream, hintpath, (int?)numberOfBytesToConsume); + } + + internal Blob CreateBlob(Stream stream, string hintpath, int? numberOfBytesToConsume) { Ensure.ArgumentNotNull(stream, "stream"); @@ -295,9 +323,32 @@ namespace LibGit2Sharp /// The of the to be created. /// The parents of the to be created. /// True to prettify the message, or false to leave it as is. - /// Character that lines start with to be stripped if prettifyMessage is true. /// The created . - public virtual Commit CreateCommit(Signature author, Signature committer, string message, Tree tree, IEnumerable parents, bool prettifyMessage, char? commentChar = null) + public virtual Commit CreateCommit(Signature author, Signature committer, string message, Tree tree, IEnumerable parents, bool prettifyMessage) + { + return CreateCommit(author, committer, message, tree, parents, prettifyMessage, null); + } + + /// + /// Inserts a into the object database, referencing an existing . + /// + /// Prettifing the message includes: + /// * Removing empty lines from the beginning and end. + /// * Removing trailing spaces from every line. + /// * Turning multiple consecutive empty lines between paragraphs into just one empty line. + /// * Ensuring the commit message ends with a newline. + /// * Removing every line starting with the . + /// + /// + /// The of who made the change. + /// The of who added the change to the repository. + /// The description of why a change was made to the repository. + /// The of the to be created. + /// The parents of the to be created. + /// True to prettify the message, or false to leave it as is. + /// When non null, lines starting with this character will be stripped if prettifyMessage is true. + /// The created . + public virtual Commit CreateCommit(Signature author, Signature committer, string message, Tree tree, IEnumerable parents, bool prettifyMessage, char? commentChar) { Ensure.ArgumentNotNull(message, "message"); Ensure.ArgumentDoesNotContainZeroByte(message, "message"); @@ -382,6 +433,18 @@ namespace LibGit2Sharp return new HistoryDivergence(repo, one, another); } + /// + /// Calculates the current shortest abbreviated + /// string representation for a . + /// + /// The which identifier should be shortened. + /// A short string representation of the . + public virtual string ShortenObjectId(GitObject gitObject) + { + var shortSha = Proxy.git_object_short_id(repo.Handle, gitObject.Id); + return shortSha; + } + /// /// Calculates the current shortest abbreviated /// string representation for a . @@ -389,9 +452,9 @@ namespace LibGit2Sharp /// The which identifier should be shortened. /// Minimum length of the shortened representation. /// A short string representation of the . - public virtual string ShortenObjectId(GitObject gitObject, int? minLength = null) + public virtual string ShortenObjectId(GitObject gitObject, int minLength) { - if (minLength.HasValue && (minLength <= 0 || minLength > ObjectId.HexSize)) + if (minLength <= 0 || minLength > ObjectId.HexSize) { throw new ArgumentOutOfRangeException("minLength", minLength, string.Format("Expected value should be greater than zero and less than or equal to {0}.", ObjectId.HexSize)); @@ -399,12 +462,12 @@ namespace LibGit2Sharp string shortSha = Proxy.git_object_short_id(repo.Handle, gitObject.Id); - if (minLength == null || (minLength <= shortSha.Length)) + if (minLength <= shortSha.Length) { return shortSha; } - return gitObject.Sha.Substring(0, minLength.Value); + return gitObject.Sha.Substring(0, minLength); } /// -- cgit v1.2.3