Skip to content

Commit 42c0156

Browse files
committed
Move CreateCommitBuffer into Commit
There is no particular need for the repository, so make this a static method in Commit and pass in the repo from the tree to the library.
1 parent 177ef4f commit 42c0156

File tree

4 files changed

+40
-40
lines changed

4 files changed

+40
-40
lines changed

LibGit2Sharp.Tests/CommitFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,7 @@ public void CanCreateACommitString()
11301130
using (var repo = new Repository(repoPath))
11311131
{
11321132
var tipCommit = repo.Head.Tip;
1133-
var recreatedCommit = repo.ObjectDatabase.CreateCommitBuffer(
1133+
var recreatedCommit = Commit.CreateBuffer(
11341134
tipCommit.Author,
11351135
tipCommit.Committer,
11361136
tipCommit.Message,

LibGit2Sharp/Commit.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,44 @@ public static SignatureInfo ExtractSignature(Repository repo, ObjectId id)
150150
return Proxy.git_commit_extract_signature(repo.Handle, id, null);
151151
}
152152

153+
/// <summary>
154+
/// Create a commit in-memroy
155+
/// <para>
156+
/// Prettifing the message includes:
157+
/// * Removing empty lines from the beginning and end.
158+
/// * Removing trailing spaces from every line.
159+
/// * Turning multiple consecutive empty lines between paragraphs into just one empty line.
160+
/// * Ensuring the commit message ends with a newline.
161+
/// * Removing every line starting with the <paramref name="commentChar"/>.
162+
/// </para>
163+
/// </summary>
164+
/// <param name="author">The <see cref="Signature"/> of who made the change.</param>
165+
/// <param name="committer">The <see cref="Signature"/> of who added the change to the repository.</param>
166+
/// <param name="message">The description of why a change was made to the repository.</param>
167+
/// <param name="tree">The <see cref="Tree"/> of the <see cref="Commit"/> to be created.</param>
168+
/// <param name="parents">The parents of the <see cref="Commit"/> to be created.</param>
169+
/// <param name="prettifyMessage">True to prettify the message, or false to leave it as is.</param>
170+
/// <param name="commentChar">When non null, lines starting with this character will be stripped if prettifyMessage is true.</param>
171+
/// <returns>The contents of the commit object.</returns>
172+
public static string CreateBuffer(Signature author, Signature committer, string message, Tree tree, IEnumerable<Commit> parents, bool prettifyMessage, char? commentChar)
173+
{
174+
Ensure.ArgumentNotNull(message, "message");
175+
Ensure.ArgumentDoesNotContainZeroByte(message, "message");
176+
Ensure.ArgumentNotNull(author, "author");
177+
Ensure.ArgumentNotNull(committer, "committer");
178+
Ensure.ArgumentNotNull(tree, "tree");
179+
Ensure.ArgumentNotNull(parents, "parents");
180+
181+
if (prettifyMessage)
182+
{
183+
message = Proxy.git_message_prettify(message, commentChar);
184+
}
185+
var treeHandle = Proxy.git_object_lookup(tree.repo.Handle, tree.Id, GitObjectType.Tree);
186+
var handles = parents.Select(c => Proxy.git_object_lookup(c.repo.Handle, c.Id, GitObjectType.Commit));
187+
188+
return Proxy.git_commit_create_buffer(tree.repo.Handle, author, committer, message, treeHandle, handles.ToArray());
189+
}
190+
153191
private class ParentsCollection : ICollection<Commit>
154192
{
155193
private readonly Lazy<ICollection<Commit>> _parents;

LibGit2Sharp/GitObject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public abstract class GitObject : IEquatable<GitObject>, IBelongToARepository
2828
/// <summary>
2929
/// The <see cref="Repository"/> containing the object.
3030
/// </summary>
31-
protected readonly Repository repo;
31+
internal readonly Repository repo;
3232

3333
/// <summary>
3434
/// Needed for mocking purposes.

LibGit2Sharp/ObjectDatabase.cs

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -422,44 +422,6 @@ public virtual Commit CreateCommit(Signature author, Signature committer, string
422422
return commit;
423423
}
424424

425-
/// <summary>
426-
/// Create a commit in-memory but do not write it to the object database.
427-
/// <para>
428-
/// Prettifing the message includes:
429-
/// * Removing empty lines from the beginning and end.
430-
/// * Removing trailing spaces from every line.
431-
/// * Turning multiple consecutive empty lines between paragraphs into just one empty line.
432-
/// * Ensuring the commit message ends with a newline.
433-
/// * Removing every line starting with the <paramref name="commentChar"/>.
434-
/// </para>
435-
/// </summary>
436-
/// <param name="author">The <see cref="Signature"/> of who made the change.</param>
437-
/// <param name="committer">The <see cref="Signature"/> of who added the change to the repository.</param>
438-
/// <param name="message">The description of why a change was made to the repository.</param>
439-
/// <param name="tree">The <see cref="Tree"/> of the <see cref="Commit"/> to be created.</param>
440-
/// <param name="parents">The parents of the <see cref="Commit"/> to be created.</param>
441-
/// <param name="prettifyMessage">True to prettify the message, or false to leave it as is.</param>
442-
/// <param name="commentChar">When non null, lines starting with this character will be stripped if prettifyMessage is true.</param>
443-
/// <returns>The contents of the commit object.</returns>
444-
public virtual string CreateCommitBuffer(Signature author, Signature committer, string message, Tree tree, IEnumerable<Commit> parents, bool prettifyMessage, char? commentChar)
445-
{
446-
Ensure.ArgumentNotNull(message, "message");
447-
Ensure.ArgumentDoesNotContainZeroByte(message, "message");
448-
Ensure.ArgumentNotNull(author, "author");
449-
Ensure.ArgumentNotNull(committer, "committer");
450-
Ensure.ArgumentNotNull(tree, "tree");
451-
Ensure.ArgumentNotNull(parents, "parents");
452-
453-
if (prettifyMessage)
454-
{
455-
message = Proxy.git_message_prettify(message, commentChar);
456-
}
457-
var treeHandle = Proxy.git_object_lookup(repo.Handle, tree.Id, GitObjectType.Tree);
458-
var handles = parents.Select(c => Proxy.git_object_lookup(repo.Handle, c.Id, GitObjectType.Commit));
459-
460-
return Proxy.git_commit_create_buffer(repo.Handle, author, committer, message, treeHandle, handles.ToArray());
461-
}
462-
463425
/// <summary>
464426
/// Inserts a <see cref="Commit"/> into the object database after attaching the given signature.
465427
/// </summary>

0 commit comments

Comments
 (0)