Skip to content

Commit

Permalink
Delegate Commit.MessageShort to libgit2 (libgit2#593)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aimeast committed Jan 6, 2014
1 parent c7b1a99 commit 7089f63
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
16 changes: 3 additions & 13 deletions LibGit2Sharp/Commit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ public class Commit : GitObject
private readonly ILazy<Signature> lazyAuthor;
private readonly ILazy<Signature> lazyCommitter;
private readonly ILazy<string> lazyMessage;
private readonly ILazy<string> lazyMessageShort;
private readonly ILazy<string> lazyEncoding;

private readonly ParentsCollection parents;
private readonly Lazy<string> lazyShortMessage;
private readonly Lazy<IEnumerable<Note>> lazyNotes;

/// <summary>
Expand All @@ -42,9 +42,9 @@ internal Commit(Repository repo, ObjectId id)
lazyAuthor = group.AddLazy(Proxy.git_commit_author);
lazyCommitter = group.AddLazy(Proxy.git_commit_committer);
lazyMessage = group.AddLazy(Proxy.git_commit_message);
lazyMessageShort = group.AddLazy(Proxy.git_commit_summary);
lazyEncoding = group.AddLazy(RetrieveEncodingOf);

lazyShortMessage = new Lazy<string>(ExtractShortMessage);
lazyNotes = new Lazy<IEnumerable<Note>>(() => RetrieveNotesOfCommit(id).ToList());

parents = new ParentsCollection(repo, id);
Expand All @@ -68,7 +68,7 @@ public virtual TreeEntry this[string relativePath]
/// <summary>
/// Gets the short commit message which is usually the first line of the commit.
/// </summary>
public virtual string MessageShort { get { return lazyShortMessage.Value; } }
public virtual string MessageShort { get { return lazyMessageShort.Value; } }

/// <summary>
/// Gets the encoding of the message.
Expand Down Expand Up @@ -100,16 +100,6 @@ public virtual TreeEntry this[string relativePath]
/// </summary>
public virtual IEnumerable<Note> Notes { get { return lazyNotes.Value; } }

private string ExtractShortMessage()
{
if (Message == null)
{
return string.Empty; //TODO: Add some test coverage
}

return Message.Split('\n')[0];
}

private IEnumerable<Note> RetrieveNotesOfCommit(ObjectId oid)
{
return repo.Notes[oid];
Expand Down
4 changes: 4 additions & 0 deletions LibGit2Sharp/Core/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ internal static extern int git_commit_create_from_oids(
[return : MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(LaxUtf8NoCleanupMarshaler))]
internal static extern string git_commit_message(GitObjectSafeHandle commit);

[DllImport(libgit2)]
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(LaxUtf8NoCleanupMarshaler))]
internal static extern string git_commit_summary(GitObjectSafeHandle commit);

[DllImport(libgit2)]
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(LaxUtf8NoCleanupMarshaler))]
internal static extern string git_commit_message_encoding(GitObjectSafeHandle commit);
Expand Down
5 changes: 5 additions & 0 deletions LibGit2Sharp/Core/Proxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,11 @@ public static string git_commit_message(GitObjectSafeHandle obj)
return NativeMethods.git_commit_message(obj);
}

public static string git_commit_summary(GitObjectSafeHandle obj)
{
return NativeMethods.git_commit_summary(obj);
}

public static string git_commit_message_encoding(GitObjectSafeHandle obj)
{
return NativeMethods.git_commit_message_encoding(obj);
Expand Down

0 comments on commit 7089f63

Please sign in to comment.