diff --git a/LibGit2Sharp.Tests/CommitFixture.cs b/LibGit2Sharp.Tests/CommitFixture.cs index fc5cc3733..33a781eb1 100644 --- a/LibGit2Sharp.Tests/CommitFixture.cs +++ b/LibGit2Sharp.Tests/CommitFixture.cs @@ -176,6 +176,18 @@ public void CanEnumerateCommitsWithReverseTopoSorting() } } + [Fact] + public void CanSimplifyByFirstParent() + { + AssertEnumerationOfCommits( + repo => new CommitFilter { Since = repo.Head, FirstParent = true }, + new[] + { + "4c062a6", "be3563a", "9fd738e", + "4a202b3", "5b5b025", "8496071", + }); + } + [Fact] public void CanGetParentsCount() { diff --git a/LibGit2Sharp/CommitFilter.cs b/LibGit2Sharp/CommitFilter.cs index 43d26bbb9..5635fc52a 100644 --- a/LibGit2Sharp/CommitFilter.cs +++ b/LibGit2Sharp/CommitFilter.cs @@ -16,6 +16,7 @@ public CommitFilter() { SortBy = CommitSortStrategies.Time; Since = "HEAD"; + FirstParent = false; } /// @@ -57,6 +58,11 @@ internal IList UntilList get { return ToList(Until); } } + /// + /// Whether to limit the walk to each commit's first parent, instead of all of them + /// + public bool FirstParent { get; set; } + private static IList ToList(object obj) { var list = new List(); diff --git a/LibGit2Sharp/CommitLog.cs b/LibGit2Sharp/CommitLog.cs index 86fa6fb93..cbc2fc498 100644 --- a/LibGit2Sharp/CommitLog.cs +++ b/LibGit2Sharp/CommitLog.cs @@ -154,6 +154,7 @@ public CommitEnumerator(Repository repo, CommitFilter filter) Sort(filter.SortBy); Push(filter.SinceList); Hide(filter.UntilList); + FirstParent(filter.FirstParent); } #region IEnumerator Members @@ -232,6 +233,13 @@ private void Sort(CommitSortStrategies options) Proxy.git_revwalk_sorting(handle, options); } + private void FirstParent(bool firstParent) + { + if (firstParent) + { + Proxy.git_revwalk_simplify_first_parent(handle); + } + } } } } diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs index 1cd002fcc..a9e72c117 100644 --- a/LibGit2Sharp/Core/NativeMethods.cs +++ b/LibGit2Sharp/Core/NativeMethods.cs @@ -1096,6 +1096,9 @@ internal static extern int git_revparse_ext( [DllImport(libgit2)] internal static extern void git_revwalk_sorting(RevWalkerSafeHandle walk, CommitSortStrategies sort); + [DllImport(libgit2)] + internal static extern void git_revwalk_simplify_first_parent(RevWalkerSafeHandle walk); + [DllImport(libgit2)] internal static extern void git_signature_free(IntPtr signature); diff --git a/LibGit2Sharp/Core/Proxy.cs b/LibGit2Sharp/Core/Proxy.cs index 970ffbbf0..0878a908b 100644 --- a/LibGit2Sharp/Core/Proxy.cs +++ b/LibGit2Sharp/Core/Proxy.cs @@ -2101,6 +2101,11 @@ public static void git_revwalk_sorting(RevWalkerSafeHandle walker, CommitSortStr NativeMethods.git_revwalk_sorting(walker, options); } + public static void git_revwalk_simplify_first_parent(RevWalkerSafeHandle walker) + { + NativeMethods.git_revwalk_simplify_first_parent(walker); + } + #endregion #region git_signature_