Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions LibGit2Sharp.Tests/CommitFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
6 changes: 6 additions & 0 deletions LibGit2Sharp/CommitFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public CommitFilter()
{
SortBy = CommitSortStrategies.Time;
Since = "HEAD";
FirstParent = false;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is redundant.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SortBy = CommitSortStrategies.Time;

I know this is completely unrelated to this PR, but shouldn't it be?

SortBy = CommitSortStrategies.Time | CommitSortStrategies.Topological;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is redundant, but I figured it was clearer to show it in the constructor, same as we don't rely on the default value for SortBy.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is redundant, but I figured it was clearer to show it in the constructor

Fair enough

}

/// <summary>
Expand Down Expand Up @@ -57,6 +58,11 @@ internal IList<object> UntilList
get { return ToList(Until); }
}

/// <summary>
/// Whether to limit the walk to each commit's first parent, instead of all of them
/// </summary>
public bool FirstParent { get; set; }

private static IList<object> ToList(object obj)
{
var list = new List<object>();
Expand Down
8 changes: 8 additions & 0 deletions LibGit2Sharp/CommitLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ public CommitEnumerator(Repository repo, CommitFilter filter)
Sort(filter.SortBy);
Push(filter.SinceList);
Hide(filter.UntilList);
FirstParent(filter.FirstParent);
}

#region IEnumerator<Commit> Members
Expand Down Expand Up @@ -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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe some braces here?

}
}
}
}
}
3 changes: 3 additions & 0 deletions LibGit2Sharp/Core/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
5 changes: 5 additions & 0 deletions LibGit2Sharp/Core/Proxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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_
Expand Down