8000 Delegate Commit.MessageShort to libgit2 (#593) · pmiossec/libgit2sharp@7089f63 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7089f63

Browse files
committed
Delegate Commit.MessageShort to libgit2 (libgit2#593)
1 parent c7b1a99 commit 7089f63

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

LibGit2Sharp/Commit.cs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ public class Commit : GitObject
2121
private readonly ILazy<Signature> lazyAuthor;
2222
private readonly ILazy<Signature> lazyCommitter;
2323
private readonly ILazy<string> lazyMessage;
24+
private readonly ILazy<string> lazyMessageShort;
2425
private readonly ILazy<string> lazyEncoding;
2526

2627
private readonly ParentsCollection parents;
27-
private readonly Lazy<string> lazyShortMessage;
2828
private readonly Lazy<IEnumerable<Note>> lazyNotes;
2929

3030
/// <summary>
@@ -42,9 +42,9 @@ internal Commit(Repository repo, ObjectId id)
4242
lazyAuthor = group.AddLazy(Proxy.git_commit_author);
4343
lazyCommitter = group.AddLazy(Proxy.git_commit_committer);
4444
lazyMessage = group.AddLazy(Proxy.git_commit_message);
45+
lazyMessageShort = group.AddLazy(Proxy.git_commit_summary);
4546
lazyEncoding = group.AddLazy(RetrieveEncodingOf);
4647

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

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

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

103-
private string ExtractShortMessage()
104-
{
105-
if (Message == null)
106-
{
107-
return string.Empty; //TODO: Add some test coverage
108-
}
109-
110-
return Message.Split('\n')[0];
111-
}
112-
113103
private IEnumerable<Note> RetrieveNotesOfCommit(ObjectId oid)
114104
{
115105
return repo.Notes[oid];

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,10 @@ internal static extern int git_commit_create_from_oids(
261261
[return : MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(LaxUtf8NoCleanupMarshaler))]
262262
internal static extern string git_commit_message(GitObjectSafeHandle commit);
263263

264+
[DllImport(libgit2)]
265+
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(LaxUtf8NoCleanupMarshaler))]
266+
internal static extern string git_commit_summary(GitObjectSafeHandle commit);
267+
264268
[DllImport(libgit2)]
265269
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(LaxUtf8NoCleanupMarshaler))]
266270
internal static extern string git_commit_message_encoding(GitObjectSafeHandle commit);

LibGit2Sharp/Core/Proxy.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,11 @@ public static string git_commit_message(GitObjectSafeHandle obj)
347347
return NativeMethods.git_commit_message(obj);
348348
}
349349

350+
public static string git_commit_summary(GitObjectSafeHandle obj)
351+
{
352+
return NativeMethods.git_commit_summary(obj);
353+
}
354+
350355
public static string git_commit_message_encoding(GitObjectSafeHandle obj)
351356
{
352357
return NativeMethods.git_commit_message_encoding(obj);

0 commit comments

Comments
 (0)
0