Skip to content

Commit 51c2ddc

Browse files
shiftkeynulltoken
authored andcommitted
Drop optional parameters in ObjectDatabase.cs
1 parent 5b729dc commit 51c2ddc

File tree

1 file changed

+71
-8
lines changed

1 file changed

+71
-8
lines changed

LibGit2Sharp/ObjectDatabase.cs

Lines changed: 71 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public virtual bool Contains(ObjectId objectId)
7575
/// <summary>
7676
/// Retrieves the header of a GitObject from the object database. The header contains the Size
7777
/// and Type of the object. Note that most backends do not support reading only the header
78-
/// of an object, so the whole object will be read and then size would be returned.
78+
/// of an object, so the whole object will be read and then size would be returned.
7979
/// </summary>
8080
/// <param name="objectId">Object Id of the queried object</param>
8181
/// <returns>GitObjectMetadata object instance containg object header information</returns>
@@ -177,6 +177,29 @@ public int Provider(IntPtr content, int max_length, IntPtr data)
177177
}
178178
}
179179

180+
/// <summary>
181+
/// Inserts a <see cref="Blob"/> into the object database, created from the content of a stream.
182+
/// <para>Optionally, git filters will be applied to the content before storing it.</para>
183+
/// </summary>
184+
/// <param name="stream">The stream from which will be read the content of the blob to be created.</param>
185+
/// <returns>The created <see cref="Blob"/>.</returns>
186+
public virtual Blob CreateBlob(Stream stream)
187+
{
188+
return CreateBlob(stream, null, null);
189+
}
190+
191+
/// <summary>
192+
/// Inserts a <see cref="Blob"/> into the object database, created from the content of a stream.
193+
/// <para>Optionally, git filters will be applied to the content before storing it.</para>
194+
/// </summary>
195+
/// <param name="stream">The stream from which will be read the content of the blob to be created.</param>
196+
/// <param name="hintpath">The hintpath is used to determine what git filters should be applied to the object before it can be placed to the object database.</param>
197+
/// <returns>The created <see cref="Blob"/>.</returns>
198+
public virtual Blob CreateBlob(Stream stream, string hintpath)
199+
{
200+
return CreateBlob(stream, hintpath, null);
201+
}
202+
180203
/// <summary>
181204
/// Inserts a <see cref="Blob"/> into the object database, created from the content of a stream.
182205
/// <para>Optionally, git filters will be applied to the content before storing it.</para>
@@ -185,7 +208,12 @@ public int Provider(IntPtr content, int max_length, IntPtr data)
185208
/// <param name="hintpath">The hintpath is used to determine what git filters should be applied to the object before it can be placed to the object database.</param>
186209
/// <param name="numberOfBytesToConsume">The number of bytes to consume from the stream.</param>
187210
/// <returns>The created <see cref="Blob"/>.</returns>
188-
public virtual Blob CreateBlob(Stream stream, string hintpath = null, int? numberOfBytesToConsume = null)
211+
public virtual Blob CreateBlob(Stream stream, string hintpath, int numberOfBytesToConsume)
212+
{
213+
return CreateBlob(stream, hintpath, (int?)numberOfBytesToConsume);
214+
}
215+
216+
internal Blob CreateBlob(Stream stream, string hintpath, int? numberOfBytesToConsume)
189217
{
190218
Ensure.ArgumentNotNull(stream, "stream");
191219

@@ -295,9 +323,32 @@ public virtual Tree CreateTree(Index index)
295323
/// <param name="tree">The <see cref="Tree"/> of the <see cref="Commit"/> to be created.</param>
296324
/// <param name="parents">The parents of the <see cref="Commit"/> to be created.</param>
297325
/// <param name="prettifyMessage">True to prettify the message, or false to leave it as is.</param>
298-
/// <param name="commentChar">Character that lines start with to be stripped if prettifyMessage is true.</param>
299326
/// <returns>The created <see cref="Commit"/>.</returns>
300-
public virtual Commit CreateCommit(Signature author, Signature committer, string message, Tree tree, IEnumerable<Commit> parents, bool prettifyMessage, char? commentChar = null)
327+
public virtual Commit CreateCommit(Signature author, Signature committer, string message, Tree tree, IEnumerable<Commit> parents, bool prettifyMessage)
328+
{
329+
return CreateCommit(author, committer, message, tree, parents, prettifyMessage, null);
330+
}
331+
332+
/// <summary>
333+
/// Inserts a <see cref="Commit"/> into the object database, referencing an existing <see cref="Tree"/>.
334+
/// <para>
335+
/// Prettifing the message includes:
336+
/// * Removing empty lines from the beginning and end.
337+
/// * Removing trailing spaces from every line.
338+
/// * Turning multiple consecutive empty lines between paragraphs into just one empty line.
339+
/// * Ensuring the commit message ends with a newline.
340+
/// * Removing every line starting with the <paramref name="commentChar"/>.
341+
/// </para>
342+
/// </summary>
343+
/// <param name="author">The <see cref="Signature"/> of who made the change.</param>
344+
/// <param name="committer">The <see cref="Signature"/> of who added the change to the repository.</param>
345+
/// <param name="message">The description of why a change was made to the repository.</param>
346+
/// <param name="tree">The <see cref="Tree"/> of the <see cref="Commit"/> to be created.</param>
347+
/// <param name="parents">The parents of the <see cref="Commit"/> to be created.</param>
348+
/// <param name="prettifyMessage">True to prettify the message, or false to leave it as is.</param>
349+
/// <param name="commentChar">When non null, lines starting with this character will be stripped if prettifyMessage is true.</param>
350+
/// <returns>The created <see cref="Commit"/>.</returns>
351+
public virtual Commit CreateCommit(Signature author, Signature committer, string message, Tree tree, IEnumerable<Commit> parents, bool prettifyMessage, char? commentChar)
301352
{
302353
Ensure.ArgumentNotNull(message, "message");
303354
Ensure.ArgumentDoesNotContainZeroByte(message, "message");
@@ -382,29 +433,41 @@ public virtual HistoryDivergence CalculateHistoryDivergence(Commit one, Commit a
382433
return new HistoryDivergence(repo, one, another);
383434
}
384435

436+
/// <summary>
437+
/// Calculates the current shortest abbreviated <see cref="ObjectId"/>
438+
/// string representation for a <see cref="GitObject"/>.
439+
/// </summary>
440+
/// <param name="gitObject">The <see cref="GitObject"/> which identifier should be shortened.</param>
441+
/// <returns>A short string representation of the <see cref="ObjectId"/>.</returns>
442+
public virtual string ShortenObjectId(GitObject gitObject)
443+
{
444+
var shortSha = Proxy.git_object_short_id(repo.Handle, gitObject.Id);
445+
return shortSha;
446+
}
447+
385448
/// <summary>
386449
/// Calculates the current shortest abbreviated <see cref="ObjectId"/>
387450
/// string representation for a <see cref="GitObject"/>.
388451
/// </summary>
389452
/// <param name="gitObject">The <see cref="GitObject"/> which identifier should be shortened.</param>
390453
/// <param name="minLength">Minimum length of the shortened representation.</param>
391454
/// <returns>A short string representation of the <see cref="ObjectId"/>.</returns>
392-
public virtual string ShortenObjectId(GitObject gitObject, int? minLength = null)
455+
public virtual string ShortenObjectId(GitObject gitObject, int minLength)
393456
{
394-
if (minLength.HasValue && (minLength <= 0 || minLength > ObjectId.HexSize))
457+
if (minLength <= 0 || minLength > ObjectId.HexSize)
395458
{
396459
throw new ArgumentOutOfRangeException("minLength", minLength,
397460
string.Format("Expected value should be greater than zero and less than or equal to {0}.", ObjectId.HexSize));
398461
}
399462

400463
string shortSha = Proxy.git_object_short_id(repo.Handle, gitObject.Id);
401464

402-
if (minLength == null || (minLength <= shortSha.Length))
465+
if (minLength <= shortSha.Length)
403466
{
404467
return shortSha;
405468
}
406469

407-
return gitObject.Sha.Substring(0, minLength.Value);
470+
return gitObject.Sha.Substring(0, minLength);
408471
}
409472

410473
/// <summary>

0 commit comments

Comments
 (0)