Last active
October 12, 2023 00:43
-
-
Save Aimeast/6250443 to your computer and use it in GitHub Desktop.
My code for Support "git log --path"
https://github.com/libgit2/libgit2sharp/issues/463
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class CommitLogExtension | |
{ | |
public static IEnumerable<Commit> PathFilter(this IEnumerable<Commit> log, string path) | |
{ | |
if (string.IsNullOrEmpty(path)) | |
return log; | |
return log.Where(s => | |
{ | |
var pathEntry = s[path]; | |
var parent = s.Parents.FirstOrDefault(); | |
if (parent == null) | |
return pathEntry != null; | |
var parentPathEntry = parent[path]; | |
if (pathEntry == null && parentPathEntry == null) | |
return false; | |
else if (pathEntry != null && parentPathEntry != null) | |
return pathEntry.Target.Sha != parentPathEntry.Target.Sha; | |
else // pathEntry!=null ^ parentPathEntry!=null | |
return true; | |
}); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ancestors = _repository.Commits | |
.QueryBy(new Filter { Since = commit, SortBy = GitSortOptions.Topological | GitSortOptions.Time }) | |
.PathFilter(path) | |
.ToList(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Maybe cant work with merged branch.